X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fvimconn_vmware.py;h=d4b83e5486399bf28219aaf9e8c8ae49a4f0025d;hb=f6bbe22d9906cde52f86658daa9ee444f2ec3a6e;hp=2910e92496878ba67050c5fda3c9dbfbc7c2a99e;hpb=ebd66721b39fda2bf315102db63ea7e0dcf7becc;p=osm%2FRO.git diff --git a/osm_ro/vimconn_vmware.py b/osm_ro/vimconn_vmware.py index 2910e924..d4b83e54 100644 --- a/osm_ro/vimconn_vmware.py +++ b/osm_ro/vimconn_vmware.py @@ -76,7 +76,7 @@ DEFAULT_IP_PROFILE = {'dhcp_count':50, INTERVAL_TIME = 5 MAX_WAIT_TIME = 1800 -API_VERSION = '5.9' +API_VERSION = '31.0' __author__ = "Mustafa Bayramov, Arpita Kate, Sachin Bhangare, Prakash Kasar" __date__ = "$09-Mar-2018 11:09:29$" @@ -297,13 +297,13 @@ class vimconnector(vimconn.vimconnector): Returns: The return client object that latter can be used to connect to vcloud director as admin for provider vdc """ - self.logger.debug("Logging into vCD {} as admin.".format(self.org_name)) try: host = self.url org = 'System' client_as_admin = Client(host, verify_ssl_certs=False) + client_as_admin.set_highest_supported_version() client_as_admin.set_credentials(BasicLoginCredentials(self.admin_user, org, self.admin_password)) except Exception as e: raise vimconn.vimconnException( @@ -317,13 +317,13 @@ class vimconnector(vimconn.vimconnector): Returns: The return client object that latter can be used to connect to vCloud director as admin for VDC """ - try: self.logger.debug("Logging into vCD {} as {} to datacenter {}.".format(self.org_name, self.user, self.org_name)) host = self.url client = Client(host, verify_ssl_certs=False) + client.set_highest_supported_version() client.set_credentials(BasicLoginCredentials(self.user, self.org_name, self.passwd)) except: raise vimconn.vimconnConnectionException("Can't connect to a vCloud director org: " @@ -3018,7 +3018,7 @@ class vimconnector(vimconn.vimconnector): else: self.logger.error("action_vminstance: Failed to {} vApp: {}".format(action, vapp_name)) - def get_vminstance_console(self, vm_id, console_type="vnc"): + def get_vminstance_console(self, vm_id, console_type="novnc"): """ Get a console for the virtual machine Params: @@ -3032,7 +3032,57 @@ class vimconnector(vimconn.vimconnector): port: the http, ssh, ... port suffix: extra text, e.g. the http path and query string """ - raise vimconn.vimconnNotImplemented("Should have implemented this") + console_dict = {} + + if console_type==None or console_type=='novnc': + + url_rest_call = "{}/api/vApp/vm-{}/screen/action/acquireMksTicket".format(self.url, vm_id) + + headers = {'Accept':'application/*+xml;version=' + API_VERSION, + 'x-vcloud-authorization': self.client._session.headers['x-vcloud-authorization']} + response = self.perform_request(req_type='POST', + url=url_rest_call, + headers=headers) + + if response.status_code == 403: + response = self.retry_rest('GET', url_rest_call) + + if response.status_code != 200: + self.logger.error("REST call {} failed reason : {}"\ + "status code : {}".format(url_rest_call, + response.content, + response.status_code)) + raise vimconn.vimconnException("get_vminstance_console : Failed to get "\ + "VM Mks ticket details") + s = re.search("(.*?)",response.content) + console_dict['server'] = s.group(1) if s else None + s1 = re.search("(\d+)",response.content) + console_dict['port'] = s1.group(1) if s1 else None + + + url_rest_call = "{}/api/vApp/vm-{}/screen/action/acquireTicket".format(self.url, vm_id) + + headers = {'Accept':'application/*+xml;version=' + API_VERSION, + 'x-vcloud-authorization': self.client._session.headers['x-vcloud-authorization']} + response = self.perform_request(req_type='POST', + url=url_rest_call, + headers=headers) + + if response.status_code == 403: + response = self.retry_rest('GET', url_rest_call) + + if response.status_code != 200: + self.logger.error("REST call {} failed reason : {}"\ + "status code : {}".format(url_rest_call, + response.content, + response.status_code)) + raise vimconn.vimconnException("get_vminstance_console : Failed to get "\ + "VM console details") + s = re.search(">.*?/(vm-\d+.*)