|
| 1 | +// Copyright 2020, Google LLC. |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +'use strict'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Create a Game Servers realm. |
| 18 | + * @param {string} projectId string project identifier. |
| 19 | + * @param {string} location Compute Engine region. |
| 20 | + * @param {string} realmId a unique identifier for the new realm |
| 21 | + */ |
| 22 | +function main( |
| 23 | + projectId = 'YOUR_PROJECT_ID', |
| 24 | + location = 'LOCATION_ID', |
| 25 | + realmId = 'REALM_ID' |
| 26 | +) { |
| 27 | + // [START cloud_game_servers_create_realm] |
| 28 | + /** |
| 29 | + * TODO(developer): Uncomment these variables before running the sample. |
| 30 | + */ |
| 31 | + // const projectId = 'Your Google Cloud Project ID'; |
| 32 | + // const location = 'A Compute Engine region, e.g. "us-central1"'; |
| 33 | + // const realmId = 'A unique identifier for the realm'; |
| 34 | + const {RealmsServiceClient} = require('@google-cloud/game-servers'); |
| 35 | + |
| 36 | + const client = new RealmsServiceClient(); |
| 37 | + |
| 38 | + async function createRealm() { |
| 39 | + const request = { |
| 40 | + parent: `projects/${projectId}/locations/${location}`, |
| 41 | + realmId: realmId, |
| 42 | + realm: { |
| 43 | + // Must use a supported time zone name. |
| 44 | + // See https://cloud.google.com/dataprep/docs/html/Supported-Time-Zone-Values_66194188 |
| 45 | + timeZone: 'US/Pacific', |
| 46 | + description: 'My Game Server realm', |
| 47 | + }, |
| 48 | + }; |
| 49 | + |
| 50 | + const [operation] = await client.createRealm(request); |
| 51 | + const results = await operation.promise(); |
| 52 | + const [realm] = results; |
| 53 | + |
| 54 | + console.log('Realm created:'); |
| 55 | + |
| 56 | + console.log(`\tRealm name: ${realm.name}`); |
| 57 | + console.log(`\tRealm description: ${realm.description}`); |
| 58 | + console.log(`\tRealm time zone: ${realm.timeZone}`); |
| 59 | + // [END cloud_game_servers_create_realm] |
| 60 | + } |
| 61 | + |
| 62 | + createRealm(); |
| 63 | +} |
| 64 | + |
| 65 | +main(...process.argv.slice(2)); |
0 commit comments