|  | 
|  | 1 | +// Licensed to the Apache Software Foundation (ASF) under one | 
|  | 2 | +// or more contributor license agreements.  See the NOTICE file | 
|  | 3 | +// distributed with this work for additional information | 
|  | 4 | +// regarding copyright ownership.  The ASF licenses this file | 
|  | 5 | +// to you under the Apache License, Version 2.0 (the | 
|  | 6 | +// "License"); you may not use this file except in compliance | 
|  | 7 | +// with the License.  You may obtain a copy of the License at | 
|  | 8 | +// | 
|  | 9 | +//   http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | +// | 
|  | 11 | +// Unless required by applicable law or agreed to in writing, | 
|  | 12 | +// software distributed under the License is distributed on an | 
|  | 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
|  | 14 | +// KIND, either express or implied.  See the License for the | 
|  | 15 | +// specific language governing permissions and limitations | 
|  | 16 | +// under the License. | 
|  | 17 | + | 
|  | 18 | +<template> | 
|  | 19 | +  <div class="migrate-volume-container"> | 
|  | 20 | + | 
|  | 21 | +    <div class="modal-form"> | 
|  | 22 | +      <p class="modal-form__label">{{ $t('storagePool') }}</p> | 
|  | 23 | +      <a-select v-model="selectedStoragePool" style="width: 100%;"> | 
|  | 24 | +        <a-select-option v-for="(storagePool, index) in storagePools" :value="storagePool.id" :key="index"> | 
|  | 25 | +          {{ storagePool.name }} | 
|  | 26 | +        </a-select-option> | 
|  | 27 | +      </a-select> | 
|  | 28 | +      <template v-if="this.resource.virtualmachineid"> | 
|  | 29 | +        <p class="modal-form__label" @click="replaceDiskOffering = !replaceDiskOffering" style="cursor:pointer;"> | 
|  | 30 | +          {{ $t('useNewDiskOffering') }} | 
|  | 31 | +        </p> | 
|  | 32 | +        <a-checkbox v-model="replaceDiskOffering" /> | 
|  | 33 | + | 
|  | 34 | +        <template v-if="replaceDiskOffering"> | 
|  | 35 | +          <p class="modal-form__label">{{ $t('newDiskOffering') }}</p> | 
|  | 36 | +          <a-select v-model="selectedDiskOffering" style="width: 100%;"> | 
|  | 37 | +            <a-select-option v-for="(diskOffering, index) in diskOfferings" :value="diskOffering.id" :key="index"> | 
|  | 38 | +              {{ diskOffering.displaytext }} | 
|  | 39 | +            </a-select-option> | 
|  | 40 | +          </a-select> | 
|  | 41 | +        </template> | 
|  | 42 | + | 
|  | 43 | +      </template> | 
|  | 44 | +    </div> | 
|  | 45 | + | 
|  | 46 | +    <a-divider /> | 
|  | 47 | + | 
|  | 48 | +    <div class="actions"> | 
|  | 49 | +      <a-button @click="closeModal"> | 
|  | 50 | +        {{ $t('Cancel') }} | 
|  | 51 | +      </a-button> | 
|  | 52 | +      <a-button type="primary" @click="submitMigrateVolume"> | 
|  | 53 | +        {{ $t('OK') }} | 
|  | 54 | +      </a-button> | 
|  | 55 | +    </div> | 
|  | 56 | + | 
|  | 57 | +  </div> | 
|  | 58 | +</template> | 
|  | 59 | + | 
|  | 60 | +<script> | 
|  | 61 | +import { api } from '@/api' | 
|  | 62 | +
 | 
