Skip to content

Commit

Permalink
v2v: add function for vpx without username
Browse files Browse the repository at this point in the history
Signed-off-by: vwu-vera <[email protected]>
  • Loading branch information
vwu-vera committed Jul 21, 2023
1 parent e20d6f4 commit ec049ed
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions virttest/utils_v2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def get_uri(self, hostname, vpx_dc=None, esx_ip=None, username=None):
self.vpx_dc = vpx_dc
self.esx_ip = esx_ip
self.username = username if username else 'root'
self.vpx_no_username = False
return uri_func()

def get_uri_without_username(self, hostname, vpx_dc=None, esx_ip=None):
"""
Uri dispatcher.
:param hostname: String with host name.
"""
uri_func = getattr(self, "_get_%s_uri" % self.hyper)
self.host = hostname
self.vpx_dc = vpx_dc
self.esx_ip = esx_ip
self.vpx_no_username = True
return uri_func()

def _get_kvm_uri(self):
Expand All @@ -92,12 +106,21 @@ def _get_esx_uri(self):
"""
uri = ''
if self.vpx_dc and self.esx_ip:
uri = "vpx://%s@%s/%s/%s/?no_verify=1" % (self.username,
self.host,
self.vpx_dc,
self.esx_ip)
if self.vpx_no_username:
uri = "vpx://%s/%s/%s/?no_verify=1" % (
self.host,
self.vpx_dc,
self.esx_ip)
else:
uri = "vpx://%s@%s/%s/%s/?no_verify=1" % (self.username,
self.host,
self.vpx_dc,
self.esx_ip)
if not self.vpx_dc and self.esx_ip:
uri = "esx://%s@%s/?no_verify=1" % (self.username, self.esx_ip)
if self.vpx_no_username:
uri = "esx://%s/?no_verify=1" % (self.esx_ip)
else:
uri = "esx://%s@%s/?no_verify=1" % (self.username, self.esx_ip)
return uri

# add new hypervisor in here.
Expand Down Expand Up @@ -182,6 +205,7 @@ def get_cmd_options(self, params):
self.input_file = self.params.get('input_file')
self.new_name = self.params.get('new_name')
self.username = self.params.get('username', 'root')
self.vpx_no_username = self.params.get('vpx_no_username')
self.vmx_nfs_src = self.params.get('vmx_nfs_src')
self.has_genid = self.params.get('has_genid')
# --mac arguments with format as v2v, multiple macs can be
Expand Down Expand Up @@ -576,6 +600,7 @@ def __init__(self, test, params, env):
self.os_type = params.get('os_type', 'linux')
self.target = params.get('target')
self.username = params.get('vm_user', 'root')
self.vpx_no_username = params.get('vpx_no_username')
self.password = params.get('vm_pwd')
self.nic_index = params.get('nic_index', 0)
self.export_name = params.get('export_name')
Expand Down Expand Up @@ -1324,6 +1349,7 @@ def _v2v_post_cmd():
hostname = params.get('hostname')
vpx_dc = params.get('vpx_dc')
esxi_host = params.get('esxi_host', params.get('esx_ip'))
vpx_no_username = params.get('vpx_no_username')
opts_extra = params.get('v2v_opts')
# Set v2v_cmd_timeout to 5 hours, the value can give v2v enough time to execute,
# and avoid v2v process be killed by mistake.
Expand Down Expand Up @@ -1351,7 +1377,10 @@ def _v2v_post_cmd():
# Return actual 'uri' according to 'hostname' and 'hypervisor'
if src_uri_type == 'esx':
vpx_dc = None
uri = uri_obj.get_uri(hostname, vpx_dc, esxi_host, vpx_username)
if vpx_no_username:
uri = uri_obj.get_uri_without_username(hostname, vpx_dc, esxi_host)
else:
uri = uri_obj.get_uri(hostname, vpx_dc, esxi_host, vpx_username)

try:
# Pre-process for v2v
Expand Down

0 comments on commit ec049ed

Please sign in to comment.