summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Sun <bins@vmware.com>2018-03-23 11:12:44 +0800
committerBin Sun <bins@vmware.com>2018-03-23 11:12:44 +0800
commitc11a895f15d2f8c3848a2912c2948054c9a2ce54 (patch)
tree2f6e23b573a718bae9e11f555f2d104739846e27
parent5a7d69be6ec867b140246db16cc8eb6007ab564d (diff)
Add default_value support and networks
Add network resource and default value support Change-Id: I01e307a8e1b0a5dce0573c9041725a023ab40de7 Issue-ID: MULTICLOUD-152 Signed-off-by: Bin Sun <bins@vmware.com>
-rw-r--r--vio/vio/api_v2/api_definition/networks.yaml85
-rw-r--r--vio/vio/api_v2/api_router/controller_builder.py17
2 files changed, 102 insertions, 0 deletions
diff --git a/vio/vio/api_v2/api_definition/networks.yaml b/vio/vio/api_v2/api_definition/networks.yaml
new file mode 100644
index 0000000..f7c4f57
--- /dev/null
+++ b/vio/vio/api_v2/api_definition/networks.yaml
@@ -0,0 +1,85 @@
+---
+ info:
+ version: "1.0.0"
+ title: "Multi Cloud Network"
+ description: "Definition of Host API"
+ termsOfService: "http://swagger.io/terms/"
+ schemes:
+ - "http"
+ produces:
+ - "application/json"
+ paths:
+ /{vimid}/{tenantid}/networks/{networkid}:
+ parameters:
+ - type: string
+ name: vimid
+ - type: string
+ format: uuid
+ name: tenantid
+ - type: string
+ name: networkid
+ in: path
+ required: true
+ get:
+ produces:
+ - "application/json"
+ responses:
+ "200":
+ schema:
+ $ref: "#/definitions/network"
+ get_all:
+ produces:
+ - "application/json"
+ responses:
+ "200":
+ schema:
+ type: "array"
+ items:
+ $ref: "#/definitions/network"
+ vim_path: "/network/v2.0/networks"
+ definitions:
+ network:
+ plural_vim_resource: "networks"
+ vim_resource: "network"
+ plural: "networks"
+ properties:
+ name:
+ type: string
+ required: true
+ source: network.name
+ id:
+ type: string
+ required: true
+ source: network.id
+ status:
+ type: string
+ source: network.status
+ required: true
+ segmentationId:
+ type: string
+ source: network.provider:segmentation_id
+ default: None
+ physicalNetwork:
+ type: string
+ source: network.provider:physical_network
+ default: None
+ networkType:
+ type: string
+ source: network.provider:network_type
+ default: None
+ tenantId:
+ type: string
+ source: network.tenant_id
+ required: true
+ shared:
+ type: boolean
+ source: network.shared
+ required: true
+ routerExternal:
+ type: boolean
+ source: network.router:external
+ required: true
+ vlanTransparent:
+ type: boolean
+ source: network.vlan_transparent
+ default: false
diff --git a/vio/vio/api_v2/api_router/controller_builder.py b/vio/vio/api_v2/api_router/controller_builder.py
index 6fcaf24..bd5adfb 100644
--- a/vio/vio/api_v2/api_router/controller_builder.py
+++ b/vio/vio/api_v2/api_router/controller_builder.py
@@ -53,6 +53,19 @@ def _get_vim_auth_session(vim_id, tenant_id):
return session.Session(auth=auth)
+def _convert_default_value(default):
+ if default == "None":
+ return None
+
+ if default == "true":
+ return True
+
+ if default == "false":
+ return False
+
+ return default
+
+
def _convert_vim_res_to_mc_res(vim_resource, res_properties):
mc_resource = {}
for key in res_properties:
@@ -63,6 +76,10 @@ def _convert_vim_res_to_mc_res(vim_resource, res_properties):
raise Exception("Required field %s is missed in VIM "
"resource %s", (attr, vim_resource))
else:
+ if "default" in res_properties[key]:
+ mc_resource[key] = _convert_default_value(
+ res_properties[key]["default"])
+
# None required fields missed, just skip.
continue