def test_get_resource(self): api = self.new_mocked_client(client.NSX3Client) client.get_resource('ports', client=api) assert_json_call( 'get', api, 'https://1.2.3.4/api/v1/ports')
def delete_resource_by_values(resource, skip_not_found=True, **kwargs): resources_get = client.get_resource(resource) matched_num = 0 for res in resources_get['results']: if utils.dict_match(kwargs, res): LOG.debug("Deleting %s from resource %s", res, resource) delete_resource = resource + "/" + str(res['id']) client.delete_resource(delete_resource) matched_num = matched_num + 1 if matched_num == 0: if skip_not_found: LOG.warning(_LW("No resource in %(res)s matched for values: " "%(values)s"), {'res': resource, 'values': kwargs}) else: err_msg = (_("No resource in %(res)s matched for values: " "%(values)s") % {'res': resource, 'values': kwargs}) raise nsx_exc.ResourceNotFound( manager=client._get_nsx_managers_from_conf(), operation=err_msg) elif matched_num > 1: LOG.warning(_LW("%(num)s resources in %(res)s matched for values: " "%(values)s"), {'num': matched_num, 'res': resource, 'values': kwargs})
def _get_resource_by_name_or_id(name_or_id, resource): all_results = client.get_resource(resource)['results'] matched_results = [] for rs in all_results: if rs.get('id') == name_or_id: # Matched by id - must be unique return name_or_id if rs.get('display_name') == name_or_id: # Matched by name - add to the list to verify it is unique matched_results.append(rs) if len(matched_results) == 0: err_msg = (_("Could not find %(resource)s %(name)s") % {'name': name_or_id, 'resource': resource}) raise nsx_exc.NsxPluginException(err_msg=err_msg) elif len(matched_results) > 1: err_msg = (_("Found multiple %(resource)s named %(name)s") % {'name': name_or_id, 'resource': resource}) raise nsx_exc.NsxPluginException(err_msg=err_msg) return matched_results[0].get('id')
def read_nsgroup(nsgroup_id): return nsxclient.get_resource('ns-groups/%s?populate_references=true' % nsgroup_id)
def get_resource(self, resource): return nsx_client.get_resource( resource, client=self._client)
def list_nsgroups(): return nsxclient.get_resource( 'ns-groups?populate_references=false').get('results', [])
def get_section_rules(section_id): resource = 'firewall/sections/%s/rules' % section_id return nsxclient.get_resource(resource)
def list_sections(): resource = 'firewall/sections' return nsxclient.get_resource(resource).get('results', [])
def get_logical_switch(logical_switch_id): resource = "logical-switches/%s" % logical_switch_id return client.get_resource(resource)
def update_resource_with_retry(resource, payload): revised_payload = client.get_resource(resource) for key_name in payload.keys(): revised_payload[key_name] = payload[key_name] return client.update_resource(resource, revised_payload)
def get_edge_cluster(edge_cluster_uuid): resource = "edge-clusters/%s" % edge_cluster_uuid return client.get_resource(resource)
def get_qos_switching_profile(profile_id): resource = 'switching-profiles/%s' % profile_id return client.get_resource(resource)
def get_version(): node = client.get_resource("node") version = node.get('node_version') return version
def read_section(section_id): resource = 'firewall/sections/%s' % section_id return nsxclient.get_resource(resource)
def read_nsgroup(nsgroup_id): return nsxclient.get_resource( 'ns-groups/%s?populate_references=true' % nsgroup_id)
def list_nsgroups(): return nsxclient.get_resource('ns-groups?populate_references=false').get( 'results', [])