Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): rework the compute list vms sample (#1534)
- Loading branch information
1 parent
3b612fc
commit 47056e9
Showing
5 changed files
with
73 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2019, Google, LLC | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// [START complete] | ||
// [START initialize] | ||
const {google} = require('googleapis'); | ||
const compute = google.compute('v1'); | ||
// [END initialize] | ||
|
||
async function listVMs() { | ||
// [START auth] | ||
const authClient = await google.auth.getClient({ | ||
scopes: [ | ||
'https://www.googleapis.com/auth/cloud-platform', | ||
'https://www.googleapis.com/auth/compute', | ||
'https://www.googleapis.com/auth/compute.readonly', | ||
], | ||
}); | ||
// [END auth] | ||
|
||
// [START list] | ||
const projectId = await google.auth.getProjectId(); | ||
const result = await compute.instances.aggregatedList({ | ||
auth: authClient, | ||
project: projectId, | ||
}); | ||
const vms = result.data; | ||
console.log('VMs:', vms); | ||
// [END list] | ||
} | ||
// [END complete] | ||
|
||
// Run the examples | ||
listVMs().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2019, Google, LLC. | ||
// 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. | ||
|
||
import {assert} from 'chai'; | ||
import {shellSync} from 'execa'; | ||
|
||
describe('Compute samples', () => { | ||
it('should list all the VMs', async () => { | ||
const res = shellSync('node ../samples/compute/listVMs'); | ||
assert.match(res.stdout, /VMs:/); | ||
}); | ||
}); |