I want to tag a resource given its id and its type programmatically. It may be a SoftLayer_Virtual_Guest or any other taggable resource, doesn't matter. The SoftLayer_Tag/setTag api takes as parameters the tagname, the keyName, and the resource id. So, where do I find the keyName for tagging a given resource type? I know I can get all tag types using the SoftLayer_Tag/getAllTagTypes, but how do I relate the keyNames with the resource type I need to tag? Is this mapping documented somewhere? Is there some api I can leverage?
Asked
Active
Viewed 88 times
1 Answers
0
There is not way to retrieve the same keyName values from the devices, the only way is by using a conditional in your script or code, for example if you are using Softlayer_Account::getVirtualGuests to retrieve virtual servers then you should put GUEST in the request as following:
https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Tag/setTags
Method: Post
{
"parameters":[
"tag1,tag2",
"GUEST",
29756959
]
}
Now, if you are using advancedSearch to retrieve the list of resources, then you can know the resourceType and on this case you could use the conditional IF, for example:
for item in items:
resourceId = item['resource']['id']
if item['resourceType'] == "SoftLayer_Hardware":
keyName = "HARDWARE"
if item['resourceType'] == "SoftLayer_Network_Vlan_Firewall":
keyName = "NETWORK_VLAN_FIREWALL"
.....
.....
result = client['Tag'].setTag("tag1,tag2", keyName, resourceId)
I think the following table could help you at the moment to set the correct keyName.
+----------------------+------------------------------------------------------+---------------------------------+ | Object or Device | Resource or Datatype | SoftLayer_Tag::getAllTagTypes | | | | (keyName) | +----------------------+------------------------------------------------------+---------------------------------+ | Bare Metal Server | SoftLayer_Hardware_Server | HARDWARE | | Gateway Member | SoftLayer_Hardware (networkGatewayMemberFlag = true) | HARDWARE | | Virtual Server | SoftLayer_Virtual_Guest | GUEST | | Ticket | SoftLayer_Ticket | TICKET | | FireWall (Dedicated) | SoftLayer_Network_Vlan_Firewall | NETWORK_VLAN_FIREWALL | | Images | SoftLayer_Virtual_Guest_Block_Device_Template_Group | IMAGE_TEMPLATE | | NetScalers | SoftLayer_Network_Application_Delivery_Controller | APPLICATION_DELIVERY_CONTROLLER | | Vlans | SoftLayer_Network_Vlan | NETWORK_VLAN | | Dedicated Hosts | SoftLayer_Virtual_DedicatedHost | DEDICATED_HOST | +----------------------+------------------------------------------------------+---------------------------------+
Some links:

Albert Camacho
- 1,129
- 1
- 7
- 13