Recupero dei dettagli dell'istanza
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Recupera i dettagli dell'istanza dato l'ID istanza nel progetto corrente.
Per saperne di più
Per la documentazione dettagliata che include questo esempio di codice, vedi quanto segue:
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples for retrieving instance details using an instance ID within the current Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples demonstrate how to get instance details in various programming languages, including C++, C#, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach language section includes instructions on how to authenticate using Application Default Credentials and how to install the client library for Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets show how to access and print details like the instance ID, display name, labels, state, and type.\u003c/p\u003e\n"],["\u003cp\u003eA link to the Google Cloud sample browser is provided to discover more code examples for Google Cloud products.\u003c/p\u003e\n"]]],[],null,["Get instance details given the instance ID in the current project.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Get instance information](/bigtable/docs/get-instance-information)\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id) {\n std::string instance_name = cbt::InstanceName(project_id, instance_id);\n StatusOr\u003cgoogle::bigtable::admin::v2::Instance\u003e instance =\n instance_admin.GetInstance(instance_name);\n if (!instance) throw std::move(instance).status();\n std::cout \u003c\u003c \"GetInstance details : \" \u003c\u003c instance-\u003eDebugString() \u003c\u003c \"\\n\";\n }\n\nC#\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Initialize request argument(s).\n GetInstanceRequest request = new GetInstanceRequest\n {\n InstanceName = new InstanceName(projectId, instanceId)\n };\n try\n {\n // Make Request.\n Console.WriteLine(\"Waiting for operation to complete...\");\n Instance respond = bigtableInstanceAdminClient.GetInstance(request);\n }\n catch (Exception ex)\n {\n Console.WriteLine($\"Exception retreiving {instanceId} instance\");\n Console.WriteLine(ex.Message);\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n Instance instance = null;\n try {\n instance = adminClient.getInstance(instanceId);\n System.out.println(\"Instance ID: \" + instance.getId());\n System.out.println(\"Display Name: \" + instance.getDisplayName());\n System.out.print(\"Labels: \");\n Map\u003cString, String\u003e labels = instance.getLabels();\n for (String key : labels.keySet()) {\n System.out.printf(\"%s - %s\", key, labels.get(key));\n }\n System.out.println(\"\\nState: \" + instance.getState());\n System.out.println(\"Type: \" + instance.getType());\n } catch (NotFoundException e) {\n System.err.println(\"Failed to get non-existent instance: \" + e.getMessage());\n }\n\nNode.js\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const [instances2] = await bigtable.instance(instanceID).get();\n console.log(`Instance ID: ${instances2.id}`);\n console.log(`Instance Meta: ${JSON.stringify(instances2.metadata)}`);\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\ApiCore\\ApiException;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\GetInstanceRequest;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Instance\\State;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Instance\\Type;\n\n /**\n * Get a Bigtable instance\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n */\n function get_instance(\n string $projectId,\n string $instanceId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n $instanceName = $instanceAdminClient-\u003einstanceName($projectId, $instanceId);\n\n printf('Fetching the Instance %s' . PHP_EOL, $instanceId);\n try {\n $getInstanceRequest = (new GetInstanceRequest())\n -\u003esetName($instanceName);\n $instance = $instanceAdminClient-\u003egetInstance($getInstanceRequest);\n } catch (ApiException $e) {\n if ($e-\u003egetStatus() === 'NOT_FOUND') {\n printf('Instance %s does not exists.' . PHP_EOL, $instanceId);\n return;\n }\n throw $e;\n }\n\n printf('Printing Details:' . PHP_EOL);\n\n // Fetch some commonly used metadata\n printf('Name: ' . $instance-\u003egetName() . PHP_EOL);\n printf('Display Name: ' . $instance-\u003egetDisplayName() . PHP_EOL);\n printf('State: ' . State::name($instance-\u003egetState()) . PHP_EOL);\n printf('Type: ' . Type::name($instance-\u003egetType()) . PHP_EOL);\n printf('Labels: ' . PHP_EOL);\n\n $labels = $instance-\u003egetLabels();\n\n // Labels are an object of the MapField class which implement the IteratorAggregate, Countable\n // and ArrayAccess interfaces so you can do the following:\n printf(\"\\tNum of Labels: \" . $labels-\u003ecount() . PHP_EOL);\n printf(\"\\tLabel with a key(dev-label): \" . ($labels['dev-label'] ?? 'N/A') . PHP_EOL);\n\n // we can even loop over all the labels\n foreach ($labels as $key =\u003e $val) {\n printf(\"\\t$key: $val\" . PHP_EOL);\n }\n }\n\nPython\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n print(\n \"\\nName of instance: {}\\nLabels: {}\".format(\n instance.display_name, instance.labels\n )\n )\n\nRuby\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # instance_id = \"my-instance\"\n instance = bigtable.instance instance_id\n puts \"Get Instance id: #{instance.instance_id}\"\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]