示例#1
0
    def wmHTTPGet(self):
        """Simply proxies an HTTP GET to another domain, and returns the results."""
        url = uiCommon.getAjaxArg("url")
        try:
            result, err = catocommon.http_get(url, 15)
            if err:
                return "External HTTP request failed.  %s" % err

        except:
            uiCommon.log("Error during HTTP GET." + traceback.format_exc())
            return traceback.format_exc()

        return result
示例#2
0
文件: aws.py 项目: AsherBond/cato
    def GetCloudObjectsAsXML(self, account_id, cloud_id, cloud_object_type, additional_args={}):
        try:
            sXML = ""

            ca = cloud.CloudAccount()
            ca.FromID(account_id)
            if ca.ID is None:
                msg = "Failed to get Cloud Account details for Cloud Account ID [" + account_id + "]."
                logger.error(msg)
                return None, msg

            if cloud_object_type is not None:
                # many reasons why we'd bail here.  Rather than a bunch of testing below, let's just crash
                # if a key field is missing.
                if not cloud_object_type.ID:
                    msg = "Cannot find definition for requested object type [" + cloud_object_type.ID + "]"
                    logger.error(msg)
                    return None, msg

            else:
                msg = "GetCloudObjectType failed for [" + cloud_object_type.ID + "]"
                logger.error(msg)
                return None, msg

            # get the cloud object
            c = cloud.Cloud()
            c.FromID(cloud_id)
            if c.ID is None:
                msg = "Failed to get Cloud details for Cloud ID [" + cloud_id + "]."
                return None, msg

            sURL, err = self.BuildURL(ca, c, cloud_object_type, additional_args)
            if err:
                return None, err

            sXML, err = catocommon.http_get(sURL, 30)
            if err:
                return None, err

            return sXML, None
        except Exception as ex:
            raise Exception(ex)
示例#3
0
    def wmTestCloudConnection(self):
        sAccountID = uiCommon.getAjaxArg("sAccountID")
        sCloudID = uiCommon.getAjaxArg("sCloudID")

        c = cloud.Cloud()
        c.FromID(sCloudID)

        ca = cloud.CloudAccount()
        ca.FromID(sAccountID)

        # NOTE: the Cloud object has a *THIN* copy of the Provider (it doesn't include
        #    products or provider clouds.)
        # But, we actually need a full provider here, so go get it!

        full_provider = cloud.Provider.FromName(c.Provider.Name)
        cot = full_provider.GetObjectTypeByName(c.Provider.TestObject)
        if not cot:
            raise Exception("Unable to find object type [%s] on Provider [%s] in cloud_providers.xml" % (c.Provider.TestObject, c.Provider.Name))

        # different providers libs have different methods for building a url
        url = ""
        if c.Provider.Name.lower() == "amazon aws":
            # Amazon aws, Eucalyptus, and OpenStackAws
            from catocloud import aws
            awsi = aws.awsInterface()
            url, err = awsi.BuildURL(ca, c, cot)
            if err:
                raise Exception(err)
        else:  
            raise Exception("Testing connection to %s not yet supported." % (c.Provider.Name))

        if not url:
            raise Exception("Unable to build API URL.")
        result, err = catocommon.http_get(url, 30)
        if err:
            raise Exception(err)

        return json.dumps({"result": "success", "response": result})