Add create API to inventory client
Also fix query string from "cluster-id" to "cluster_id" Change-Id: I2e894cd30d27ff332aa729b04c3706450ebd61ed
This commit is contained in:
parent
0895bfa5e8
commit
13d0b5301d
@ -2166,7 +2166,7 @@ class InventoryTestCase(BaseTestResource):
|
||||
self.CONTAINER_CLUSTER,
|
||||
'ContainerApplication')
|
||||
base_url = 'https://1.2.3.4/api/v1/fabric/container-applications'
|
||||
surfix = '?cluster-id=%s' % self.CONTAINER_CLUSTER
|
||||
surfix = '?cluster_id=%s' % self.CONTAINER_CLUSTER
|
||||
test_client.assert_json_call(
|
||||
'get', mocked_resource,
|
||||
base_url + surfix,
|
||||
@ -2182,6 +2182,21 @@ class InventoryTestCase(BaseTestResource):
|
||||
base_url + surfix,
|
||||
headers=self.default_headers())
|
||||
|
||||
def test_create_resource(self):
|
||||
mocked_resource = self.get_mocked_resource()
|
||||
body = {'resource_type': 'ContainerCluster',
|
||||
'name': 'k8s-1',
|
||||
'external_id': 'id-1',
|
||||
'cluster_type': 'Kubernetes',
|
||||
'infrastructure': {'infra_type': 'vSphere'}}
|
||||
mocked_resource.create('ContainerCluster', body)
|
||||
base_url = 'https://1.2.3.4/api/v1/fabric/container-clusters'
|
||||
test_client.assert_json_call(
|
||||
'post', mocked_resource,
|
||||
base_url,
|
||||
data=jsonutils.dumps(body, sort_keys=True),
|
||||
headers=self.default_headers())
|
||||
|
||||
def test_update(self):
|
||||
mocked_resource = self.get_mocked_resource()
|
||||
body = {}
|
||||
|
@ -757,7 +757,7 @@ class Inventory(utils.NsxLibApiBase):
|
||||
if not resource_type:
|
||||
msg = "null resource type is not supported"
|
||||
raise exceptions.ResourceNotFound(details=msg)
|
||||
request_url = "%s?cluster-id=%s" % (
|
||||
request_url = "%s?cluster_id=%s" % (
|
||||
self.get_path(self._get_path_for_resource(resource_type)),
|
||||
cluster_id)
|
||||
return self.client.url_get(request_url)
|
||||
@ -771,6 +771,14 @@ class Inventory(utils.NsxLibApiBase):
|
||||
resource_id)
|
||||
return self.client.url_delete(request_url)
|
||||
|
||||
def create(self, resource_type, resource):
|
||||
if not resource_type:
|
||||
msg = "null resource type is not supported"
|
||||
raise exceptions.ResourceNotFound(details=msg)
|
||||
request_url = self.get_path(
|
||||
self._get_path_for_resource(resource_type))
|
||||
return self.client.url_post(request_url, resource)
|
||||
|
||||
def _get_path_for_resource(self, resource_type):
|
||||
path = self.RESOURCES_PATH.get(resource_type)
|
||||
if not path:
|
||||
|
Loading…
x
Reference in New Issue
Block a user