Issue with inserting multiple metadata key/values while create a new instance

44 views
Skip to first unread message

Vikram Saggu

unread,
Jun 15, 2016, 5:52:42 AM6/15/16
to gce-discussion
Hi all,

Using PHP with Google Service Account library to create instance's.

Issue is with setting up multiple metadata key/values.

While giving up multiple metadata key/values on creating a new instance, it is only taking single key/value instead.

Here is my code.

/// META-DATA
    $googleMetadataItemsObj = new Google_Service_Compute_MetadataItems();
    $googleMetadataItemsObj->setKey('fname','lname');
    $googleMetadataItemsObj->setValue('abc','def');   
   
    $googleMetadataObj = new Google_Service_Compute_Metadata();
    $googleMetadataObj->setKind('compute#metadata');
    $googleMetadataObj->setItems(array($googleMetadataItemsObj));
/// META-DATA

    $new_instance = new Google_Service_Compute_Instance();
    $new_instance->setName($instancename);
    $new_instance->setKind('compute#operation');
    $new_instance->setMachineType($machineType);
    $new_instance->setDisks(array($googleAttachDiskObj));
    $new_instance->setNetworkInterfaces(array($googleNetworkInterfaceObj));
    $new_instance->setMetadata($googleMetadataObj);
    $new_instance->setServiceAccounts($googleServiceAccountObj);
    $insertInstance = $computeService->instances->insert(DEFAULT_PROJECT,$zone, $new_instance);


George (Google Cloud Support)

unread,
Jun 15, 2016, 5:13:16 PM6/15/16
to gce-discussion
Hello Vikram,

Is it possible to do a get on the key/value and check for the output?

I was able to find this discussion that might shed some light.

I hope this helps.

Sincerely,
George

Vikram Saggu

unread,
Jun 16, 2016, 1:51:42 AM6/16/16
to gce-discussion
Hello George,

The discussion you referred is also setting up single key/value for the metadata, which i am able to do it. My problem is while setting up multiple key/values in metadata. Issue is with preparing array i think which is not happening. I tried my best alternate ways but still fails to insert multiple metadata key/values.

I've replied to your referred discussion, mentioning my problem. If you could see it again and try to sort if possible.

Thank you.

George (Google Cloud Support)

unread,
Jun 16, 2016, 5:01:32 PM6/16/16
to gce-discussion
Hello Vikram,

Thank you for providing the REST output on the other discussion. As only one key and one value should pass at a time, see this github for more information.

I hope this helps.

Sincerely,
George

Vikram Saggu

unread,
Jun 16, 2016, 11:52:08 PM6/16/16
to gce-discussion
Hello George,

I figured it out by doing the following way for adding multiple key/values in Metadata.


/// META-DATA
    $googleMetadataItemsObj = new Google_Service_Compute_MetadataItems();
    $googleMetadataItemsObj=array(array("key"=>'firstkey',"value"=>'firstvalue'),array("key"=>'secondkey',"value"=>'secondvalue'));

   
    $googleMetadataObj = new Google_Service_Compute_Metadata();
    $googleMetadataObj->setKind('compute#metadata');
    $googleMetadataObj->setItems($googleMetadataItemsObj);
/// META-DATA
Reply all
Reply to author
Forward
0 new messages