Example #1
0
    def parse_error(self):
        text = None
        body = self.parse_body()

        if self.has_content_type('application/xml'):
            text = '; '.join(
                [err.text or '' for err in body.getiterator() if err.text])
        elif self.has_content_type('application/json'):
            values = list(body.values())

            context = self.connection.context
            driver = self.connection.driver
            key_pair_name = context.get('key_pair_name', None)

            if len(values) > 0 and values[0]['code'] == 404 and key_pair_name:
                raise KeyPairDoesNotExistError(name=key_pair_name,
                                               driver=driver)
            elif len(values) > 0 and 'message' in values[0]:
                text = ';'.join(
                    [fault_data['message'] for fault_data in values])
            else:
                text = body
        else:
            # while we hope a response is always one of xml or json, we have
            # seen html or text in the past, its not clear we can really do
            # something to make it more readable here, so we will just pass
            # it along as the whole response body in the text variable.
            text = body

        return '%s %s %s' % (self.status, self.error, text)
Example #2
0
 def get_key_pair(self, name):
     try:
         key_material = self.key_pairs[name]
     except KeyError:
         raise KeyPairDoesNotExistError(name, self)
     return KeyPair(name, key_material,
                    get_key_fingerprint(parse_openssh_pubkey(key_material)),
                    self)
Example #3
0
 def _key_name_to_id(self, name):
     result = self.connection.request('SoftLayer_Account',
                                      'getSshKeys').object
     key_id = [x for x in result if x['label'] == name]
     if len(key_id) == 0:
         raise KeyPairDoesNotExistError(name, self)
     else:
         return int(key_id[0]['id'])
Example #4
0
 def _key_name_to_id(self, name):
     result = self.connection.request("SoftLayer_Account",
                                      "getSshKeys").object
     key_id = [x for x in result if x["label"] == name]
     if len(key_id) == 0:
         raise KeyPairDoesNotExistError(name, self)
     else:
         return int(key_id[0]["id"])