def reference_lookup(self, resource_table_id, tag_type): """Returns the SoftLayer Service for the corresponding type :param int resource_table_id: Tag_Reference::resourceTableId :param string tag_type: Tag_Reference->tagType->keyName From SoftLayer_Tag::getAllTagTypes() |Type |Service | | ----------------------------- | ------ | |Hardware |HARDWARE| |CCI |GUEST| |Account Document |ACCOUNT_DOCUMENT| |Ticket |TICKET| |Vlan Firewall |NETWORK_VLAN_FIREWALL| |Contract |CONTRACT| |Image Template |IMAGE_TEMPLATE| |Application Delivery Controller |APPLICATION_DELIVERY_CONTROLLER| |Vlan |NETWORK_VLAN| |Dedicated Host |DEDICATED_HOST| """ service = self.type_to_service(tag_type) if service is None: raise SoftLayerAPIError( 404, "Unable to lookup {} types".format(tag_type)) return self.client.call(service, 'getObject', id=resource_table_id)
def get_translation(self, context_id, translation_id): """Retrieves a translation entry for the given id values. :param int context_id: The id-value representing the context instance. :param int translation_id: The id-value representing the translation instance. :return dict: Mapping of properties for the translation entry. :raise SoftLayerAPIError: If a translation cannot be found. """ translation = next((x for x in self.get_translations(context_id) if x['id'] == translation_id), None) if translation is None: raise SoftLayerAPIError('SoftLayer_Exception_ObjectNotFound', 'Unable to find object with id of \'{}\'' .format(translation_id)) return translation
def test_list_detail_ungettable(self): mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject') mock.side_effect = SoftLayerAPIError(404, "TEST ERROR") result = self.run_command(['tags', 'list', '-d']) self.assert_no_fail(result) self.assertIn("TEST ERROR", result.output) # From fixtures/virutal_guest.getObject # self.assert_called_with('SoftLayer_Tag', 'getUnattachedTagsForCurrentUser') self.assert_called_with('SoftLayer_Tag', 'getAttachedTagsForCurrentUser') self.assert_called_with('SoftLayer_Tag', 'getReferences', identifier=1286571) self.assert_called_with('SoftLayer_Virtual_Guest', 'getObject', identifier=33488921)
def get_tunnel_context(self, context_id, **kwargs): """Retrieves the network tunnel context instance. :param int context_id: The id-value representing the context instance. :return dict: Mapping of properties for the tunnel context. :raise SoftLayerAPIError: If a context cannot be found. """ _filter = utils.NestedDict(kwargs.get('filter') or {}) _filter['networkTunnelContexts']['id'] = utils.query_filter(context_id) kwargs['filter'] = _filter.to_dict() contexts = self.account.getNetworkTunnelContexts(**kwargs) if len(contexts) == 0: raise SoftLayerAPIError('SoftLayer_Exception_ObjectNotFound', 'Unable to find object with id of \'{}\'' .format(context_id)) return contexts[0]