def guest_deploy(self, userid, image_name, transportfiles=None, remotehost=None, vdev=None): """ Deploy image and punch config driver to target """ # Get image location (TODO: update this image location) image_file = "/var/lib/zvmsdk/images/" + image_name # Unpack image file to root disk vdev = vdev or CONF.zvm.user_root_vdev cmd = ['/opt/zthin/bin/unpackdiskimage', userid, vdev, image_file] (rc, output) = zvmutils.execute(cmd) if rc != 0: err_msg = ("unpackdiskimage failed with return code: %d." % rc) output_lines = output.split('\n') for line in output_lines: if line.__contains__("ERROR:"): err_msg += ("\\n" + line.strip()) LOG.error(err_msg) raise exception.ZVMGuestDeployFailed(userid=userid, msg=err_msg) # Purge guest reader to clean dirty data rd = ("changevm %s purgerdr" % userid) with zvmutils.expect_request_failed_and_reraise( exception.ZVMGuestDeployFailed, userid=userid): self._request(rd) # Punch transport files if specified if transportfiles: # Copy transport file to local try: tmp_trans_dir = tempfile.mkdtemp() local_trans = tmp_trans_dir + '/cfgdrv' if remotehost: cmd = [ "/usr/bin/scp", "-B", ("%s:%s" % (remotehost, transportfiles)), local_trans ] else: cmd = ["/usr/bin/cp", transportfiles, local_trans] (rc, output) = zvmutils.execute(cmd) if rc != 0: err_msg = ("copy config drive to local failed with" "return code: %d." % rc) LOG.error(err_msg) raise exception.ZVMGuestDeployFailed(userid=userid, msg=err_msg) # Punch config drive to guest userid rd = ("changevm %(uid)s punchfile %(file)s --class X" % { 'uid': userid, 'file': local_trans }) with zvmutils.expect_request_failed_and_reraise( exception.ZVMGuestDeployFailed, userid=userid): self._request(rd) finally: # remove the local temp config drive folder self._pathutils.clean_temp_folder(tmp_trans_dir)
def is_guest_exist(self, userid): cmd = 'sudo vmcp q %s' % userid output = zvmutils.execute(cmd)[1] if re.search('(^HCP\w\w\w003E)', output): # userid not exist return False return True