def test_project_of_domain_id_scope_header_pass(self): project_name = uuid.uuid4().hex project_domain_id = uuid.uuid4().hex auth, session = self.create(auth_url=self.TEST_URL, project_name=project_name, project_domain_id=project_domain_id) session.get(self.TEST_URL, authenticated=True) self.assertRequestHeaderEqual('X-Project-Name', project_name) self.assertRequestHeaderEqual('X-Project-Domain-Id', project_domain_id)
async def list_fips(auth_token): url = '%s/floatingips.json' % NEUTRON_ENDPOINT headers = {'content-type': 'application/json', 'X-Auth-Token': auth_token} async with ClientSession() as session: async with session.get(url, headers=headers) as response: response = await response.json() return [s['floating_ip_address'] for s in response['floatingips']]
async def list_images(auth_token): url = '%s/images' % GLANCE_ENDPOINT headers = {'content-type': 'application/json', 'X-Auth-Token': auth_token} async with ClientSession() as session: async with session.get(url, headers=headers) as response: response = await response.json() return [s['name'] for s in response['images']]
async def list_servers(auth_token): url = '%s/servers/detail' % NOVA_ENDPOINT headers = {'content-type': 'application/json', 'X-Auth-Token': auth_token} async with ClientSession() as session: async with session.get(url, headers=headers) as response: response = await response.json() return [s['name'] for s in response['servers']]
def get_last_timestamp(): ts_response = session.get('http://252.3.54.57:8041/v1/metric/' + json_id[0]['id'] + '/measures?aggregation=sum') actual_timestamp = json.loads(ts_response.text)[-1][0][:-6] new_timestamp = datetime.datetime.strptime(actual_timestamp, '%Y-%m-%dT%H:%M:%S') new_timestamp = new_timestamp + datetime.timedelta(1) return new_timestamp
def _get_from_deckhand(design_ref): keystone_args = {} for attr in ('auth_url', 'password', 'project_domain_name', 'project_name', 'username', 'user_domain_name'): keystone_args[attr] = cfg.CONF.get('keystone_authtoken', {}).get(attr) auth = keystoneauth1.identity.v3.Password(**keystone_args) session = keystoneauth1.session.Session(auth=auth) return session.get(design_ref[len(_DECKHAND_PREFIX):], timeout=DH_TIMEOUT)
def _get_from_deckhand(design_ref, ctx=None): keystone_args = {} for attr in ('auth_url', 'password', 'project_domain_name', 'project_name', 'username', 'user_domain_name'): keystone_args[attr] = cfg.CONF.get('keystone_authtoken', {}).get(attr) if ctx is not None: addl_headers = { 'X-CONTEXT-MARKER': ctx.context_marker, 'X-END-USER': ctx.end_user } else: addl_headers = {} auth = keystoneauth1.identity.v3.Password(**keystone_args) session = keystoneauth1.session.Session(auth=auth, additional_headers=addl_headers) return session.get(design_ref[len(_DECKHAND_PREFIX):], timeout=DH_TIMEOUT)
def test_domain_name_scope_header_pass(self): domain_name = uuid.uuid4().hex auth, session = self.create(auth_url=self.TEST_URL, domain_name=domain_name) session.get(self.TEST_URL, authenticated=True) self.assertRequestHeaderEqual('X-Domain-Name', domain_name)
for region in regionsname: mydata = '{ "archive_policy_name": "year_rate", "name":"' + region[ 0] + '" }' response = session.post('http://252.3.54.57:8041/v1/metric/', data=mydata, headers={'Content-Type': 'application/json'}) # -- obtaining IDs -- """ In order to insert the Protezione Civile data stored in the data.json file we need first to issue an HTTP GET request, the HTTP response will be JSON parsed in order to extract the metrics IDs to create the metrics ID list. """ response = session.get('http://252.3.54.57:8041/v1/metric/') metrics_list = json.loads(response.text) for metric in metrics_list: for region in regionsname: if region[0] == metric['name']: region.append(metric['id']) # -- Insert measures through metrics -- """ Issuing of HTTP POST Requests to store data inside Gnocchi: region[1] is the name of the Region (the first letter is in uppercase) region[2] is the extracted ID """ with open('data.json') as json_file: dataj = json.load(json_file)
def _session_request(self, session, request_url): try: return session.get(request_url) except: raise falcon.HTTPUnauthorized('Authentication required', ('Authentication token is invalid.'))