|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2021 Google Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +require_once 'vendor/autoload.php'; |
| 19 | + |
| 20 | +use Google\Cloud\Compute\V1\InstancesClient; |
| 21 | +use Google\Cloud\Compute\V1\ZonesClient; |
| 22 | +use Google\Cloud\Compute\V1\MachineTypesClient; |
| 23 | +use Google\Cloud\Compute\V1\ImagesClient; |
| 24 | +use Google\Cloud\Compute\V1\FirewallsClient; |
| 25 | +use Google\Cloud\Compute\V1\NetworksClient; |
| 26 | +use Google\Cloud\Compute\V1\DisksClient; |
| 27 | +use Google\Cloud\Compute\V1\GlobalOperationsClient; |
| 28 | +use Google\Protobuf\Internal\Message; |
| 29 | + |
| 30 | +/** |
| 31 | + * Set these variables to your project and zone. |
| 32 | + */ |
| 33 | +$projectId = 'php-docs-samples-kokoro'; |
| 34 | +$zoneName = 'us-central1-f'; |
| 35 | + |
| 36 | +// Instantiate clients for calling the Compute API. |
| 37 | +$instancesClient = new InstancesClient(); |
| 38 | +$zonesClient = new ZonesClient(); |
| 39 | +$disksClient = new DisksClient(); |
| 40 | +$machineTypesClient = new MachineTypesClient(); |
| 41 | +$imagesClient = new ImagesClient(); |
| 42 | +$firewallsClient = new FirewallsClient(); |
| 43 | +$networksClient = new NetworksClient(); |
| 44 | +$globalOperationsClient = new GlobalOperationsClient(); |
| 45 | + |
| 46 | +/** |
| 47 | + * Helper function to pretty-print a Protobuf message. |
| 48 | + */ |
| 49 | +function print_message(Message $message) |
| 50 | +{ |
| 51 | + return json_encode( |
| 52 | + json_decode($message->serializeToJsonString(), true), |
| 53 | + JSON_PRETTY_PRINT |
| 54 | + ); |
| 55 | +} |
| 56 | +?> |
| 57 | +<!doctype html> |
| 58 | +<html> |
| 59 | + <head><meta charset="utf-8"></head> |
| 60 | + <body> |
| 61 | + <header><h1>Google Cloud Compute Sample App</h1></header> |
| 62 | + <div class="main-content"> |
| 63 | + <h2 class="collapsible">List Instances</h2> |
| 64 | + <div id="listInstances" class="collapsible-content"> |
| 65 | + <?php foreach ($instancesClient->list_($projectId, $zoneName) as $instance): ?> |
| 66 | + <pre><?= print_message($instance) ?></pre> |
| 67 | + <?php endforeach ?> |
| 68 | + </div> |
| 69 | + |
| 70 | + <h2 class="collapsible">List Zones</h2> |
| 71 | + <div id="listZones" class="collapsible-content"> |
| 72 | + <?php foreach ($zonesClient->list_($projectId) as $zone): ?> |
| 73 | + <pre><?= print_message($zone) ?></pre> |
| 74 | + <?php endforeach ?> |
| 75 | + </div> |
| 76 | + |
| 77 | + <h2 class="collapsible">List Disks</h2> |
| 78 | + <div id="listDisks" class="collapsible-content"> |
| 79 | + <?php foreach ($disksClient->list_($projectId, $zoneName) as $disk): ?> |
| 80 | + <pre><?= print_message($disk) ?></pre> |
| 81 | + <?php endforeach ?> |
| 82 | + </div> |
| 83 | + |
| 84 | + <h2 class="collapsible">List Machine Types</h2> |
| 85 | + <div id="listMachineTypes" class="collapsible-content"> |
| 86 | + <?php foreach ($machineTypesClient->list_($projectId, $zoneName) as $machineType): ?> |
| 87 | + <pre><?= print_message($machineType) ?></pre> |
| 88 | + <?php endforeach ?> |
| 89 | + </div> |
| 90 | + |
| 91 | + <h2 class="collapsible">List Images</h2> |
| 92 | + <div id="listImages" class="collapsible-content"> |
| 93 | + <?php foreach ($imagesClient->list_($projectId) as $image): ?> |
| 94 | + <pre><?= print_message($image) ?></pre> |
| 95 | + <?php endforeach ?> |
| 96 | + </div> |
| 97 | + |
| 98 | + <h2 class="collapsible">List Firewalls</h2> |
| 99 | + <div id="listFirewalls" class="collapsible-content"> |
| 100 | + <?php foreach ($firewalls = $firewallsClient->list_($projectId) as $firewall): ?> |
| 101 | + <pre><?= print_message($firewall) ?></pre> |
| 102 | + <?php endforeach ?> |
| 103 | + </div> |
| 104 | + |
| 105 | + <h2 class="collapsible">List Networks</h2> |
| 106 | + <div id="listNetworks" class="collapsible-content"> |
| 107 | + <?php foreach ($networksClient->list_($projectId) as $network): ?> |
| 108 | + <pre><?= print_message($network) ?></pre> |
| 109 | + <?php endforeach ?> |
| 110 | + </div> |
| 111 | + |
| 112 | + <h2 class="collapsible">List Operations</h2> |
| 113 | + <div id="listGlobalOperations" class="collapsible-content"> |
| 114 | + <?php foreach ($globalOperationsClient->list_($projectId) as $operation): ?> |
| 115 | + <pre><?= print_message($operation) ?></pre> |
| 116 | + <?php endforeach ?> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + </body> |
| 120 | +</html> |
| 121 | + |
| 122 | +<style> |
| 123 | +.collapsible { |
| 124 | + background-color: #eee; |
| 125 | + color: #444; |
| 126 | + cursor: pointer; |
| 127 | + padding: 18px; |
| 128 | + width: 100%; |
| 129 | + border: none; |
| 130 | + text-align: left; |
| 131 | + outline: none; |
| 132 | + font-size: 15px; |
| 133 | +} |
| 134 | + |
| 135 | +.active, .collapsible:hover { |
| 136 | + background-color: #ccc; |
| 137 | +} |
| 138 | + |
| 139 | +.collapsible-content { |
| 140 | + padding: 0 18px; |
| 141 | + display: none; |
| 142 | + overflow: hidden; |
| 143 | + background-color: #f1f1f1; |
| 144 | +} |
| 145 | +</style> |
| 146 | + |
| 147 | +<script> |
| 148 | + var coll = document.getElementsByClassName("collapsible"); |
| 149 | + var i; |
| 150 | + |
| 151 | + for (i = 0; i < coll.length; i++) { |
| 152 | + coll[i].addEventListener("click", function() { |
| 153 | + this.classList.toggle("active"); |
| 154 | + var content = this.nextElementSibling; |
| 155 | + if (content.style.display === "block") { |
| 156 | + content.style.display = "none"; |
| 157 | + } else { |
| 158 | + content.style.display = "block"; |
| 159 | + } |
| 160 | + }); |
| 161 | + } |
| 162 | +</script> |
0 commit comments