def main(): utils.check_login_user() # parse input option argv = [encode.convert_to_unicode(a) for a in sys.argv[1:]] args = get_parser().parse_args(argv) # read and check args kwargs = {} if args.name is not None: kwargs['name'] = args.name if args.metadata is not None: kwargs['metadata'] = args.metadata if args.description is not None: kwargs['description'] = args.description if args.file_name is not None: kwargs['file_name'] = args.file_name if args.fpga_image_id is not None: kwargs['fpga_image_id'] = args.fpga_image_id if args.image_id is not None: kwargs['image_id'] = args.image_id if args.page is not None: kwargs['page'] = args.page if args.size is not None: kwargs['size'] = args.size try: utils.check_param(**kwargs) except Exception as e: utils.exit('Error: %s' % encode.exception_to_unicode(e)) # read and check config file config.read_config_and_verify() access_key = os.getenv('OS_ACCESS_KEY') secret_key = os.getenv('OS_SECRET_KEY') bucket_name = os.getenv('OS_BUCKET_NAME') region_id = os.getenv('OS_REGION_ID') domain_id = os.getenv('OS_DOMAIN_ID') project_id = os.getenv('OS_PROJECT_ID') obs_endpoint = os.getenv('OS_OBS_ENDPOINT') vpc_endpoint = os.getenv('OS_VPC_ENDPOINT') fis_endpoint = os.getenv('OS_FIS_ENDPOINT') try: # configure intranet dns of ecs config.configure_intranet_dns_ecs(region_id) # check bucket utils._check_bucket_acl_location(bucket_name, access_key, secret_key, obs_endpoint, region_id, domain_id) # check fis rest.fpga_image_relation_list(access_key, secret_key, project_id, region_id, fis_endpoint) except Exception as e: utils.exit('Error: %s' % encode.exception_to_unicode(e)) if kwargs: print('fis argument(s) and config file are OK') else: print('fis config file is OK')
def do_fpga_image_relation_list(args): """Query FPGA image relations visible to a tenant""" kwargs = OrderedDict() if args.image_id is not None: kwargs['image_id'] = args.image_id if args.fpga_image_id is not None: kwargs['fpga_image_id'] = args.fpga_image_id if args.page is not None and args.size is not None: kwargs['page'] = args.page kwargs['size'] = args.size elif args.page is not None and args.size is None\ or args.page is None and args.size is not None: utils.print_err('Error: argument --page and --size ' 'must exist or not exist at the same time') return utils.check_param(**kwargs) status_code, reason, body = rest.fpga_image_relation_list(*_get_config(), params=kwargs) if status_code != 200 or not isinstance(body, dict): raise FisException(_invalid_resp(status_code, reason, body)) _do_resp(status_code, reason) relation_list = [] for relations in body.get('associations', []): image_id = relations.get('image_id', None) for fpga_image in relations.get('fpgaimages', []): relation = {} relation['image_id'] = image_id relation.update(fpga_image) relation['fpga_image_id'] = relation.get('id', None) relation_list.append(relation) columns = [ 'image_id', 'fpga_image_id', 'name', 'status', 'protected', 'size', 'createdAt', 'description', 'metadata', 'message' ] utils.print_list(relation_list, columns) if args.image_id is None and args.fpga_image_id is None: print( 'Tips: The FPGA image relations can only be obtained if at least one of the \033[31m--fpga-image-id\033[0m and \033[31m--image-id\033[0m arguments is specified, otherwise only an empty list is returned.' )