Closed NAVEEVXB closed 1 year ago
When you say CheckRelocate gives success, are you basing that on the task not failing, or the task.info.result[] not containing any error objects? (e.g. assert len(task.info.result[0].error) == 0)
In your spec
, I don't see service
property. Did you just exclude that from your example?
hi. Thanks for the reply. during the checkRelocate, the task.info.state comes back with success. error is empty
For the Service property it says it is not mandatory. I have not used it. I have provided destination host/resource pool and other details as part of relocateSpec. Is this mandatory for cross vcenter migration? if so, how can I setup?
I tried to add the service property, but I am not able to get the sslThumbprint from the destnation host. host.config.sslThumbPrintData comes with len = 0 or sslThumbprintInfo comes with None. Why and how can I get the SSL Thumbprint info?
One other observation, when without providing sslThumbprint property, it gives an error "Authencity is failed for SSL verfication something..." and when I check the task object returned by the vcenter, it has a sslThumbprint data, which when I provide as value to sslThumbprint, it works like Magic. I am wondering, how does the vCenter task object get the sslThumbprint data and why I am not able to get it from the host?
For the Service property it says it is not mandatory.
It is only mandatory for doing a cross vCenter migration. You will need to provide a proper sslThumbprint value. There are various ways to get it, although I don't think any are built into pyVmomi itself. User likely would want to validate they are connecting to the correct vCenter...
cmd = 'openssl s_client -connect %s:443 </dev/null 2>&1 |' % hostname + \
'openssl x509 -noout -fingerprint|cut -d"=" -f 2'
this might be some subprocess command you run to generate it (assuming you have openssl cli). Based on https://community.rsa.com/t5/securid-knowledge-base/how-to-view-a-certificate-fingerprint-as-sha-256-sha-1-or-md5/ta-p/4230
hi. Thanks for the reply. during the checkRelocate, the task.info.state comes back with success. error is empty
You would want to look at the task.info.result value. The task itself generates a list of errors and warnings. Usually it runs successfully, so something like the UI has a localized list of messages to give back to the user. An error fault is limited in how it can be represented (typically just 1 localized string with some arguments substituted).
Thanks @prziborowski for your help. I was able to resolve it successfully. Your feedback on setting the "Service" property was the missing link in the first place for cross vcenter migration activity. . I also used openssl to get the sshThumbprint from the destination host. Here is the latest code for your reference.
def connect(self):
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.verify_mode = ssl.CERT_REQUIRED
try:
si = SmartConnect(host=self.host_name, user=self.username, pwd=self.password, sslContext=context)
self.si = si
self.ssl = True
#ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
except Exception as ex:
if 'CERTIFICATE_VERIFY_FAILED' in str(ex):
try:
context.verify_mode = ssl.CERT_NONE
si = SmartConnect(host=self.host_name, user=self.username, pwd=self.password, sslContext=context)
self.si = si
self.ssl=False
ctx = ssl.SSLContext()
except Exception as ex:
raise ConnectException(ex)
else:
raise ConnectException("Unable to Connect")
finally:
if self.si is not None:
url = "https://" + self.host_name
self.siUUID = self.si.RetrieveContent().about.instanceUuid
content = self.si.RetrieveContent()
sm = content.sessionManager
session = sm.AcquireCloneTicket()
vc_cert = ssl.get_server_certificate((self.host_name, (443)))
vc_pem = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
vc_cert)
vc_fingerprint = vc_pem.digest('sha1')
self.thumbprint = vc_fingerprint.decode()
Above code is for connecting to host, and I use this as a placeholder to collect sshThumbprint.
This is how I am setting up the service property.
service = vim.ServiceLocator()
credentials = vim.ServiceLocator.Credential()
pwd = vim.ServiceLocator.NamePassword()
pwd.username = self.target_username
pwd.password = self.target_password
credentials = pwd
service.credential = credentials
service.instanceUuid = self.target_obj.siUUID
service.url = "https://" + self.target_host_name #+ ":443/sdk"
#dest_host = vim.HostSystem
#tick = dest_host.AcquireCimServicesTicket()
service.sslThumbprint = self.target_obj.thumbprint
spec.service = service
This worked like magic. Thanks again for your support.
Regards Naveen
Describe the bug
I am trying to do a cross vcenter migration using pyvmomi. I have set the network as well and assigned them as part of the deviceChange property. code for that is as follows. here is the code that I have written,
Reproduction steps
1. 2. 3. ...
Expected behavior
Even when I do not change network or not initialize deviceChange property of relocateSpec, it gives similar error. What am I doing wrong?
Additional context
No response