@@ -65,6 +65,64 @@ def save(self):
6565 )
6666
6767
68+ class FMCloudTags (object ):
69+ """
70+ A Tenant Cloud Tags in the FM instance
71+ """
72+
73+ def __init__ (self , client , tenant_id , cloud_tags ):
74+ self .client = client
75+ self .tenant_id = tenant_id
76+ self .cloud_tags = json .loads (cloud_tags ["msg" ])
77+
78+ def add_tag (self , key , value ):
79+ """
80+ Add a tag to the tenant
81+
82+
83+ :param str key: Tag key
84+ :param str value: Tag value
85+ """
86+ if key in self .cloud_tags :
87+ raise Exception ("Key already exists" )
88+ self .cloud_tags [key ] = value
89+
90+ def update_tag (self , key , new_key = None , new_value = None ):
91+ """
92+ Update a tag key or value
93+
94+
95+ :param str key: Key of the tag to update
96+ :param str new_key: Optional, new key for the tag
97+ :param str new_value: Optional, new value for the tag
98+ """
99+ if key not in self .cloud_tags :
100+ raise Exception ("Key does not exists" )
101+ if new_value :
102+ self .cloud_tags [key ] = new_value
103+ if new_key :
104+ self .cloud_tags [new_key ] = self .cloud_tags [key ]
105+ del self .cloud_tags [key ]
106+
107+ def delete_tag (self , key ):
108+ """
109+ Delete a tag
110+
111+
112+ :param str key: Key of the tag to delete
113+ """
114+ if key not in self .cloud_tags :
115+ raise Exception ("Key does not exists" )
116+ del self .cloud_tags [key ]
117+
118+ def save (self ):
119+ """Saves the tags on FM"""
120+
121+ self .client ._perform_empty (
122+ "PUT" , "/tenants/%s/cloud-tags" % (self .tenant_id ), body = self .cloud_tags
123+ )
124+
125+
68126class FMCloudAuthentication (dict ):
69127 def __init__ (self , data ):
70128 """
0 commit comments