This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-primate.git


The following commit(s) were added to refs/heads/master by this push:
     new 9fa1b10  vm: FIX - Add dropdown select IP for network type is Shared 
(#762)
9fa1b10 is described below

commit 9fa1b108b1a00999600315b1ce02b791f213cf2e
Author: Hoang Nguyen <[email protected]>
AuthorDate: Tue Sep 29 19:08:58 2020 +0700

    vm: FIX - Add dropdown select IP for network type is Shared (#762)
    
    * vm: add dropdown select IP for network type is Shared
    
    * remove function not use
---
 src/views/compute/InstanceTab.vue | 57 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 3 deletions(-)

diff --git a/src/views/compute/InstanceTab.vue 
b/src/views/compute/InstanceTab.vue
index 43159f8..8048c24 100644
--- a/src/views/compute/InstanceTab.vue
+++ b/src/views/compute/InstanceTab.vue
@@ -92,7 +92,7 @@
                 icon="swap"
                 shape="circle"
                 :disabled="!('updateVmNicIp' in $store.getters.apis)"
-                @click="editIpAddressNic = record.nic.id; showUpdateIpModal = 
true" />
+                @click="onChangeIPAddress(record)" />
             </a-tooltip>
             <a-tooltip placement="bottom" v-if="record.nic.type !== 'L2'">
               <template slot="title">
@@ -187,7 +187,18 @@
 
       <div class="modal-form">
         <p class="modal-form__label">{{ $t('label.publicip') }}:</p>
-        <a-input v-model="editIpAddressValue"></a-input>
+        <a-select
+          showSearch
+          v-if="editNicResource.type==='Shared'"
+          v-model="editIpAddressValue"
+          :loading="listIps.loading">
+          <a-select-option v-for="ip in listIps.opts" :key="ip.ipaddress">
+            {{ ip.ipaddress }}
+          </a-select-option>
+        </a-select>
+        <a-input
+          v-else
+          v-model="editIpAddressValue"></a-input>
       </div>
     </a-modal>
 
@@ -304,7 +315,12 @@ export default {
           dataIndex: 'size',
           scopedSlots: { customRender: 'size' }
         }
-      ]
+      ],
+      editNicResource: {},
+      listIps: {
+        loading: false,
+        opts: []
+      }
     }
   },
   created () {
@@ -354,6 +370,33 @@ export default {
         this.secondaryIPs = response.listnicsresponse.nic[0].secondaryip
       })
     },
+    fetchPublicIps (networkid) {
+      this.listIps.loading = true
+      this.listIps.opts = []
+      api('listPublicIpAddresses', {
+        networkid: networkid,
+        allocatedonly: false,
+        forvirtualnetwork: false
+      }).then(json => {
+        const listPublicIps = 
json.listpublicipaddressesresponse.publicipaddress || []
+        listPublicIps.forEach(item => {
+          if (item.state === 'Free') {
+            this.listIps.opts.push({
+              ipaddress: item.ipaddress
+            })
+          }
+        })
+        this.listIps.opts.sort(function (a, b) {
+          const currentIp = a.ipaddress.replaceAll('.', '')
+          const nextIp = b.ipaddress.replaceAll('.', '')
+          if (parseInt(currentIp) < parseInt(nextIp)) { return -1 }
+          if (parseInt(currentIp) > parseInt(nextIp)) { return 1 }
+          return 0
+        })
+      }).finally(() => {
+        this.listIps.loading = false
+      })
+    },
     showAddModal () {
       this.showAddNetworkModal = true
       this.listNetworks()
@@ -367,6 +410,14 @@ export default {
       this.editIpAddressValue = ''
       this.newSecondaryIp = ''
     },
+    onChangeIPAddress (record) {
+      this.editNicResource = record.nic
+      this.editIpAddressNic = record.nic.id
+      this.showUpdateIpModal = true
+      if (record.nic.type === 'Shared') {
+        this.fetchPublicIps(record.nic.networkid)
+      }
+    },
     submitAddNetwork () {
       const params = {}
       params.virtualmachineid = this.vm.id

Reply via email to