def __init__(self, request_headers, request_query_params, request_spec): self.req_headers = request_headers self.req_qparams = request_query_params self.req_spec = request_spec self.pks_cache = get_pks_cache() self.ovdc_cache = OvdcCache(get_vcd_sys_admin_client()) self.is_ovdc_present_in_request = False config = get_server_runtime_config() self.vcd_client, self.session = connect_vcd_user_via_token( vcd_uri=config['vcd']['host'], headers=self.req_headers, verify_ssl_certs=config['vcd']['verify'])
def info(self, headers): tenant_client, session = connect_vcd_user_via_token( vcd_uri=self.config['vcd']['host'], headers=headers, verify_ssl_certs=self.config['vcd']['verify']) result = Service.version() if tenant_client.is_sysadmin(): result['consumer_threads'] = len(self.threads) result['all_threads'] = threading.activeCount() result['requests_in_progress'] = self.active_requests_count() result['config_file'] = self.config_file result['status'] = self.get_status() else: del result['python'] return result
def _connect_tenant(self): server_config = get_server_runtime_config() host = server_config['vcd']['host'] verify = server_config['vcd']['verify'] self.tenant_client, self.client_session = connect_vcd_user_via_token( vcd_uri=host, headers=self.req_headers, verify_ssl_certs=verify) self.tenant_info = { 'user_name': self.client_session.get('user'), 'user_id': self.client_session.get('userId'), 'org_name': self.client_session.get('org'), 'org_href': self.tenant_client._get_wk_endpoint( _WellKnownEndpoint.LOGGED_IN_ORG) }
def update_status(self, headers, body): tenant_client, session = connect_vcd_user_via_token( vcd_uri=self.config['vcd']['host'], headers=headers, verify_ssl_certs=self.config['vcd']['verify']) reply = {} if tenant_client.is_sysadmin(): if 'enabled' in body: if body['enabled'] and self.should_stop: reply['body'] = { 'message': 'Cannot enable while being stopped.' } reply['status_code'] = 500 else: self.is_enabled = body['enabled'] reply['body'] = {'message': 'Updated'} reply['status_code'] = 200 elif 'stopped' in body: if self.is_enabled: reply['body'] = { 'message': 'Cannot stop CSE while is enabled.' ' Disable the service first.' } reply['status_code'] = 500 else: message = 'CSE graceful shutdown started.' n = self.active_requests_count() if n > 0: message += ' CSE will finish processing %s requests.' \ % n reply['body'] = {'message': message} reply['status_code'] = 200 self.should_stop = True else: reply['body'] = {'message': 'Unknown status'} reply['status_code'] = 500 else: reply['body'] = {'message': 'Unauthorized'} reply['status_code'] = 401 return reply