I am using Django Rest API on open stack version 2.1 Unable to update Server Tags it is giving response text:'{"itemNotFound": {"code": 404, "message": "The resource could not be found."}}' the code explanation is there is an array of object contains multiple server objects with updated tags within a loop it will request and append responses in an array for front-end
@classmethod
def update_tags(self, params):
check(self, params)
responses = []
try:
headers = {
"X-Auth-Token": params.headers['x-auth-token'],
"Content-type": 'application/json'
}
for server in params.data['payload']:
replace_tags = {"tags": server["tags"]}
response=requests.put(os.environ.get('PROTOCOL')+'://'+os.environ.get('OPENSTACK_HOST')+':'+os.environ.get('COMPUTE_PORT')+'/v2.1/servers/' +server['id']+'/tags', data=json.dumps(replace_tags), headers=headers, verify=False)
responses.append(response)
return responses
except Exception as e:
raise e
parameters which are being passed from check method which is written below
def check(self, params):
self.connection = get_openstack_conn(params)
the get_openstack_conn method
def get_openstack_conn(params):
token = params.META.get("HTTP_X_AUTH_TOKEN")
scope = params.META.get("HTTP_X_SCOPE")
organization = params.META.get("HTTP_X_ORG")
print("environment variables")
print("PROTOCOL = ",os.environ.get('PROTOCOL'))
print("OPENSTACK_HOST = ",os.environ.get('OPENSTACK_HOST'))
print("KEY_STONE_PORT = ",os.environ.get('KEY_STONE_PORT'))
if(scope == 'projectScope'):
connector = openstack.connect(auth_url=os.environ.get('PROTOCOL')+'://'+os.environ.get('OPENSTACK_HOST') +
':'+os.environ.get('KEY_STONE_PORT')+'/v3', verify=False, auth_type="token", token=token, project_id=organization)
elif(scope == 'domainScope'):
connector = openstack.connect(auth_url=os.environ.get('PROTOCOL')+'://'+os.environ.get('OPENSTACK_HOST') +
':'+os.environ.get('KEY_STONE_PORT')+'/v3', verify=False, auth_type="token", token=token, domain_id=organization)
return connector