Hi.
I have a relatively little expirience with js and Orchestrator.
I faced with External Network в vCloud Director metadata's read/write problem. I want to write metadata to ProvidervDC, External Network, Storage Profile and some other objects, that ProvidervDC includes.
Before I write a new key, I check if it already exists.
Suppose, I have an ProvidervDC with three External Networks: ExtNet1, ExtNet2 and ExtNet3. Neither ProvidervDC nor External Network has metadata.
I run my script that writes metadata.
Then I delete ExtNet2's metadata, run script again. It shows me, that ExtNet2 ALREADY HAVE the metadata (but I've delete it).
When I delete the metadata of all objects (ExtNet1, ExtNet2, ExtNet3 and ProvidervDC) and run script, it'll work correctly.
What is the hell?
Code is here:
- function setMetadataBoolean(obj,key,value){
- var metadata = obj.getMetadata();
- var vclMetadataStringValue = new VclMetadataBooleanValue() ;
- vclMetadataStringValue.value = value;
- var vclAbstractValueObject = new VclAbstractValueObject();
- vclAbstractValueObject.setValue(vclMetadataStringValue);
- var vclMetadataEntry = new VclMetadataEntry();
- vclMetadataEntry.key = key;
- vclMetadataEntry.typedValue = vclAbstractValueObject;
- System.log("Setting key " + key + " with value " + value);
- return metadata.updateTypedEntry(vclMetadataEntry);
- }
- function getMetadataBoolean(obj,key){
- ObjMetadata = obj.getMetadata();
- Entries = ObjMetadata.getTypedEntries()
- for each (Entrie in Entries.enumerate()){
- if (Entrie.key == key){
- value = Entrie.typedValue.getValue(new VclMetadataBooleanValue).value;
- break;
- }else{value = null;}
- }
- return value;
- }
- //get all ProvidervDC
- var AllPvDC = System.getModule("com.vmware.library.vCloud.operation.admin").getProviderVdcsVCloudHostAdmin(vCDHA);
- for each (PvDC in AllPvDC){
- if (getMetadataBoolean(PvDC,"service1") == null){setMetadataBoolean(PvDC,"service1",true);}
- //get all External Network in ProvidervDC
- var AllExtNet = System.getModule("com.vmware.library.vCloud.operation.admin").getExternalNetworksProviderVdc(PvDC);
- for each (ExtNet in AllExtNet){
- System.log(ExtNet.name);
- System.log(getMetadataBoolean(ExtNet,"service1"));
- if (getMetadataBoolean(ExtNet,"service1") == null){setMetadataBoolean(ExtNet,"service1",true);}
- }
- }