|
|
|
@ -1179,7 +1179,7 @@ class DecortController(object):
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def compute_affinity(self,comp_dict,tags,aff,aaff,label=""):
|
|
|
|
|
def compute_affinity(self,comp_dict,tags,aff,aaff,label):
|
|
|
|
|
"""
|
|
|
|
|
Manage Compute Tags,Affinitylabel and rules
|
|
|
|
|
@param (dict) comp_dict: dictionary of the Compute parameters
|
|
|
|
@ -1190,34 +1190,46 @@ class DecortController(object):
|
|
|
|
|
"""
|
|
|
|
|
self.result['waypoints'] = "{} -> {}".format(self.result['waypoints'], "compute_affinity")
|
|
|
|
|
|
|
|
|
|
for tag in tags.items():
|
|
|
|
|
if tag not in comp_dict['tags'].items():
|
|
|
|
|
if tags:
|
|
|
|
|
for tag in tags.items():
|
|
|
|
|
if tag not in comp_dict['tags'].items():
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
key=tag[0],
|
|
|
|
|
value=tag[1], )
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/tagAdd", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
if comp_dict['tags']:
|
|
|
|
|
for tag in comp_dict['tags'].items():
|
|
|
|
|
if tag not in tags.items():
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
key=tag[0],)
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/tagRemove", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
else:
|
|
|
|
|
if comp_dict['tags']:
|
|
|
|
|
for tag in comp_dict['tags'].items():
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
key=tag[0],)
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/tagRemove", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
if label:
|
|
|
|
|
if comp_dict['affinityLabel'] == "":
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
key=tag[0],
|
|
|
|
|
value=tag[1], )
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/tagAdd", api_params)
|
|
|
|
|
affinityLabel=label,)
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/affinityLabelSet", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
for tag in comp_dict['tags'].items():
|
|
|
|
|
if tag not in tags.items():
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
key=tag[0],)
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/tagRemove", api_params)
|
|
|
|
|
else:
|
|
|
|
|
if comp_dict['affinityLabel'] != "":
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'])
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/affinityLabelRemove", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
if label and comp_dict['affinityLabel'] != label:
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'],
|
|
|
|
|
affinityLabel=label,)
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/affinityLabelSet", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
elif label == "" and comp_dict['affinityLabel']:
|
|
|
|
|
api_params = dict(computeId=comp_dict['id'])
|
|
|
|
|
self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/affinityLabelRemove", api_params)
|
|
|
|
|
self.result['failed'] = False
|
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
affrule_del = []
|
|
|
|
|
affrule_add = []
|
|
|
|
@ -1225,24 +1237,28 @@ class DecortController(object):
|
|
|
|
|
aaffrule_add = []
|
|
|
|
|
|
|
|
|
|
#AFFINITY
|
|
|
|
|
for rule in comp_dict['affinityRules']:
|
|
|
|
|
del rule['guid']
|
|
|
|
|
if rule not in aff:
|
|
|
|
|
affrule_del.append(rule)
|
|
|
|
|
if comp_dict['affinityRules']:
|
|
|
|
|
for rule in comp_dict['affinityRules']:
|
|
|
|
|
del rule['guid']
|
|
|
|
|
if rule not in aff:
|
|
|
|
|
affrule_del.append(rule)
|
|
|
|
|
|
|
|
|
|
for rule in aff:
|
|
|
|
|
if rule not in comp_dict['affinityRules']:
|
|
|
|
|
affrule_add.append(rule)
|
|
|
|
|
if aff:
|
|
|
|
|
for rule in aff:
|
|
|
|
|
if rule not in comp_dict['affinityRules']:
|
|
|
|
|
affrule_add.append(rule)
|
|
|
|
|
|
|
|
|
|
#ANTI AFFINITY
|
|
|
|
|
for rule in comp_dict['antiAffinityRules']:
|
|
|
|
|
del rule['guid']
|
|
|
|
|
if rule not in aaff:
|
|
|
|
|
aaffrule_del.append(rule)
|
|
|
|
|
|
|
|
|
|
for rule in aaff:
|
|
|
|
|
if rule not in comp_dict['antiAffinityRules']:
|
|
|
|
|
aaffrule_add.append(rule)
|
|
|
|
|
if comp_dict['antiAffinityRules']:
|
|
|
|
|
for rule in comp_dict['antiAffinityRules']:
|
|
|
|
|
del rule['guid']
|
|
|
|
|
if rule not in aaff:
|
|
|
|
|
aaffrule_del.append(rule)
|
|
|
|
|
|
|
|
|
|
if aaff:
|
|
|
|
|
for rule in aaff:
|
|
|
|
|
if rule not in comp_dict['antiAffinityRules']:
|
|
|
|
|
aaffrule_add.append(rule)
|
|
|
|
|
|
|
|
|
|
#AFFINITY
|
|
|
|
|
if len (affrule_del):
|
|
|
|
|