You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/09/10 13:36:57 UTC

[GitHub] [cloudstack] shwstppr opened a new pull request #5434: ui: add custom form for update template

shwstppr opened a new pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434


   ### Description
   
   Adds a custom UI form for updating a template with more options such as details.
   
   <!--- ********************************************************************************* -->
   <!--- NOTE: AUTOMATATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. -->
   <!--- PLEASE PUT AN 'X' in only **ONE** box -->
   <!--- ********************************************************************************* -->
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [x] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [ ] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [ ] Minor
   - [ ] Trivial
   
   
   ### Screenshots (if appropriate):
   ![Screenshot from 2021-09-10 19-02-25](https://user-images.githubusercontent.com/153340/132861727-6dcfa68c-a79a-4995-a0c6-6a6e70afc53f.png)
   
   
   ### How Has This Been Tested?
   <!-- Please describe in detail how you tested your changes. -->
   <!-- Include details of your testing environment, and the tests you ran to -->
   <!-- see how your change affects other areas of the code, etc. -->
   
   
   <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1014169122


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1018481370


   @shwstppr Checked with KVM & VMware templates. I could see the keyboard type in the API call from UI, but I'm re-open the update template form, the updated keyboard type is not shown. Please check.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020260583


   @Pearl1594 can you please try again


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020786012






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020256771


   UI build: :heavy_check_mark:
   Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5434 (SL-JID-1057)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020785523


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1019776080


   @sureshanaparti fixed the empty nicAdapter, keyboard behaviour. If no value is selected for these fields, detail will not be passed to the API and it will be removed for the template.
   Added warning for changing template type to SYSTEM
   ![Screenshot from 2022-01-24 12-26-48](https://user-images.githubusercontent.com/153340/150736015-d0c412f2-d1eb-403c-856f-6ebb9681be63.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020248581


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti merged pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti merged pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1019780440


   UI build: :heavy_check_mark:
   Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5434 (SL-JID-1054)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020786012


   @shwstppr a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1017362656


   UI build: :heavy_check_mark:
   Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5434 (SL-JID-1044)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#discussion_r789657993



##########
File path: ui/src/views/image/UpdateTemplate.vue
##########
@@ -0,0 +1,389 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout" v-ctrl-enter="handleSubmit">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.name')" :tooltip="apiParams.name.description"/>
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: `${$t('message.error.required.input')}` }]
+            }]"
+            :placeholder="apiParams.name.description"
+            autoFocus />
+        </a-form-item>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.displaytext')" :tooltip="apiParams.displaytext.description"/>
+          <a-input
+            v-decorator="['displaytext', {
+              rules: [{ required: true, message: `${$t('message.error.required.input')}` }]
+            }]"
+            :placeholder="apiParams.displaytext.description"
+            autoFocus />
+        </a-form-item>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.passwordenabled')" :tooltip="apiParams.passwordenabled.description"/>
+          <a-switch v-decorator="['passwordenabled', {}]" />
+        </a-form-item>
+
+        <a-row :gutter="12" v-if="['KVM', 'VMware'].includes(resource.hypervisor)">
+          <a-col :md="24" :lg="resource.hypervisor === 'KVM' ? 24 : 12" v-if="resource.hypervisor === 'KVM' || (resource.hypervisor === 'VMware' && !resource.deployasis)">
+            <a-form-item :label="$t('label.rootdiskcontrollertype')">
+              <a-select
+                v-decorator="['rootDiskController', {
+                  rules: [
+                    {
+                      required: true,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :loading="rootDisk.loading"
+                :placeholder="$t('label.rootdiskcontrollertype')">
+                <a-select-option v-for="opt in rootDisk.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+          <a-col :md="24" :lg="12" v-if="resource.hypervisor === 'VMware' && !resource.deployasis">
+            <a-form-item :label="$t('label.nicadaptertype')">
+              <a-select
+                v-decorator="['nicAdapter', {
+                  rules: [
+                    {
+                      required: false,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :placeholder="$t('label.nicadaptertype')">
+                <a-select-option v-for="opt in nicAdapterType.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+        </a-row>
+        <a-row :gutter="12" v-if="resource.hypervisor !== 'VMware' || (resource.hypervisor === 'VMware' && !resource.deployasis)">
+          <a-col :md="24" :lg="24">
+            <a-form-item v-if="resource.hypervisor === 'VMware' && !resource.deployasis" :label="$t('label.keyboardtype')">
+              <a-select
+                v-decorator="['keyboard']"
+                :placeholder="$t('label.keyboard')">
+                <a-select-option v-for="opt in keyboardType.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+          <a-col :md="24" :lg="24">
+            <a-form-item :label="$t('label.ostypeid')">
+              <a-select
+                showSearch
+                optionFilterProp="children"
+                :filterOption="(input, option) => {
+                  return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
+                }"
+                v-decorator="['ostypeid', {
+                  rules: [
+                    {
+                      required: true,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :loading="osTypes.loading"
+                :placeholder="apiParams.ostypeid.description">
+                <a-select-option v-for="opt in osTypes.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+        </a-row>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
+          <a-switch v-decorator="['isdynamicallyscalable', {}]" />
+        </a-form-item>
+        <a-form-item :label="$t('label.templatetype')" v-if="isAdmin">
+          <a-select
+            showSearch
+            optionFilterProp="children"
+            :filterOption="(input, option) => {
+              return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
+            }"
+            v-decorator="['templatetype']"
+            :placeholder="apiParams.templatetype.description">
+            <a-select-option v-for="opt in templatetypes" :key="opt">
+              {{ opt }}
+            </a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('label.cancel') }}</a-button>
+          <a-button :loading="loading" ref="submit" type="primary" @click="handleSubmit">{{ this.$t('label.ok') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+import TooltipLabel from '@/components/widgets/TooltipLabel'
+
+export default {
+  name: 'UpdateTemplate',
+  components: {
+    TooltipLabel
+  },
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      templatetypes: ['BUILTIN', 'USER', 'SYSTEM', 'ROUTING'],
+      rootDisk: {},
+      nicAdapterType: {},
+      keyboardType: {},
+      osTypes: {},
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+    this.apiParams = this.$getApiParams('updateTemplate')
+  },
+  created () {
+    this.$set(this.rootDisk, 'loading', false)
+    this.$set(this.rootDisk, 'opts', [])
+    this.$set(this.nicAdapterType, 'loading', false)
+    this.$set(this.nicAdapterType, 'opts', [])
+    this.$set(this.keyboardType, 'loading', false)
+    this.$set(this.keyboardType, 'opts', [])
+    this.$set(this.osTypes, 'loading', false)
+    this.$set(this.osTypes, 'opts', [])
+    const resourceFields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable']
+    if (this.isAdmin()) {
+      resourceFields.push('templatetype')
+    }
+    for (var field of resourceFields) {
+      var fieldValue = this.resource[field]
+      if (fieldValue) {
+        this.form.getFieldDecorator(field, { initialValue: fieldValue })
+      }
+    }
+    const resourceDetailsFields = []
+    if (this.resource.hypervisor === 'KVM') {
+      resourceDetailsFields.push('rootDiskController')
+    } else if (this.resource.hypervisor === 'VMware' && !this.resource.deployasis) {
+      resourceDetailsFields.push(...['rootDiskController', 'nicAdapter', 'keyboard'])
+    }
+    for (var detailsField of resourceDetailsFields) {
+      var detailValue = this.resource?.details?.[detailsField] || null
+      if (detailValue) {
+        this.form.getFieldDecorator(detailsField, { initialValue: detailValue })
+      }
+    }
+    this.fetchData()
+  },
+  methods: {
+    isAdmin () {
+      return ['Admin'].includes(this.$store.getters.userInfo.roletype)
+    },
+    fetchData () {
+      this.fetchOsTypes()
+      this.fetchRootDiskControllerTypes(this.resource.hypervisor)
+      this.fetchNicAdapterTypes()
+      this.fetchKeyboardTypes()
+    },
+    isValidValueForKey (obj, key) {
+      return key in obj && obj[key] != null && obj[key] !== undefined
+    },
+    fetchOsTypes () {
+      const params = {}
+      params.listAll = true
+      this.osTypes.opts = []
+      this.osTypes.loading = true
+      api('listOsTypes', params).then(json => {
+        const listOsTypes = json.listostypesresponse.ostype
+        this.$set(this.osTypes, 'opts', listOsTypes)
+      }).finally(() => {
+        this.osTypes.loading = false
+      })
+    },
+    fetchRootDiskControllerTypes (hyperVisor) {
+      const controller = []
+      this.rootDisk.opts = []
+
+      if (hyperVisor === 'KVM') {
+        controller.push({
+          id: '',
+          description: ''
+        })
+        controller.push({
+          id: 'ide',
+          description: 'ide'
+        })
+        controller.push({
+          id: 'osdefault',
+          description: 'osdefault'
+        })
+        controller.push({
+          id: 'scsi',
+          description: 'scsi'
+        })
+        controller.push({
+          id: 'virtio',
+          description: 'virtio'
+        })
+      } else if (hyperVisor === 'VMware') {
+        controller.push({
+          id: '',
+          description: ''
+        })
+        controller.push({
+          id: 'scsi',
+          description: 'scsi'
+        })
+        controller.push({
+          id: 'ide',
+          description: 'ide'
+        })
+        controller.push({
+          id: 'osdefault',
+          description: 'osdefault'
+        })
+        controller.push({
+          id: 'pvscsi',
+          description: 'pvscsi'
+        })
+        controller.push({
+          id: 'lsilogic',
+          description: 'lsilogic'
+        })
+        controller.push({
+          id: 'lsisas1068',
+          description: 'lsilogicsas'
+        })
+        controller.push({
+          id: 'buslogic',
+          description: 'buslogic'
+        })
+      }
+
+      this.$set(this.rootDisk, 'opts', controller)
+    },
+    fetchNicAdapterTypes () {
+      const nicAdapterType = []
+      nicAdapterType.push({
+        id: '',
+        description: ''
+      })
+      nicAdapterType.push({
+        id: 'E1000',
+        description: 'E1000'
+      })
+      nicAdapterType.push({
+        id: 'PCNet32',
+        description: 'PCNet32'
+      })
+      nicAdapterType.push({
+        id: 'Vmxnet2',
+        description: 'Vmxnet2'
+      })
+      nicAdapterType.push({
+        id: 'Vmxnet3',
+        description: 'Vmxnet3'
+      })
+
+      this.$set(this.nicAdapterType, 'opts', nicAdapterType)
+    },
+    fetchKeyboardTypes () {
+      const keyboardType = []
+      const keyboardOpts = this.$config.keyboardOptions || {}
+      keyboardType.push({
+        id: '',
+        description: ''
+      })
+
+      Object.keys(keyboardOpts).forEach(keyboard => {
+        keyboardType.push({
+          id: keyboard,
+          description: this.$t(keyboardOpts[keyboard])
+        })
+      })
+
+      this.$set(this.keyboardType, 'opts', keyboardType)
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      if (this.loading) return
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        this.loading = true
+        const params = {
+          id: this.resource.id
+        }
+        const detailsField = ['rootDiskController', 'nicAdapter', 'keyboardType']

Review comment:
       ```suggestion
           const detailsField = ['rootDiskController', 'nicAdapter', 'keyboard']
   ```
   
   May be, this is the issue with keyboard detail.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020249772


   @shwstppr a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020785523


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1014169369


   @sureshanaparti a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1014182953


   UI build: :heavy_check_mark:
   Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5434 (SL-JID-1024)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] utchoang commented on a change in pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
utchoang commented on a change in pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#discussion_r785668472



##########
File path: ui/src/views/image/UpdateTemplate.vue
##########
@@ -0,0 +1,389 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+  <div class="form-layout" v-ctrl-enter="handleSubmit">
+    <a-spin :spinning="loading">
+      <a-form
+        :form="form"
+        @submit="handleSubmit"
+        layout="vertical">
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.name')" :tooltip="apiParams.name.description"/>
+          <a-input
+            v-decorator="['name', {
+              rules: [{ required: true, message: `${$t('message.error.required.input')}` }]
+            }]"
+            :placeholder="apiParams.name.description"
+            autoFocus />
+        </a-form-item>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.displaytext')" :tooltip="apiParams.displaytext.description"/>
+          <a-input
+            v-decorator="['displaytext', {
+              rules: [{ required: true, message: `${$t('message.error.required.input')}` }]
+            }]"
+            :placeholder="apiParams.displaytext.description"
+            autoFocus />
+        </a-form-item>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.passwordenabled')" :tooltip="apiParams.passwordenabled.description"/>
+          <a-switch v-decorator="['passwordenabled', {}]" />
+        </a-form-item>
+
+        <a-row :gutter="12" v-if="['KVM', 'VMware'].includes(resource.hypervisor)">
+          <a-col :md="24" :lg="resource.hypervisor === 'KVM' ? 24 : 12" v-if="resource.hypervisor === 'KVM' || (resource.hypervisor === 'VMware' && !resource.deployasis)">
+            <a-form-item :label="$t('label.rootdiskcontrollertype')">
+              <a-select
+                v-decorator="['rootDiskController', {
+                  rules: [
+                    {
+                      required: true,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :loading="rootDisk.loading"
+                :placeholder="$t('label.rootdiskcontrollertype')">
+                <a-select-option v-for="opt in rootDisk.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+          <a-col :md="24" :lg="12" v-if="resource.hypervisor === 'VMware' && !resource.deployasis">
+            <a-form-item :label="$t('label.nicadaptertype')">
+              <a-select
+                v-decorator="['nicAdapter', {
+                  rules: [
+                    {
+                      required: false,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :placeholder="$t('label.nicadaptertype')">
+                <a-select-option v-for="opt in nicAdapterType.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+        </a-row>
+        <a-row :gutter="12" v-if="resource.hypervisor !== 'VMware' || (resource.hypervisor === 'VMware' && !resource.deployasis)">
+          <a-col :md="24" :lg="24">
+            <a-form-item v-if="resource.hypervisor === 'VMware' && !resource.deployasis" :label="$t('label.keyboardtype')">
+              <a-select
+                v-decorator="['keyboard']"
+                :placeholder="$t('label.keyboard')">
+                <a-select-option v-for="opt in keyboardType.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+          <a-col :md="24" :lg="24">
+            <a-form-item :label="$t('label.ostypeid')">
+              <a-select
+                showSearch
+                optionFilterProp="children"
+                :filterOption="(input, option) => {
+                  return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
+                }"
+                v-decorator="['ostypeid', {
+                  rules: [
+                    {
+                      required: true,
+                      message: `${this.$t('message.error.select')}`
+                    }
+                  ]
+                }]"
+                :loading="osTypes.loading"
+                :placeholder="apiParams.ostypeid.description">
+                <a-select-option v-for="opt in osTypes.opts" :key="opt.id">
+                  {{ opt.name || opt.description }}
+                </a-select-option>
+              </a-select>
+            </a-form-item>
+          </a-col>
+        </a-row>
+        <a-form-item>
+          <tooltip-label slot="label" :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
+          <a-switch v-decorator="['isdynamicallyscalable', {}]" />
+        </a-form-item>
+        <a-form-item :label="$t('label.templatetype')" v-if="isAdmin">
+          <a-select
+            showSearch
+            optionFilterProp="children"
+            :filterOption="(input, option) => {
+              return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
+            }"
+            v-decorator="['templatetype']"
+            :placeholder="apiParams.templatetype.description">
+            <a-select-option v-for="opt in templatetypes" :key="opt">
+              {{ opt }}
+            </a-select-option>
+          </a-select>
+        </a-form-item>
+
+        <div :span="24" class="action-button">
+          <a-button @click="closeAction">{{ this.$t('label.cancel') }}</a-button>
+          <a-button :loading="loading" ref="submit" type="primary" @click="handleSubmit">{{ this.$t('label.ok') }}</a-button>
+        </div>
+      </a-form>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+import { api } from '@/api'
+import TooltipLabel from '@/components/widgets/TooltipLabel'
+
+export default {
+  name: 'UpdateTemplate',
+  components: {
+    TooltipLabel
+  },
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    }
+  },
+  data () {
+    return {
+      templatetypes: ['BUILTIN', 'USER', 'SYSTEM', 'ROUTING'],
+      rootDisk: {},
+      nicAdapterType: {},
+      keyboardType: {},
+      osTypes: {},
+      loading: false
+    }
+  },
+  beforeCreate () {
+    this.form = this.$form.createForm(this)
+    this.apiParams = this.$getApiParams('updateTemplate')
+  },
+  created () {
+    this.$set(this.rootDisk, 'loading', false)
+    this.$set(this.rootDisk, 'opts', [])
+    this.$set(this.nicAdapterType, 'loading', false)
+    this.$set(this.nicAdapterType, 'opts', [])
+    this.$set(this.keyboardType, 'loading', false)
+    this.$set(this.keyboardType, 'opts', [])
+    this.$set(this.osTypes, 'loading', false)
+    this.$set(this.osTypes, 'opts', [])
+    const resourceFields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable']
+    if (this.isAdmin()) {
+      resourceFields.push('templatetype')
+    }
+    for (var field of resourceFields) {
+      var fieldValue = this.resource[field]
+      if (fieldValue) {
+        this.form.getFieldDecorator(field, { initialValue: fieldValue })
+      }
+    }
+    const resourceDetailsFields = []
+    if (this.resource.hypervisor === 'KVM') {
+      resourceDetailsFields.push('rootDiskController')
+    } else if (this.resource.hypervisor === 'VMware' && !this.resource.deployasis) {
+      resourceDetailsFields.push(...['rootDiskController', 'nicAdapter', 'keyboard'])
+    }
+    for (var detailsField of resourceDetailsFields) {
+      var detailValue = this.resource?.details?.[detailsField] || null
+      if (detailValue) {
+        this.form.getFieldDecorator(detailsField, { initialValue: detailValue })
+      }
+    }
+    this.fetchData()
+  },
+  methods: {
+    isAdmin () {
+      return ['Admin'].includes(this.$store.getters.userInfo.roletype)
+    },
+    fetchData () {
+      this.fetchOsTypes()
+      this.fetchRootDiskControllerTypes(this.resource.hypervisor)
+      this.fetchNicAdapterTypes()
+      this.fetchKeyboardTypes()
+    },
+    isValidValueForKey (obj, key) {
+      return key in obj && obj[key] != null && obj[key] !== undefined
+    },
+    fetchOsTypes () {
+      const params = {}
+      params.listAll = true
+      this.osTypes.opts = []
+      this.osTypes.loading = true
+      api('listOsTypes', params).then(json => {
+        const listOsTypes = json.listostypesresponse.ostype
+        this.$set(this.osTypes, 'opts', listOsTypes)
+      }).finally(() => {
+        this.osTypes.loading = false
+      })
+    },
+    fetchRootDiskControllerTypes (hyperVisor) {
+      const controller = []
+      this.rootDisk.opts = []
+
+      if (hyperVisor === 'KVM') {
+        controller.push({
+          id: '',
+          description: ''
+        })
+        controller.push({
+          id: 'ide',
+          description: 'ide'
+        })
+        controller.push({
+          id: 'osdefault',
+          description: 'osdefault'
+        })
+        controller.push({
+          id: 'scsi',
+          description: 'scsi'
+        })
+        controller.push({
+          id: 'virtio',
+          description: 'virtio'
+        })
+      } else if (hyperVisor === 'VMware') {
+        controller.push({
+          id: '',
+          description: ''
+        })
+        controller.push({
+          id: 'scsi',
+          description: 'scsi'
+        })
+        controller.push({
+          id: 'ide',
+          description: 'ide'
+        })
+        controller.push({
+          id: 'osdefault',
+          description: 'osdefault'
+        })
+        controller.push({
+          id: 'pvscsi',
+          description: 'pvscsi'
+        })
+        controller.push({
+          id: 'lsilogic',
+          description: 'lsilogic'
+        })
+        controller.push({
+          id: 'lsisas1068',
+          description: 'lsilogicsas'
+        })
+        controller.push({
+          id: 'buslogic',
+          description: 'buslogic'
+        })
+      }
+
+      this.$set(this.rootDisk, 'opts', controller)
+    },
+    fetchNicAdapterTypes () {
+      const nicAdapterType = []
+      nicAdapterType.push({
+        id: '',
+        description: ''
+      })
+      nicAdapterType.push({
+        id: 'E1000',
+        description: 'E1000'
+      })
+      nicAdapterType.push({
+        id: 'PCNet32',
+        description: 'PCNet32'
+      })
+      nicAdapterType.push({
+        id: 'Vmxnet2',
+        description: 'Vmxnet2'
+      })
+      nicAdapterType.push({
+        id: 'Vmxnet3',
+        description: 'Vmxnet3'
+      })
+
+      this.$set(this.nicAdapterType, 'opts', nicAdapterType)
+    },
+    fetchKeyboardTypes () {
+      const keyboardType = []
+      const keyboardOpts = this.$config.keyboardOptions || {}
+      keyboardType.push({
+        id: '',
+        description: ''
+      })
+
+      Object.keys(keyboardOpts).forEach(keyboard => {
+        keyboardType.push({
+          id: keyboard,
+          description: this.$t(keyboardOpts[keyboard])
+        })
+      })
+
+      this.$set(this.keyboardType, 'opts', keyboardType)
+    },
+    handleSubmit (e) {
+      e.preventDefault()
+      if (this.loading) return
+      this.form.validateFields((err, values) => {
+        if (err) {
+          return
+        }
+        this.loading = true
+        const params = {
+          id: this.resource.id
+        }
+        const detailsField = ['rootDiskController', 'nicAdapter', 'keyboardType']
+        for (const key in values) {
+          if (!this.isValidValueForKey(values, key)) continue
+          if (detailsField.includes(key)) {
+            params['details[0].' + key] = values[key]
+            continue
+          }
+          params[key] = values[key]
+        }
+        api('updateTemplate', params).then(json => {
+          this.$message.success(`${this.$t('message.success.update.template')}: ${this.resource.name}`)

Review comment:
       @shwstppr Can you add the translate this key.
   ![image](https://user-images.githubusercontent.com/13766648/149719271-8cf583f7-42d2-4e97-a411-064b93540ca9.png)
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1017241167


   Hi @shwstppr can you address the outstanding comments please. thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1017348783


   @shwstppr a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1019777060


   @shwstppr a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti merged pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti merged pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] Pearl1594 commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
Pearl1594 commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020058339


   @shwstppr I believe we need to disable / remove the templatetype field from the form when a user with User role logs in -
   ![image](https://user-images.githubusercontent.com/10495417/150784525-6b30ae65-701e-49a7-a220-03760f602e8c.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1020790614


   UI build: :heavy_check_mark:
   Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5434 (SL-JID-1061)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1019776850


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1019803899


   > @sureshanaparti fixed the empty nicAdapter, keyboard behaviour. If no value is selected for these fields, detail will not be passed to the API and it will be removed for the template.
   > Added warning for changing template type to SYSTEM
   > ![Screenshot from 2022-01-24 12-26-48](https://user-images.githubusercontent.com/153340/150736015-d0c412f2-d1eb-403c-856f-6ebb9681be63.png)
   
   ok @shwstppr , will check. thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti edited a comment on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
sureshanaparti edited a comment on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1018481370


   @shwstppr Checked with KVM & VMware templates. I could see the keyboard type in the update template API call from UI, but it seems the API call is not including keyboard in details parameter (and so if any keyboard detail exists, it gets deleted). Please check.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5434: ui: add custom form for update template

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5434:
URL: https://github.com/apache/cloudstack/pull/5434#issuecomment-1017348043


   @blueorangutan ui


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org