def connection(self): creds = deepcopy(self.client_config) if creds.get('insecure', False) and 'ca_file' in creds: del creds['ca_file'] if not self._connection: try: self._connection = get_client(**creds) except AuthorizationFailure as e: if 'sslerror' in str(e).lower(): raise StarlingXFatalException('SSL validation failed.') raise StarlingXFatalException(e) return self._connection
def sysinv(self): if not self._sysinv: self._sysinv = cgts_client.get_client( self.SYSINV_API_VERSION, os_username=self.conf['admin_user'], os_password=self.conf['admin_pwd'], os_auth_url=self.conf['auth_url'], os_project_name=self.conf['admin_tenant'], os_project_domain_name=self.conf['project_domain'], os_user_domain_name=self.conf['user_domain'], os_region_name=self.conf['region_name'], os_service_type='platform', os_endpoint_type='admin') return self._sysinv
def sysinv(self): """Return SysinvClient.""" # To prevent TOX dependency failures, this import is localized. from cgtsclient import client as cgts_client self._sysinv = cgts_client.get_client( SYSINV_API_VERSION, **{ 'os_username': self._session.auth._username, 'os_project_name': self._session.auth._project_name, 'os_password': self._session.auth._password, 'os_auth_url': self._session.auth.auth_url + '/v3', 'os_user_domain_name': self._session.auth._user_domain_name, 'os_project_domain_name': self._session.auth._project_domain_name, 'os_endpoint_type': 'internal' }) return self._sysinv
def main(): try: # Process command line options and arguments, configure logging, # configure debug and show options parse_arguments(show) if not show['diskview'] and not show['vgview']: # both disk and vg views are printed show['all'] = True api_version = utils.env('SYSTEM_API_VERSION', default='1') # Print selected options, and timestamp prog = os.path.basename(sys.argv[0]) ts = datetime.datetime.now() if show['debug']: print("%s: %s options: view:%s System api version: %s" % (prog, ts.isoformat(), show, api_version)) cgts_client_creds = get_system_creds() if not cgts_client_creds['os_username']: raise exc.CommandError("You must provide a username via " "env[OS_USERNAME]") if not cgts_client_creds['os_password']: # priviledge check (only allow Keyring retrieval if we are root) if os.geteuid() == 0: cgts_client_creds['os_password'] = keyring.get_password( 'CGCS', cgts_client_creds['os_username']) else: raise exc.CommandError("You must provide a password via " "env[OS_PASSWORD]") if not cgts_client_creds['os_tenant_name']: raise exc.CommandError("You must provide a tenant_id via " "env[OS_TENANT_NAME]") if not cgts_client_creds['os_auth_url']: raise exc.CommandError("You must provide a auth url via " "env[OS_AUTH_URL]") if not cgts_client_creds['os_region_name']: raise exc.CommandError("You must provide a region_name via " "env[OS_REGION_NAME]") cc = cgts_client.get_client(api_version, **cgts_client_creds) # Get all info and display in table format get_info_and_display(cc, show) sys.exit(0) except KeyboardInterrupt as e: logger.warning('caught: %r, shutting down', e) sys.exit(0) except IOError as e: logger.warning('caught: %r, shutting down', e) sys.exit(0) except Exception as e: logger.error('exception: %r', e, exc_info=1) sys.exit(-4)
def main(self, argv): # Parse args once to find version parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self._setup_debugging(options.debug) # build available subcommands based on version api_version = options.system_api_version subcommand_parser = self.get_subcommand_parser(api_version) self.parser = subcommand_parser # Handle top-level --help/-h before attempting to parse # a command off the command line if options.help or not argv: self.do_help(options) return 0 # Parse args again and call whatever callback was selected args = subcommand_parser.parse_args(argv) # Short-circuit and deal with help command right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 if not (args.os_auth_token and args.system_url): if not args.os_username: raise exc.CommandError("You must provide a username via " "either --os-username or via " "env[OS_USERNAME]") if not args.os_password: # priviledge check (only allow Keyring retrieval if we are root) if os.geteuid() == 0: args.os_password = keyring.get_password( 'CGCS', args.os_username) else: raise exc.CommandError("You must provide a password via " "either --os-password or via " "env[OS_PASSWORD]") if not (args.os_project_id or args.os_project_name): raise exc.CommandError("You must provide a project name via " "either --os-project-name or via " "env[OS_PROJECT_NAME]") if not args.os_auth_url: raise exc.CommandError("You must provide an auth url via " "either --os-auth-url or via " "env[OS_AUTH_URL]") if not args.os_region_name: raise exc.CommandError("You must provide an region name via " "either --os-region-name or via " "env[OS_REGION_NAME]") client = cgclient.get_client(api_version, **(args.__dict__)) try: args.func(client, args) except exc.Unauthorized: raise exc.CommandError("Invalid Identity credentials.")
project_name=os.environ['OS_PROJECT_NAME'], user_domain_name=os.environ['OS_USER_DOMAIN_NAME'], project_domain_name=os.environ['OS_PROJECT_NAME'], project_domain_id=os.environ['OS_PROJECT_DOMAIN_ID']) except KeyError: logging.error('Please source your RC file before execution, ' 'e.g.: `source ~/downloads/admin-rc.sh`') sys.exit(1) os_client_args = {} for key, val in client_args.items(): os_client_args['os_{key}'.format(key=key)] = val os_client_args['os_password'] = os_client_args.pop('os_api_key') os_client_args['os_region_name'] = 'RegionOne' os_client_args['api_version'] = 1 config_client = get_client(**os_client_args) dc_client = client.client(**dc_client_args) class System(object): def __init__(self, api_response): self.api_response = api_response self.id = self.api_response.uuid self.name = self.api_response.name try: self.distributed_cloud_role = \ self.api_response.distributed_cloud_role.lower() except AttributeError: self.distributed_cloud_role = \ self.api_response.distributed_cloud_role