def do_import_server(args): '''Import the server''' env = {'OS_USERNAME': args.os_username, 'OS_PASSWORD': args.os_password, 'OS_TENANT_NAME': args.os_tenant_name, 'OS_AUTH_URL': args.os_auth_url} meta = os.path.join(args.path, 'server.json') with open(meta, 'r') as f: vm = json.load(f) logger.info("Create image, this will take sometimes, please waiting ...") image_name = ''.join([args.name, '-import']) disk = os.path.join(args.path, 'disk') _, image_id = bcec_utils.image_create(env, image_name, disk) vm['image'] = image_id logger.info("Create image done") logger.info("Create server, please waiting ...") vm['name'] = args.name bcec_utils.create_server(env, vm) logger.info("import server done") logger.info("Import done")
def do_import_ovf(args): '''Import the ovf''' # 1. read ovf file to get ram and vcpu info # 2. convert image # 3. upload image # 4. create vm # step1 vm = bcec_utils.parse_ovf_import(args.file) print vm # step2 logger.info("Convert image to qcow2 format, please wait ...") images = vm['disks'] for image_name in images: dir_path = os.path.dirname(os.path.abspath(args.file)) src_image = os.path.join(dir_path, images[image_name]['href']) dest_image = os.path.join(dir_path, ''.join([image_name.split(".")[0], ".qcow2" ])) bcec_utils.image_convert("vmdk", src_image, "qcow2" , dest_image) logger.info("Convert image done") # step3 image_name = ''.join([args.name, '-ovf']) env = {'OS_USERNAME': args.os_username, 'OS_PASSWORD': args.os_password, 'OS_TENANT_NAME': args.os_tenant_name, 'OS_AUTH_URL': args.os_auth_url} logger.info("Create image, this will take sometimes, please waiting ...") _, image_id = bcec_utils.image_create(env, image_name, dest_image) vm['image'] = image_id logger.info("Create image done") logger.info("Create server, please waiting ...") vm['name'] = args.name bcec_utils.create_server(env, vm) logger.info("import server done")