|  | 63 | +export default { | 
|  | 64 | +  name: 'MigrateVolume', | 
|  | 65 | +  props: { | 
|  | 66 | +    resource: { | 
|  | 67 | +      type: Object, | 
|  | 68 | +      required: true | 
|  | 69 | +    } | 
|  | 70 | +  }, | 
|  | 71 | +  inject: ['parentFetchData', 'parentToggleLoading'], | 
|  | 72 | +  data () { | 
|  | 73 | +    return { | 
|  | 74 | +      storagePools: [], | 
|  | 75 | +      selectedStoragePool: null, | 
|  | 76 | +      diskOfferings: [], | 
|  | 77 | +      replaceDiskOffering: !!this.resource.virtualmachineid, | 
|  | 78 | +      selectedDiskOffering: null | 
|  | 79 | +    } | 
|  | 80 | +  }, | 
|  | 81 | +  created () { | 
|  | 82 | +    this.fetchStoragePools() | 
|  | 83 | +    this.resource.virtualmachineid && this.fetchDiskOfferings() | 
|  | 84 | +  }, | 
|  | 85 | +  methods: { | 
|  | 86 | +    fetchStoragePools () { | 
|  | 87 | +      api('listStoragePools', { | 
|  | 88 | +        zoneid: this.resource.zoneid | 
|  | 89 | +      }).then(response => { | 
|  | 90 | +        this.storagePools = response.liststoragepoolsresponse.storagepool | 
|  | 91 | +        this.selectedStoragePool = this.storagePools[0].id | 
|  | 92 | +      }).catch(error => { | 
|  | 93 | +        this.$notification.error({ | 
|  | 94 | +          message: `Error ${error.response.status}`, | 
|  | 95 | +          description: error.response.data.errorresponse.errortext | 
|  | 96 | +        }) | 
|  | 97 | +        this.closeModal() | 
|  | 98 | +      }) | 
|  | 99 | +    }, | 
|  | 100 | +    fetchDiskOfferings () { | 
|  | 101 | +      api('listDiskOfferings', { | 
|  | 102 | +        listall: true | 
|  | 103 | +      }).then(response => { | 
|  | 104 | +        this.diskOfferings = response.listdiskofferingsresponse.diskoffering | 
|  | 105 | +        this.selectedDiskOffering = this.diskOfferings[0].id | 
|  | 106 | +      }).catch(error => { | 
|  | 107 | +        this.$notification.error({ | 
|  | 108 | +          message: `Error ${error.response.status}`, | 
|  | 109 | +          description: error.response.data.errorresponse.errortext | 
|  | 110 | +        }) | 
|  | 111 | +        this.closeModal() | 
|  | 112 | +      }) | 
|  | 113 | +    }, | 
|  | 114 | +    closeModal () { | 
|  | 115 | +      this.$parent.$parent.close() | 
|  | 116 | +    }, | 
|  | 117 | +    submitMigrateVolume () { | 
|  | 118 | +      this.closeModal() | 
|  | 119 | +      this.parentToggleLoading() | 
|  | 120 | +      api('migrateVolume', { | 
|  | 121 | +        livemigrate: this.resource.vmstate === 'Running', | 
|  | 122 | +        storageid: this.selectedStoragePool, | 
|  | 123 | +        volumeid: this.resource.id, | 
|  | 124 | +        newdiskofferingid: this.replaceDiskOffering ? this.selectedDiskOffering : null | 
|  | 125 | +      }).then(response => { | 
|  | 126 | +        this.$pollJob({ | 
|  | 127 | +          jobId: response.migratevolumeresponse.jobid, | 
|  | 128 | +          successMessage: `Successfully migrated volume`, | 
|  | 129 | +          successMethod: () => { | 
|  | 130 | +            this.parentFetchData() | 
|  | 131 | +            this.parentToggleLoading() | 
|  | 132 | +          }, | 
|  | 133 | +          errorMessage: 'Migrating volume failed', | 
|  | 134 | +          errorMethod: () => { | 
|  | 135 | +            this.parentFetchData() | 
|  | 136 | +            this.parentToggleLoading() | 
|  | 137 | +          }, | 
|  | 138 | +          loadingMessage: `Migrating volume...`, | 
|  | 139 | +          catchMessage: 'Error encountered while fetching async job result', | 
|  | 140 | +          catchMethod: () => { | 
|  | 141 | +            this.parentFetchData() | 
|  | 142 | +            this.parentToggleLoading() | 
|  | 143 | +          } | 
|  | 144 | +        }) | 
|  | 145 | +      }).catch(error => { | 
|  | 146 | +        this.$notification.error({ | 
|  | 147 | +          message: `Error ${error.response.status}`, | 
|  | 148 | +          description: error.response.data.errorresponse.errortext | 
|  | 149 | +        }) | 
|  | 150 | +        this.closeModal() | 
|  | 151 | +      }) | 
|  | 152 | +    } | 
|  | 153 | +  } | 
|  | 154 | +} | 
|  | 155 | +</script> | 
|  | 156 | + | 
|  | 157 | +<style scoped lang="scss"> | 
|  | 158 | +  .migrate-volume-container { | 
|  | 159 | +    width: 95vw; | 
|  | 160 | +    max-width: 100%; | 
|  | 161 | +
 | 
|  | 162 | +    @media (min-width: 760px) { | 
|  | 163 | +      width: 50vw; | 
|  | 164 | +    } | 
|  | 165 | +  } | 
|  | 166 | +
 | 
|  | 167 | +  .actions { | 
|  | 168 | +    display: flex; | 
|  | 169 | +    justify-content: flex-end; | 
|  | 170 | +    margin-top: 20px; | 
|  | 171 | +
 | 
|  | 172 | +    button { | 
|  | 173 | +      &:not(:last-child) { | 
|  | 174 | +        margin-right: 10px; | 
|  | 175 | +      } | 
|  | 176 | +    } | 
|  | 177 | +  } | 
|  | 178 | +
 | 
|  | 179 | +  .modal-form { | 
|  | 180 | +    margin-top: -20px; | 
|  | 181 | +
 | 
|  | 182 | +    &__label { | 
|  | 183 | +      font-weight: bold; | 
|  | 184 | +      margin-top: 10px; | 
|  | 185 | +      margin-bottom: 5px; | 
|  | 186 | +    } | 
|  | 187 | +
 | 
|  | 188 | +  } | 
|  | 189 | +</style> | 
0 commit comments