def do_export_server(args): '''Export 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} if args.path is None: work_dir = os.getcwd() else: work_dir = args.path if os.path.exists(work_dir) is False: os.makedirs(work_dir) disk = os.path.join(work_dir, 'disk') meta = os.path.join(work_dir, 'server.json') logger.info("Get server's info, please waiting ...") server_info = bcec_utils.get_server_info(env, args.name) logger.info("Get server's info done") with open(meta, 'w') as f: json.dump(server_info, f) snap_name = ''.join([args.name, '-export', '-snap']) logger.info("Make snapshot, this will take sometimes, please waiting ...") _, image_size, image_id = bcec_utils.server_snapshot(env, args.name, snap_name) logger.info("Make snapshot done") logger.info("Download image, this will take sometimes, please waiting ...") bcec_utils.image_download(env, image_id, disk) logger.info("Download image done") logger.info("Export done")
def do_export_ovf(args): '''Export the server to an ovf''' # 1. get server info # 2. snapshot and download image # 3. convert image # 4. write ovf file #step1 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("Get server's info, please waiting ...") server_info = bcec_utils.get_server_info(env, args.server) logger.info("Get server's info done") if args.path is None: work_dir = os.getcwd() else: work_dir = args.path if os.path.exists(work_dir) is False: os.makedirs(work_dir) src_image = os.path.join(work_dir, ''.join([args.name, ".qcow2" ])) #step2: snap_name = ''.join([args.name, '-ovf', '-snap']) logger.info("Make snapshot, this will take sometimes, please waiting ...") _, image_size, image_id = bcec_utils.server_snapshot(env, args.server, snap_name) logger.info("Make snapshot done") logger.info("Download image, this will take sometimes, please waiting ...") src_image = os.path.join(work_dir, ''.join([args.name, '-ovf-disk1' ".qcow2"])) bcec_utils.image_download(env, image_id, src_image) logger.info("Download image done") #step3 #image_size = bcec_utils.get_image_size(env, snap_name) dest_image = os.path.join(work_dir, ''.join([args.name, '-ovf-disk1' ".vmdk"])) logger.info("Convert image to vmdk format, please waiting ...") bcec_utils.image_convert("qcow2", src_image, "vmdk" , dest_image) logger.info("Convert image done") server_info['disk'] = ''.join([args.name, '-ovf-disk1' ".vmdk"]) server_info['disk_capacity'] = image_size #step4 ovf_path = os.path.join(work_dir, ''.join([args.name, ".ovf" ])) bcec_utils.create_ovf(server_info, ovf_path) logger.info("Create ovf done")