From 3b396bde07d4b4161d834530d2158e7b84ed8bba Mon Sep 17 00:00:00 2001 From: PaulFenton Date: Sat, 13 Jan 2024 13:17:48 -0500 Subject: [PATCH 1/4] implemented fix for instance name argument on create_image_from_disk() --- README.md | 57 +++++++++---------- .../ingredients/images/create.py | 3 +- .../client_library/snippets/images/create.py | 3 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e75d8df0160..51f7ba07b52 100644 --- a/README.md +++ b/README.md @@ -12,61 +12,60 @@ Check out some of the samples found on this repository on the [Google Cloud Samp 1. Install [`pip` and `virtualenv`][cloud_python_setup] if you do not already have them. -1. Clone this repository: +2. Clone this repository: - ``` - git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git - ``` + ``` + git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + ``` -1. Obtain authentication credentials. +3. Obtain authentication credentials. - Create local credentials by running the following command and following the - oauth2 flow (read more about the command [here][auth_command]): + Create local credentials by running the following command and following the + oauth2 flow (read more about the command [here][auth_command]): - ``` - gcloud auth application-default login - ``` + ``` + gcloud auth application-default login + ``` - Read more about [Google Cloud Platform Authentication][gcp_auth]. + Read more about [Google Cloud Platform Authentication][gcp_auth]. ## How to run a sample 1. Change directory to one of the sample folders, e.g. `logging/cloud-client`: - ``` - cd logging/cloud-client/ - ``` + ``` + cd logging/cloud-client/ + ``` -1. Create a virtualenv. Samples are compatible with Python 3.6+. +2. Create a virtualenv. Samples are compatible with Python 3.6+. - ``` - python3 -m venv env - source env/bin/activate - ``` + ``` + python3 -m venv env + source env/bin/activate + ``` -1. Install the dependencies needed to run the samples. +3. Install the dependencies needed to run the samples. - ``` - pip install -r requirements.txt - ``` + ``` + pip install -r requirements.txt + ``` -1. Run the sample: +4. Run the sample: - ``` - python snippets.py - ``` + ``` + python snippets.py + ``` ## Contributing Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md). -[slack_badge]: https://img.shields.io/badge/slack-Google%20Cloud%20Platform-E01563.svg +[slack_badge]: https://img.shields.io/badge/slack-Google%20Cloud%20Platform-E01563.svg [slack_link]: https://googlecloud-community.slack.com/ [cloud]: https://cloud.google.com/ [cloud_python_setup]: https://cloud.google.com/python/setup [auth_command]: https://cloud.google.com/sdk/gcloud/reference/beta/auth/application-default/login [gcp_auth]: https://cloud.google.com/docs/authentication#projects_and_resources - [py-2.7-shield]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-2.7.svg [py-2.7-link]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-2.7.html [py-3.8-shield]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-3.8.svg diff --git a/compute/client_library/ingredients/images/create.py b/compute/client_library/ingredients/images/create.py index 70274a01f33..8484a3639c1 100644 --- a/compute/client_library/ingredients/images/create.py +++ b/compute/client_library/ingredients/images/create.py @@ -64,8 +64,9 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: + instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=disk_user + project=project_id, zone=zone, instance=instance_name ) if instance.status in STOPPED_MACHINE_STATUS: continue diff --git a/compute/client_library/snippets/images/create.py b/compute/client_library/snippets/images/create.py index ec718d1b59c..25c399ecad3 100644 --- a/compute/client_library/snippets/images/create.py +++ b/compute/client_library/snippets/images/create.py @@ -118,8 +118,9 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: + instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=disk_user + project=project_id, zone=zone, instance=instance_name ) if instance.status in STOPPED_MACHINE_STATUS: continue From 35d3441a845b1d4497052d3921183a6191a375fc Mon Sep 17 00:00:00 2001 From: PaulFenton Date: Mon, 15 Jan 2024 17:42:33 -0500 Subject: [PATCH 2/4] Revert "implemented fix for instance name argument on create_image_from_disk()" This reverts commit 3b396bde07d4b4161d834530d2158e7b84ed8bba. --- README.md | 57 ++++++++++--------- .../ingredients/images/create.py | 3 +- .../client_library/snippets/images/create.py | 3 +- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 51f7ba07b52..e75d8df0160 100644 --- a/README.md +++ b/README.md @@ -12,60 +12,61 @@ Check out some of the samples found on this repository on the [Google Cloud Samp 1. Install [`pip` and `virtualenv`][cloud_python_setup] if you do not already have them. -2. Clone this repository: +1. Clone this repository: - ``` - git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git - ``` + ``` + git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + ``` -3. Obtain authentication credentials. +1. Obtain authentication credentials. - Create local credentials by running the following command and following the - oauth2 flow (read more about the command [here][auth_command]): + Create local credentials by running the following command and following the + oauth2 flow (read more about the command [here][auth_command]): - ``` - gcloud auth application-default login - ``` + ``` + gcloud auth application-default login + ``` - Read more about [Google Cloud Platform Authentication][gcp_auth]. + Read more about [Google Cloud Platform Authentication][gcp_auth]. ## How to run a sample 1. Change directory to one of the sample folders, e.g. `logging/cloud-client`: - ``` - cd logging/cloud-client/ - ``` + ``` + cd logging/cloud-client/ + ``` -2. Create a virtualenv. Samples are compatible with Python 3.6+. +1. Create a virtualenv. Samples are compatible with Python 3.6+. - ``` - python3 -m venv env - source env/bin/activate - ``` + ``` + python3 -m venv env + source env/bin/activate + ``` -3. Install the dependencies needed to run the samples. +1. Install the dependencies needed to run the samples. - ``` - pip install -r requirements.txt - ``` + ``` + pip install -r requirements.txt + ``` -4. Run the sample: +1. Run the sample: - ``` - python snippets.py - ``` + ``` + python snippets.py + ``` ## Contributing Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md). -[slack_badge]: https://img.shields.io/badge/slack-Google%20Cloud%20Platform-E01563.svg +[slack_badge]: https://img.shields.io/badge/slack-Google%20Cloud%20Platform-E01563.svg [slack_link]: https://googlecloud-community.slack.com/ [cloud]: https://cloud.google.com/ [cloud_python_setup]: https://cloud.google.com/python/setup [auth_command]: https://cloud.google.com/sdk/gcloud/reference/beta/auth/application-default/login [gcp_auth]: https://cloud.google.com/docs/authentication#projects_and_resources + [py-2.7-shield]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-2.7.svg [py-2.7-link]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-2.7.html [py-3.8-shield]: https://storage.googleapis.com/cloud-devrel-public/python-docs-samples/badges/py-3.8.svg diff --git a/compute/client_library/ingredients/images/create.py b/compute/client_library/ingredients/images/create.py index 8484a3639c1..70274a01f33 100644 --- a/compute/client_library/ingredients/images/create.py +++ b/compute/client_library/ingredients/images/create.py @@ -64,9 +64,8 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: - instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=instance_name + project=project_id, zone=zone, instance=disk_user ) if instance.status in STOPPED_MACHINE_STATUS: continue diff --git a/compute/client_library/snippets/images/create.py b/compute/client_library/snippets/images/create.py index 25c399ecad3..ec718d1b59c 100644 --- a/compute/client_library/snippets/images/create.py +++ b/compute/client_library/snippets/images/create.py @@ -118,9 +118,8 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: - instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=instance_name + project=project_id, zone=zone, instance=disk_user ) if instance.status in STOPPED_MACHINE_STATUS: continue From eeffd298a7095852059978ab086e9840e8fb1d91 Mon Sep 17 00:00:00 2001 From: PaulFenton Date: Mon, 15 Jan 2024 17:45:13 -0500 Subject: [PATCH 3/4] reimplemented create _image_from_disk() fix --- compute/client_library/ingredients/images/create.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compute/client_library/ingredients/images/create.py b/compute/client_library/ingredients/images/create.py index 70274a01f33..8484a3639c1 100644 --- a/compute/client_library/ingredients/images/create.py +++ b/compute/client_library/ingredients/images/create.py @@ -64,8 +64,9 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: + instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=disk_user + project=project_id, zone=zone, instance=instance_name ) if instance.status in STOPPED_MACHINE_STATUS: continue From 8d08abd57dd9c5f4cd84050d0b6f117fb0186cc0 Mon Sep 17 00:00:00 2001 From: PaulFenton Date: Mon, 15 Jan 2024 17:47:08 -0500 Subject: [PATCH 4/4] regenerated snippet --- compute/client_library/snippets/images/create.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compute/client_library/snippets/images/create.py b/compute/client_library/snippets/images/create.py index ec718d1b59c..25c399ecad3 100644 --- a/compute/client_library/snippets/images/create.py +++ b/compute/client_library/snippets/images/create.py @@ -118,8 +118,9 @@ def create_image_from_disk( disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name) for disk_user in disk.users: + instance_name = disk_user.split("/")[-1] instance = instance_client.get( - project=project_id, zone=zone, instance=disk_user + project=project_id, zone=zone, instance=instance_name ) if instance.status in STOPPED_MACHINE_STATUS: continue