예제 #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
예제 #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
예제 #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
                 
예제 #4
0
    def _login(self):
        logger.info("try to login vcloud.")

        url = self.base_url + '/api/sessions'
        encode = "Basic " + base64.standard_b64encode(self.username + "@" +
                                                      self.org + ":" +
                                                      self.password)
        headers = {
            "Authorization": encode.rstrip(),
            "Accept": "application/*+xml;version=" + self.version
        }
        response = rest_execute(method="post",
                                url=url,
                                headers=headers,
                                verify=self.verify)

        if not response:
            logger.error("vcloud login failed, "
                         "host: %s, username: %s, org: %s" %
                         (self.base_url, self.username, self.org))
            return False

        if response.status_code == requests.codes.ok:
            logger.info("login vcloud success.")
            self.token = response.headers["x-vcloud-authorization"]
            session = sessionType.parseString(response.content, True)
            self.query_url = filter(
                lambda link: link.type_ ==
                'application/vnd.vmware.vcloud.query.queryList+xml',
                session.Link)[0].href
            return True

        elif response.status_code == requests.codes.unauthorized:
            logger.error("vcloud authorize failed, "
                         "host: %s, username: %s, org: %s" %
                         (self.base_url, self.username, self.org))
            return False

        else:
            logger.error(
                "vcloud authorize failed, "
                "host: %s, username: %s, org: %s, response_code: %s" %
                (self.base_url, self.username, self.org, response.status_code))
            return False
예제 #5
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
    def _login(self):
        logger.info("try to login vcloud.")

        url = self.base_url + '/api/sessions'
        encode = "Basic " + base64.standard_b64encode(
            self.username + "@" + self.org + ":" + self.password)
        headers = {"Authorization": encode.rstrip(),
                   "Accept": "application/*+xml;version=" + self.version}
        response = rest_execute(method="post", url=url,
                                headers=headers, verify=self.verify)

        if not response:
            logger.error("vcloud login failed, "
                         "host: %s, username: %s, org: %s"
                         % (self.base_url, self.username, self.org))
            return False

        if response.status_code == requests.codes.ok:
            logger.info("login vcloud success.")
            self.token = response.headers["x-vcloud-authorization"]
            session = sessionType.parseString(response.content, True)
            self.query_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.query.queryList+xml', session.Link)[0].href
            return True

        elif response.status_code == requests.codes.unauthorized:
            logger.error("vcloud authorize failed, "
                         "host: %s, username: %s, org: %s"
                         % (self.base_url, self.username, self.org))
            return False

        else:
            logger.error("vcloud authorize failed, "
                         "host: %s, username: %s, org: %s, response_code: %s"
                         % (self.base_url, self.username, self.org,
                            response.status_code))
            return False