1. GUI 환경

추가 예정

2. CLI 환경

2.1. VM 원격 시동

2.1.1. 파이썬 패키지

pip install oauth2client

pip install --upgrade google-api-python-client

2.1.2. api code

# gcp_api.py
"""
BEFORE RUNNING:
---------------
1. If not already done, enable the Compute Engine API
   and check the quota for your project at
   <https://console.developers.google.com/apis/api/compute>
2. This sample uses Application Default Credentials for authentication.
   If not already done, install the gcloud CLI from
   <https://cloud.google.com/sdk> and run
   `gcloud beta auth application-default login`.
   For more information, see
   <https://developers.google.com/identity/protocols/application-default-credentials>
3. Install the Python client library for Google APIs by running
   `pip install --upgrade google-api-python-client`
"""
from pprint import pprint

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/nas/workspace/kbae/2022_GEP_DOWNLOADER/data-platform.json"

credentials = GoogleCredentials.get_application_default()

service = discovery.build('compute', 'v1', credentials=credentials)

# Project ID for this request.
project = 'data-platform-339409'  # TODO: Update placeholder value.

# The name of the zone for this request.
zone = 'us-central1-a'  # TODO: Update placeholder value.

# Name of the instance resource to start.
instance = 'first-windows'  # TODO: Update placeholder value.

request = service.instances().start(project=project, zone=zone, instance=instance)
response = request.execute()

# TODO: Change code below to process the `response` dict:
pprint(response)

2.2. Ubuntu Cloud SDK

https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu?hl=ko

# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] <http://packages.cloud.google.com/apt> cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud public key
curl <https://packages.cloud.google.com/apt/doc/apt-key.gpg> | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

2.3. gcloud

2.3.1. Generate ssh key

> gcloud compute connect-to-serial-port {vm 이름} \\                                                                                                              
    --port=2 \\
    --zone={time zone}\\
    --project={project id}

WARNING: The private SSH key file for gcloud does not exist.
WARNING: The public SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/google_compute_engine
Your public key has been saved in /root/.ssh/google_compute_engine.pub
The key fingerprint is:
...                                                                                                                                                                                                
channel 0: open failed: connect failed: The serial-port-enable metadata attribute is not set on this VM. It should be set to 'yes' to enable serial port access.
Connection to ssh-serialport.googleapis.com closed.

<aside> 💡

/root/.ssh 에서 google_compute_engine, google_compute_engine.pub, google_compute_known_hosts 확인

</aside>

2.3.2. 직렬 콘솔 Open

> gcloud compute instances add-metadata {vm 이름} \\
    --metadata serial-port-enable=TRUE

No zone specified. Using zone [us-central1-a] for instance: [first-windows].
Updated [<https://www.googleapis.com/compute/v1/projects/data-platform-339409/zones/us-central1-a/instances/first-windows>].
/nas/Dataset/SR_DATA/aerial_images/raws >