Skip to content

Commit

Permalink
Merge pull request #3725 from vwu-vera/vpx_nouser
Browse files Browse the repository at this point in the history
v2v: add function for vpx without username
  • Loading branch information
chunfuwen authored Jul 26, 2023
2 parents 07f72ff + ab3e51a commit 77c9a17
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions virttest/utils_v2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,30 @@ def get_uri(self, hostname, vpx_dc=None, esx_ip=None, username=None):
Uri dispatcher.
:param hostname: String with host name.
:param vpx_dc: String with vpx data center.
:param esx_ip: String with ESX server IP address.
"""
uri_func = getattr(self, "_get_%s_uri" % self.hyper)
self.host = hostname
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.
:param vpx_dc: String with vpx data center.
:param esx_ip: String with ESX server IP address.
"""
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 +110,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 +209,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 +604,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 +1353,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 +1381,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 77c9a17

Please sign in to comment.