我想以编程方式给定资源的id和类型。可能是SoftLayer_Virtual_Guest或任何其他可标记资源,都没有关系。 SoftLayer_Tag / setTag api将标记名,键名和资源ID作为参数。因此,在哪里可以找到用于标记给定资源类型的keyName?我知道我可以使用SoftLayer_Tag / getAllTagTypes获得所有标记类型,但是如何将keyNames与需要标记的资源类型相关联?此映射是否记录在某处?我可以使用一些API吗?
答案 0 :(得分:0)
没有办法从设备中检索相同的keyName值,唯一的方法是在脚本或代码中使用条件,例如,如果您使用Softlayer_Account::getVirtualGuests来检索虚拟服务器,则应将在请求中 GUEST ,如下:
https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Tag/setTags
Method: Post
{
"parameters":[
"tag1,tag2",
"GUEST",
29756959
]
}
现在,如果您正在使用advancedSearch来检索资源列表,那么您可以知道resourceType,在这种情况下,您可以使用条件IF,例如:
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)
我认为下表目前可以帮助您设置正确的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 | +----------------------+------------------------------------------------------+---------------------------------+
一些链接: