summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxinhuili <lxinhui@vmware.com>2017-03-17 04:38:46 -0700
committerxinhuili <lxinhui@vmware.com>2017-03-17 04:38:46 -0700
commit08a4a5d309ed13fb118f249940392bc5b277c413 (patch)
treec793b01dba62ac4d0315e458c082e7ac096dad4b
parent312eaa87aad223fb92849c0062fb6b123c4e984c (diff)
Fix port problem
This patch is to fix patch problem. Change-Id: Ifca7b000df17fac13b2e128a52f71790f9a5346c Issue-ids: MULTIVIM-36 Signed-off-by: xinhuili <lxinhui@vmware.com>
-rw-r--r--vio/vio/pub/vim/drivers/vimsdk/image_v2.py9
-rw-r--r--vio/vio/pub/vim/vimapi/network/OperatePort.py10
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateServers.py11
-rw-r--r--vio/vio/swagger/image_utils.py6
-rw-r--r--vio/vio/swagger/nova_utils.py10
-rw-r--r--vio/vio/swagger/views/image/views.py4
6 files changed, 31 insertions, 19 deletions
diff --git a/vio/vio/pub/vim/drivers/vimsdk/image_v2.py b/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
index a9342cf..8553adf 100644
--- a/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
+++ b/vio/vio/pub/vim/drivers/vimsdk/image_v2.py
@@ -56,13 +56,10 @@ class GlanceClient(base.DriverBase):
container_format = data.pop('container_format')
if not all([container_format, disk_format]):
- LOG.error( "Both container_format and disk_format are required")
+ raise Exception("Both container_format and disk_format are required")
- try:
- img = self._proxy._create(_image.Image, disk_format=disk_format,
- container_format=container_format, **data)
- except Exception as ex:
- pass
+ img = self._proxy._create(_image.Image, disk_format=disk_format,
+ container_format=container_format, **data)
return img
@sdk.translate_exception
diff --git a/vio/vio/pub/vim/vimapi/network/OperatePort.py b/vio/vio/pub/vim/vimapi/network/OperatePort.py
index 3e9e4eb..235498d 100644
--- a/vio/vio/pub/vim/vimapi/network/OperatePort.py
+++ b/vio/vio/pub/vim/vimapi/network/OperatePort.py
@@ -26,7 +26,7 @@ class OperatePort(BaseNet):
"vnicType": "binding:vnic_type",
"securityGroups": "security_groups",
"macAddress": "mac_address",
- "subnetId": "subnet_id",
+ # "subnetId": "subnet_id",
"ip": "ip_address"
}
@@ -41,7 +41,11 @@ class OperatePort(BaseNet):
result['name'] = port.name
result['vnicType'] = port.binding_vnic_type
result['macAddress'] = port.mac_address
- result['subnetId'] = port.subnet_id or port.fixed_ips[0]['subnet_id']
+ if port.fixed_ips:
+ subnet_id = port.fixed_ips[0]['subnet_id']
+ else:
+ subnet_id = port.subnet_id
+ result['subnetId'] = subnet_id
result['securityGroups'] = port.security_group_ids
return result
@@ -49,6 +53,8 @@ class OperatePort(BaseNet):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info)
body = translate(self.keys_mapping, body)
+ if body.get('subnetId'):
+ body['fixed_ips'] = [{'subnet_id': body.pop('subnetId')}]
port = network.port_create(**body)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId']}
resp = self._convert(port)
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateServers.py b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
index 98a836b..a3f1bf4 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateServers.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
@@ -38,12 +38,13 @@ class OperateServers(OperateNova):
boot_type = boot.get('type')
if boot_type == 1:
# boot from vol
- req['block_device_mapping_v2'] = {
+ req['block_device_mapping_v2'] = [{
+ 'boot_index': "0",
'uuid': boot["volumeId"],
'source_type': 'volume',
'destination_type': 'volume',
'delete_on_termination': False
- }
+ }]
elif boot_type == 2:
req['imageRef'] = cc.find_image(boot.get('imageId')).id
networks = create_req.get('nicArray', [])
@@ -54,13 +55,15 @@ class OperateServers(OperateNova):
req['availability_zone'] = az
md = create_req.get('metadata', [])
if md:
- req['metadata'] = [{n['keyName']: n['Value']} for n in md]
+ req['metadata'] = {n['keyName']: n['value'] for n in md}
userdata = create_req.get('userdata', None)
if userdata:
req['user_data'] = base64.encodestring(userdata)
sg = create_req.get('securityGroups', [])
if sg:
- req['security_groups'] = sg
+ req['security_groups'] = []
+ for v in sg:
+ req['security_groups'].append({'name':v})
# todo attach volumes after server created
volumes = create_req.get('volumeArray', [])
return cc.create_server(**req)
diff --git a/vio/vio/swagger/image_utils.py b/vio/vio/swagger/image_utils.py
index 3073bd1..a7302a8 100644
--- a/vio/vio/swagger/image_utils.py
+++ b/vio/vio/swagger/image_utils.py
@@ -59,8 +59,6 @@ def req_body_formatter(body):
param['disk_format'] = body.get('imageType')
param['container_format'] = body.get('containerFormat')
param['visibility'] = body.get('visibility')
- param['imagePath'] = body.get('imagePath')
- if body.get('properties'):
- param['vmware_adaptertype'] = body.get('properties').get('vmware_adaptertype')
- param['vmware_ostype'] = body.get('properties').get('vmware_ostype')
+ properties = body.get('properties', {})
+ param.update(properties)
return param
diff --git a/vio/vio/swagger/nova_utils.py b/vio/vio/swagger/nova_utils.py
index 97dc5be..816234e 100644
--- a/vio/vio/swagger/nova_utils.py
+++ b/vio/vio/swagger/nova_utils.py
@@ -34,8 +34,14 @@ def server_formatter(server, interfaces=[]):
r['nicArray'] = [{'portId': i.port_id} for i in interfaces]
elif server.networks:
r['nicArray'] = [{'portId': n['port']} for n in server.networks]
- if server.attached_volumes:
- r["volumeArray"] = [{'volumeId': v['id']} for v in server.attached_volumes]
+ # TODO: wait sdk fix block_device_mapping
+ try:
+ if server.attached_volumes:
+ r["volumeArray"] = [{'volumeId': v['id']} for v in server.attached_volumes]
+ elif server.block_device_mapping:
+ r["volumeArray"] = [{'volumeId': v['uuid']} for v in server.block_device_mapping]
+ except ValueError as e:
+ r['volumeArray'] = [{'volumeId':""}]
if server.image_id or server.image:
r['boot'] = {
'type': 2,
diff --git a/vio/vio/swagger/views/image/views.py b/vio/vio/swagger/views/image/views.py
index ff3b4d3..34877f0 100644
--- a/vio/vio/swagger/views/image/views.py
+++ b/vio/vio/swagger/views/image/views.py
@@ -105,7 +105,9 @@ class CreateListImagesView(APIView):
return Response(data=rsp, status=status.HTTP_200_OK)
param = image_utils.req_body_formatter(req_body)
- image = image_instance.create_vim_image(vimid, tenantid, **param)
+ image = image_instance.create_vim_image(vimid, tenantid,
+ imagePath=req_body.get('imagePath'),
+ **param)
rsp = image_utils.image_formatter(image)
rsp.update(vim_rsp)