Просмотр исходного кода

Merge pull request #317 from smiclea/storage-schema

Use the updated storage API schema
Dorin Paslaru 7 лет назад
Родитель
Сommit
095b43fa97

+ 4 - 4
src/components/organisms/WizardOptions/WizardOptions.jsx

@@ -26,7 +26,7 @@ import WizardOptionsField from '../../molecules/WizardOptionsField'
 import StatusImage from '../../atoms/StatusImage'
 import type { Field } from '../../../types/Field'
 import type { Instance } from '../../../types/Instance'
-import type { Storage } from '../../../types/Endpoint'
+import type { StorageBackend } from '../../../types/Endpoint'
 
 import { executionOptions } from '../../../config'
 
@@ -63,7 +63,7 @@ type Props = {
   onChange: (field: Field, value: any) => void,
   useAdvancedOptions: boolean,
   hasStorageMap: boolean,
-  storage: Storage[],
+  storageBackends: StorageBackend[],
   onAdvancedOptionsToggle: (showAdvanced: boolean) => void,
   wizardType: string,
   loading: boolean,
@@ -118,8 +118,8 @@ class WizardOptions extends React.Component<Props> {
       }
     }
 
-    if (this.props.hasStorageMap && this.props.useAdvancedOptions && this.props.storage.length > 0) {
-      fieldsSchema.push({ name: 'default_storage', type: 'string', enum: this.props.storage.map(s => s.name) })
+    if (this.props.hasStorageMap && this.props.useAdvancedOptions && this.props.storageBackends.length > 0) {
+      fieldsSchema.push({ name: 'default_storage', type: 'string', enum: this.props.storageBackends.map(s => s.name) })
     }
 
     return fieldsSchema

+ 5 - 5
src/components/organisms/WizardPageContent/WizardPageContent.jsx

@@ -34,7 +34,7 @@ import StyleProps from '../../styleUtils/StyleProps'
 import Palette from '../../styleUtils/Palette'
 import { providerTypes, wizardConfig } from '../../../config'
 import type { WizardData } from '../../../types/WizardData'
-import type { Endpoint, Storage, StorageMap } from '../../../types/Endpoint'
+import type { Endpoint, StorageBackend, StorageMap } from '../../../types/Endpoint'
 import type { Instance, Nic, Disk } from '../../../types/Instance'
 import type { Field } from '../../../types/Field'
 import type { Network } from '../../../types/Network'
@@ -116,7 +116,7 @@ type Props = {
   onInstancePageClick: (page: number) => void,
   onOptionsChange: (field: Field, value: any) => void,
   onNetworkChange: (nic: Nic, network: Network) => void,
-  onStorageChange: (sourceStorage: Disk, targetStorage: Storage, type: 'backend' | 'disk') => void,
+  onStorageChange: (sourceStorage: Disk, targetStorage: StorageBackend, type: 'backend' | 'disk') => void,
   onAddScheduleClick: (schedule: ScheduleType) => void,
   onScheduleChange: (scheduleId: string, schedule: ScheduleType) => void,
   onScheduleRemove: (scheudleId: string) => void,
@@ -341,7 +341,7 @@ class WizardPageContent extends React.Component<Props, State> {
             data={this.props.wizardData.options}
             useAdvancedOptions={this.state.useAdvancedOptions}
             hasStorageMap={this.props.hasStorageMap}
-            storage={this.props.endpointStore.storage}
+            storageBackends={this.props.endpointStore.storageBackends}
             wizardType={this.props.type}
             onAdvancedOptionsToggle={useAdvancedOptions => { this.handleAdvancedOptionsToggle(useAdvancedOptions) }}
           />
@@ -362,7 +362,7 @@ class WizardPageContent extends React.Component<Props, State> {
       case 'storage':
         body = (
           <WizardStorage
-            storage={this.props.endpointStore.storage}
+            storageBackends={this.props.endpointStore.storageBackends}
             instancesDetails={this.props.instanceStore.instancesDetails}
             storageMap={this.props.storageMap}
             defaultStorage={String(this.props.wizardData.options ? this.props.wizardData.options.default_storage : '')}
@@ -392,7 +392,7 @@ class WizardPageContent extends React.Component<Props, State> {
             wizardType={this.props.type}
             instancesDetails={this.props.instanceStore.instancesDetails}
             defaultStorage={
-              this.props.endpointStore.storage.find(
+              this.props.endpointStore.storageBackends.find(
                 s => this.props.wizardData.options ?
                   s.name === this.props.wizardData.options.default_storage :
                   false

+ 7 - 7
src/components/organisms/WizardStorage/WizardStorage.jsx

@@ -23,7 +23,7 @@ import Dropdown from '../../molecules/Dropdown'
 import Palette from '../../styleUtils/Palette'
 import StyleProps from '../../styleUtils/StyleProps'
 import type { Instance, Disk } from '../../../types/Instance'
-import type { Storage, StorageMap } from '../../../types/Endpoint'
+import type { StorageBackend, StorageMap } from '../../../types/Endpoint'
 
 import backendImage from './images/backend.svg'
 import diskImage from './images/disk.svg'
@@ -138,11 +138,11 @@ export const getDisks = (instancesDetails: Instance[], type: 'backend' | 'disk')
 }
 
 type Props = {
-  storage: Storage[],
+  storageBackends: StorageBackend[],
   instancesDetails: Instance[],
   storageMap: ?StorageMap[],
   defaultStorage: ?string,
-  onChange: (sourceStorage: Disk, targetStorage: Storage, type: 'backend' | 'disk') => void,
+  onChange: (sourceStorage: Disk, targetStorage: StorageBackend, type: 'backend' | 'disk') => void,
 }
 @observer
 class WizardStorage extends React.Component<Props> {
@@ -162,7 +162,7 @@ class WizardStorage extends React.Component<Props> {
     let storageMap = this.props.storageMap
     let storageItems = [
       { name: 'Default', id: null },
-      ...this.props.storage,
+      ...this.props.storageBackends,
     ]
 
     disks = disks.filter(d => d[diskFieldName])
@@ -201,7 +201,7 @@ class WizardStorage extends React.Component<Props> {
                   items={storageItems}
                   labelField="name"
                   valueField="id"
-                  onChange={(item: Storage) => { this.props.onChange(disk, item, type) }}
+                  onChange={(item: StorageBackend) => { this.props.onChange(disk, item, type) }}
                 />
               </StorageItem>
             )
@@ -214,7 +214,7 @@ class WizardStorage extends React.Component<Props> {
   renderBackendMapping() {
     let disks = getDisks(this.props.instancesDetails, 'backend')
 
-    if (disks.length === 0 || this.props.storage.length === 0) {
+    if (disks.length === 0 || this.props.storageBackends.length === 0) {
       return null
     }
 
@@ -224,7 +224,7 @@ class WizardStorage extends React.Component<Props> {
   renderDiskMapping() {
     let disks = getDisks(this.props.instancesDetails, 'disk')
 
-    if (disks.length === 0 || this.props.storage.length === 0) {
+    if (disks.length === 0 || this.props.storageBackends.length === 0) {
       return this.renderNoStorage()
     }
 

+ 3 - 3
src/components/organisms/WizardSummary/WizardSummary.jsx

@@ -27,7 +27,7 @@ import LabelDictionary from '../../../utils/LabelDictionary'
 import DateUtils from '../../../utils/DateUtils'
 import type { Schedule } from '../../../types/Schedule'
 import type { WizardData } from '../../../types/WizardData'
-import type { StorageMap, Storage } from '../../../types/Endpoint'
+import type { StorageMap, StorageBackend } from '../../../types/Endpoint'
 import type { Instance, Disk } from '../../../types/Instance'
 
 import { getDisks } from '../WizardStorage'
@@ -144,7 +144,7 @@ type Props = {
   schedules: Schedule[],
   storageMap: StorageMap[],
   instancesDetails: Instance[],
-  defaultStorage: ?Storage,
+  defaultStorage: ?StorageBackend,
 }
 @observer
 class WizardSummary extends React.Component<Props> {
@@ -297,7 +297,7 @@ class WizardSummary extends React.Component<Props> {
     }
     let fieldName = type === 'backend' ? 'storage_backend_identifier' : 'id'
 
-    let fullStorageMap: { source: Disk, target: ?Storage }[] = disks.filter(d => d[fieldName]).map(disk => {
+    let fullStorageMap: { source: Disk, target: ?StorageBackend }[] = disks.filter(d => d[fieldName]).map(disk => {
       let diskMapped = storageMap.find(s => s.source[fieldName] === disk[fieldName])
       if (diskMapped) {
         return { source: diskMapped.source, target: diskMapped.target }

+ 2 - 2
src/components/pages/WizardPage/WizardPage.jsx

@@ -37,7 +37,7 @@ import replicaStore from '../../../stores/ReplicaStore'
 import KeyboardManager from '../../../utils/KeyboardManager'
 import { wizardConfig, executionOptions, providersWithExtraOptions } from '../../../config'
 import type { MainItem } from '../../../types/MainItem'
-import type { Endpoint as EndpointType, Storage } from '../../../types/Endpoint'
+import type { Endpoint as EndpointType, StorageBackend } from '../../../types/Endpoint'
 import type { Instance, Nic, Disk } from '../../../types/Instance'
 import type { Field } from '../../../types/Field'
 import type { Network } from '../../../types/Network'
@@ -290,7 +290,7 @@ class WizardPage extends React.Component<Props, State> {
     wizardStore.setPermalink(wizardStore.data)
   }
 
-  handleStorageChange(source: Disk, target: Storage, type: 'backend' | 'disk') {
+  handleStorageChange(source: Disk, target: StorageBackend, type: 'backend' | 'disk') {
     wizardStore.updateStorage({ source, target, type })
   }
 

+ 1 - 1
src/sources/EndpointSource.js

@@ -230,7 +230,7 @@ class EdnpointSource {
     })
   }
 
-  static loadStorage(endpointId: string, data: any): Promise<Storage[]> {
+  static loadStorage(endpointId: string, data: any): Promise<Storage> {
     let env = btoa(JSON.stringify(data))
     return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/storage?env=${env}`).then(response => {
       return response.data.storage

+ 4 - 4
src/stores/EndpointStore.js

@@ -14,7 +14,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 import { observable, action } from 'mobx'
-import type { Endpoint, Validation, Storage } from '../types/Endpoint'
+import type { Endpoint, Validation, StorageBackend } from '../types/Endpoint'
 import EndpointSource from '../sources/EndpointSource'
 
 export const passwordFields = ['password', 'private_key_passphrase']
@@ -38,7 +38,7 @@ class EndpointStore {
   @observable adding = false
   @observable connectionInfoLoading = false
   @observable connectionsInfoLoading = false
-  @observable storage: Storage[] = []
+  @observable storageBackends: StorageBackend[] = []
 
   @action getEndpoints(options?: { showLoading: boolean }) {
     if (options && options.showLoading) {
@@ -135,9 +135,9 @@ class EndpointStore {
   }
 
   @action loadStorage(endpointId: string, data: any): Promise<void> {
-    this.storage = []
+    this.storageBackends = []
     return EndpointSource.loadStorage(endpointId, data).then(storage => {
-      this.storage = storage
+      this.storageBackends = storage.storage_backends
     })
   }
 }

+ 6 - 2
src/types/Endpoint.js

@@ -41,14 +41,18 @@ export type DestinationOption = {
   config_default: string | { name: string, id: string },
 }
 
-export type Storage = {
+export type StorageBackend = {
   id: string,
   name: string,
+}
+
+export type Storage = {
+  storage_backends: StorageBackend[],
   config_default?: string,
 }
 
 export type StorageMap = {
   type: 'backend' | 'disk',
   source: Disk,
-  target: Storage,
+  target: StorageBackend,
 }