Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Add samples for game server deployments #25

Merged
merged 7 commits into from Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/AUTHORING_GUIDE.md
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md
1 change: 1 addition & 0 deletions samples/CONTRIBUTING.md
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md
244 changes: 244 additions & 0 deletions samples/snippets/README.rst
@@ -0,0 +1,244 @@
.. This file is automatically generated. Do not edit this file directly.

Google Cloud Game Servers Python Samples
===============================================================================

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/README.rst


This directory contains samples for Google Cloud Game Servers. The `Google Cloud Game Servers`_ is a managed service that enables game developers to deploy and manage their dedicated game servers across multiple Agones clusters around the world through a single interface.




.. _Google Cloud Game Servers: https://cloud.google.com/game-servers/docs/





Setup
-------------------------------------------------------------------------------


Authentication
++++++++++++++

This sample requires you to have authentication setup. Refer to the
`Authentication Getting Started Guide`_ for instructions on setting up
credentials for applications.

.. _Authentication Getting Started Guide:
https://cloud.google.com/docs/authentication/getting-started

Install Dependencies
++++++++++++++++++++

#. Clone python-docs-samples and change directory to the sample directory you want to use.

.. code-block:: bash

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.

.. _Python Development Environment Setup Guide:
https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate

#. Install the dependencies needed to run the samples.

.. code-block:: bash

$ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/

Samples
-------------------------------------------------------------------------------

Create deployment
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/create_deployment.py,/README.rst




To run this sample:

.. code-block:: bash

$ python create_deployment.py

usage: create_deployment.py [-h] --project-id PROJECT_ID --deployment-id
DEPLOYMENT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.
--deployment-id DEPLOYMENT_ID
Your game server deployment ID.



Delete deployment
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/delete_deployment.py,/README.rst




To run this sample:

.. code-block:: bash

$ python delete_deployment.py

usage: delete_deployment.py [-h] --project-id PROJECT_ID --deployment-id
DEPLOYMENT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.
--deployment-id DEPLOYMENT_ID
Your game server deployment ID.



Get deployment
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/get_deployment.py,/README.rst




To run this sample:

.. code-block:: bash

$ python get_deployment.py

usage: get_deployment.py [-h] --project-id PROJECT_ID --deployment-id
DEPLOYMENT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.
--deployment-id DEPLOYMENT_ID
Your game server deployment ID.



Get rollout
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/get_rollout.py,/README.rst




To run this sample:

.. code-block:: bash

$ python get_rollout.py

usage: get_rollout.py [-h] --project-id PROJECT_ID --deployment-id
DEPLOYMENT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.
--deployment-id DEPLOYMENT_ID
Your game server deployment ID.



List deployments
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/list_deployments.py,/README.rst




To run this sample:

.. code-block:: bash

$ python list_deployments.py

usage: list_deployments.py [-h] --project-id PROJECT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.



Update rollout by removing default config
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/update_rollout_remove_default.py,/README.rst




To run this sample:

.. code-block:: bash

$ python update_rollout_remove_default.py

usage: update_rollout_remove_default.py [-h] --project-id PROJECT_ID
--deployment-id DEPLOYMENT_ID

optional arguments:
-h, --help show this help message and exit
--project-id PROJECT_ID
Your cloud project ID.
--deployment-id DEPLOYMENT_ID
Your game server deployment ID.





The client library
-------------------------------------------------------------------------------

This sample uses the `Google Cloud Client Library for Python`_.
You can read the documentation for more details on API usage and use GitHub
to `browse the source`_ and `report issues`_.

.. _Google Cloud Client Library for Python:
https://googlecloudplatform.github.io/google-cloud-python/
.. _browse the source:
https://github.com/GoogleCloudPlatform/google-cloud-python
.. _report issues:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues


.. _Google Cloud SDK: https://cloud.google.com/sdk/
36 changes: 36 additions & 0 deletions samples/snippets/README.rst.in
@@ -0,0 +1,36 @@
# This file is used to generate README.rst

product:
name: Google Cloud Game Servers
short_name: Game Servers
url: https://cloud.google.com/game-servers/docs/
description: >
The `Google Cloud Game Servers`_ is a managed service that enables game
developers to deploy and manage their dedicated game servers across
multiple Agones clusters around the world through a single interface.

setup:
- auth
- install_deps

samples:
- name: Create deployment
file: create_deployment.py
show_help: True
- name: Delete deployment
file: delete_deployment.py
show_help: True
- name: Get deployment
file: get_deployment.py
show_help: True
- name: Get rollout
file: get_rollout.py
show_help: True
- name: List deployments
file: list_deployments.py
show_help: True
- name: Update rollout by removing default config
file: update_rollout_remove_default.py
show_help: True

cloud_client_library: true
59 changes: 59 additions & 0 deletions samples/snippets/create_deployment.py
@@ -0,0 +1,59 @@
#!/usr/bin/env python

# Copyright 2020 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google Cloud Game Servers sample for creating a Game Server Deployment.

Example usage:
python create_deployment.py --project-id <project-id> --deployment-id <deployment-id>
"""

import argparse

from google.cloud import gaming
from google.cloud.gaming_v1.types import game_server_deployments


# [START cloud_game_servers_create_deployment]
def create_deployment(project_id, deployment_id):
"""Creates a game server deployment."""

client = gaming.GameServerDeploymentsServiceClient()

# Location is hard coded as global, as Game Server Deployments can
# only be created in global. This is done for all operations on
# Game Server Deployments, as well as for its child resource types.
request = game_server_deployments.CreateGameServerDeploymentRequest(
parent=f"projects/{project_id}/locations/global",
deployment_id=deployment_id,
game_server_deployment=game_server_deployments.GameServerDeployment(
description="My Game Server Deployment"
),
)

operation = client.create_game_server_deployment(request)
print(f"Create deployment operation: {operation.operation.name}")
operation.result(timeout=120)
# [END cloud_game_servers_create_deployment]


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--project-id', help='Your cloud project ID.', required=True)
parser.add_argument('--deployment-id', help='Your game server deployment ID.', required=True)

args = parser.parse_args()

create_deployment(args.project_id, args.deployment_id)