Example #1
0
    def handleList(self, conf_info):
        logger.info("start list google projects")
        if (not self.callerArgs
                or not self.callerArgs.get(ggc.google_credentials_name)):
            logger.error("Missing Google credentials")
            raise Exception("Missing Google credentials")

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        logger.info(self.callerArgs[ggc.google_credentials_name])
        config = gconf.get_google_settings(scc.getMgmtUri(),
                                           self.getSessionKey(),
                                           cred_name=stanza_name)
        res_mgr = grm.GoogleResourceManager(logger, config)
        try:
            projects = [project["projectId"] for project in res_mgr.projects()]
        except googleapiclient.errors.HttpError as e:
            if e.resp.status == 403:
                projects = [config[ggc.google_credentials]["project_id"]]
            else:
                raise e
        except Exception as e:
            print(e)
            raise BaseException()
        conf_info["google_projects"].append("projects", projects)
        logger.info("end of listing google projects")
Example #2
0
    def handleList(self, conf_info):
        logger.info("start listing google subscriptions")
        for required in self.valid_params:
            if not self.callerArgs or not self.callerArgs.get(required):
                logger.error('Missing "%s"', required)
                raise Exception('Missing "{}"'.format(required))

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        config = gconf.get_google_settings(scc.getMgmtUri(),
                                           self.getSessionKey(),
                                           cred_name=stanza_name)

        project = self.callerArgs[ggc.google_project][0]
        config.update({
            "service_name":
            "storage",
            "version":
            "v1",
            "scopes":
            ["https://www.googleapis.com/auth/cloud-platform.read-only"]
        })
        storage = create_google_client(config)

        buckets = storage.buckets()
        bucket_names = list()
        request = buckets.list(project=project)
        while request:
            try:
                response = request.execute()
            except googleapiclient.errors.HttpError, exc:
                RH_Err.ctl(400, exc)
            names = [item.get('name') for item in response.get('items')]
            bucket_names.extend(names)
            request = buckets.list_next(request, response)
Example #3
0
    def handleList(self, conf_info):
        logger.info("start listing google cloud monitor metrics")
        for required in self.valid_params:
            if not self.callerArgs or not self.callerArgs.get(required):
                logger.error('Missing "%s"', required)
                raise Exception('Missing "{}"'.format(required))

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        config = gconf.get_google_settings(
            scc.getMgmtUri(), self.getSessionKey(), cred_name=stanza_name)

        project = self.callerArgs[ggc.google_project][0]
        monitor = gmw.GoogleCloudMonitor(logger, config)
        metric_descs = monitor.metric_descriptors(project)
        metrics = [desc["type"] for desc in metric_descs]
        conf_info[gmc.google_metrics].append("metrics", metrics)
        logger.info("end of listing google cloud monitor metrics")
Example #4
0
    def handleList(self, conf_info):
        logger.info("start listing google subscriptions")
        for required in self.valid_params:
            if not self.callerArgs or not self.callerArgs.get(required):
                logger.error('Missing "%s"', required)
                raise Exception('Missing "{}"'.format(required))

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        config = gconf.get_google_settings(scc.getMgmtUri(),
                                           self.getSessionKey(),
                                           cred_name=stanza_name)

        project = self.callerArgs[ggc.google_project][0]
        config[ggc.google_project] = project
        ps = GooglePubSub(config)
        subscriptions = [
            sub["name"].split("/")[-1] for sub in ps.subscriptions()
        ]
        conf_info['google_subscriptions'].append("subscriptions",
                                                 subscriptions)
        logger.info("end of listing google subscriptions")