Beispiel #1
0
 def update_session_data(self, token):
     headers = {}
     headers["x-vcloud-authorization"] = token
     headers["Accept"] = "application/*+xml;version=" + self.version
     self.response = Http.get(self.url,
                              headers=headers,
                              verify=self.verify,
                              logger=self.logger)
     if self.response.status_code == requests.codes.ok:
         self.session = sessionType.parseString(
             self.response.content.decode('utf-8'), True)
         self.org_url = [
             link for link in self.session.Link
             if link.type_ == 'application/vnd.vmware.vcloud.org+xml'
         ][0].href
         self.username = self.session.get_user()
         self.user_id = self.session.get_userId().split(':')[-1]
         self.org = self.session.get_org()
         self.org_id = self.org_url.split('/')[-1]
         self.response = Http.get(self.org_url,
                                  headers=headers,
                                  verify=self.verify,
                                  logger=self.logger)
         if self.response.status_code == requests.codes.ok:
             self.token = token
             self.organization = organizationType.parseString(
                 self.response.content.decode('utf-8'), True)
             return True
         else:
             return False
     else:
         return False
Beispiel #2
0
 def login(self, password=None, token=None):
     if token:
         headers = {}
         headers["x-vcloud-authorization"] = token
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = requests.get(self.org_url, headers=headers, verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             self.token = token
             self.organization = organizationType.parseString(self.response.content, True)
             return True
         else:
             return False
     else:
         encode = "Basic " + base64.standard_b64encode(self.username + "@" + self.org + ":" + password)
         headers = {}
         headers["Authorization"] = encode.rstrip()
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = requests.post(self.url, headers=headers, verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             self.token = self.response.headers["x-vcloud-authorization"]
             session = sessionType.parseString(self.response.content, True)
             self.org_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.org+xml', session.Link)[0].href
             return True
         else:
             return False
                 
Beispiel #3
0
 def login(self, password=None, token=None):
     if token:
         headers = {}
         headers["x-vcloud-authorization"] = token
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = requests.get(self.org_url,
                                      headers=headers,
                                      verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             self.token = token
             self.organization = organizationType.parseString(
                 self.response.content, True)
             return True
         else:
             return False
     else:
         encode = "Basic " + base64.standard_b64encode(self.username + "@" +
                                                       self.org + ":" +
                                                       password)
         headers = {}
         headers["Authorization"] = encode.rstrip()
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = requests.post(self.url,
                                       headers=headers,
                                       verify=self.verify)
         if self.response.status_code == requests.codes.ok:
             self.token = self.response.headers["x-vcloud-authorization"]
             session = sessionType.parseString(self.response.content, True)
             self.org_url = filter(
                 lambda link: link.type_ ==
                 'application/vnd.vmware.vcloud.org+xml',
                 session.Link)[0].href
             return True
         else:
             return False
Beispiel #4
0
 def login(self, password=None, token=None):
     if token:
         headers = {}
         headers["x-vcloud-authorization"] = token
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = Http.get(self.org_url, headers=headers, verify=self.verify, logger=self.logger)
         if self.response.status_code == requests.codes.ok:
             self.token = token
             self.organization = organizationType.parseString(self.response.content, True)
             return True
         else:
             return False
     else:
         headers = {}
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = Http.post(self.url, headers=headers, auth=(self.username + "@" + self.org, password), verify=self.verify, logger=self.logger)
         if self.response.status_code == requests.codes.ok:
             self.token = self.response.headers["x-vcloud-authorization"]
             self.session = sessionType.parseString(self.response.content, True)
             self.org_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.org+xml', self.session.Link)[0].href
             return True
         else:
             return False