Skip to content

Commit

Permalink
gcp auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarsh2001 committed Oct 4, 2023
1 parent 0624f36 commit a0a7a00
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions .github/auth/vm_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@

def authenticate_vm(path):
credentials = Credentials.from_service_account_file(path)
return discovery.build('compute', 'v1', credentials=credentials)
return discovery.build('compute', 'v1', credentials=credentials), credentials
def start_runner(creds, user, id = "gpu-insatnce", zone='us-central1-a', instance='demos-tests'):
compute = authenticate_vm(creds)
compute, credentials = authenticate_vm(creds)
compute.instances().start(project=id, zone=zone, instance=instance).execute()
# request = compute.instances().get(project=id, zone=zone, instance=instance)
# response = request.execute()
#
# # Extract the external IP address of the instance
# external_ip = response['networkInterfaces'][0]['accessConfigs'][0]['natIP']

# Establish an SSH connection to the instance
credentials, _ = impersonated_credentials.load_credentials_from_file(
creds,
target_principal=id
)

# Get the SSH username (assuming it's stored in the credentials)
ssh_username = credentials.service_account_email
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(
hostname=f'{instance}.{zone}.compute.internal',
username=user, # Typically 'your-username' or 'gce-username'
username=ssh_username, # Typically 'your-username' or 'gce-username'
pkey=paramiko.RSAKey(file_obj=credentials.signer.key_file),
)

Expand Down

0 comments on commit a0a7a00

Please sign in to comment.