1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from lcm.pub.utils.values import ignore_case_get
22 from .exceptions import VimException
24 logger = logging.getLogger(__name__)
26 RES_EXIST, RES_NEW = 0, 1
27 NET_PRIVATE, NET_SHSRED = 0, 1
28 VLAN_TRANSPARENT_NO, VLAN_TRANSPARENT_YES = 0, 1
30 def create_vim_res(data, do_notify, do_rollback):
32 for vol in ignore_case_get(data, "volume_storages"):
33 create_volume(vol, do_notify, 10)
34 for network in ignore_case_get(data, "vls"):
35 create_network(network, do_notify, 20)
37 except VimException as e:
38 logger.error(e.message)
39 do_rollback(e.message)
41 logger.error(traceback.format_exc())
42 do_rollback(str(sys.exc_info()))
44 def create_volume(vol, do_notify, progress)
46 "tenant": vol["properties"]["location_info"]["tenant"],
47 "volumeName": vol["properties"]["volume_name"],
48 "volumeSize": int(ignore_case_get(vol["properties"], "size", "0")),
49 "imageName": ignore_case_get(vol, "image_file"),
50 "volumeType": ignore_case_get(vol["properties"], "custom_volume_type")
52 vim_id = vol["properties"]["location_info"]["vimid"],
53 ret = api.create_volume(vim_id, param)
54 do_notify(progress, ret)
56 def create_network(network, do_notify, progress):
58 "tenant": network["properties"]["location_info"]["tenant"],
59 "networkName": network["properties"]["network_name"],
60 "shared": NET_PRIVATE,
61 "networkType": network["properties"]["network_type"],
62 "physicalNetwork": ignore_case_get(network["properties"], "physical_network")
64 vlan_transparent = ignore_case_get(network["properties"], "vlan_transparent")
66 param["vlanTransparent"] = VLAN_TRANSPARENT_YES
67 segmentation_id = ignore_case_get(network["properties"], "segmentation_id")
69 param["segmentationId"] = int(segmentation_id)
70 vim_id = network["properties"]["location_info"]["vimid"],
71 ret = api.create_network(vim_id, param)
72 do_notify(progress, ret)