Skip to content

Commit

Permalink
taking out one glcoud call (#657)
Browse files Browse the repository at this point in the history
rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED

Signed-off-by: Paige Rubendall <[email protected]>
  • Loading branch information
paigerube14 authored Jul 3, 2024
1 parent 5f836f2 commit 0514831
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions kraken/node_actions/gcp_node_scenarios.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sys
import time
import logging
import json
import kraken.node_actions.common_node_functions as nodeaction
from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios
from googleapiclient import discovery
Expand All @@ -10,11 +12,19 @@

class GCP:
def __init__(self):

self.project = runcommand.invoke("gcloud config get-value project").split("/n")[0].strip()
logging.info("project " + str(self.project) + "!")
credentials = GoogleCredentials.get_application_default()
self.client = discovery.build("compute", "v1", credentials=credentials, cache_discovery=False)
try:
gapp_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
with open(gapp_creds, "r") as f:
f_str = f.read()
self.project = json.loads(f_str)['project_id']
#self.project = runcommand.invoke("gcloud config get-value project").split("/n")[0].strip()
logging.info("project " + str(self.project) + "!")
credentials = GoogleCredentials.get_application_default()
self.client = discovery.build("compute", "v1", credentials=credentials, cache_discovery=False)

except Exception as e:
logging.error("Error on setting up GCP connection: " + str(e))
sys.exit(1)

# Get the instance ID of the node
def get_instance_id(self, node):
Expand Down

0 comments on commit 0514831

Please sign in to comment.