Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Read and write metadata in vCloud Director

$
0
0

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:

 

 

  1. function setMetadataBoolean(obj,key,value){ 
  2.     var metadata = obj.getMetadata(); 
  3.     var vclMetadataStringValue = new VclMetadataBooleanValue() ; 
  4.     vclMetadataStringValue.value = value; 
  5.     var vclAbstractValueObject = new VclAbstractValueObject(); 
  6.     vclAbstractValueObject.setValue(vclMetadataStringValue); 
  7.     var vclMetadataEntry = new VclMetadataEntry(); 
  8.     vclMetadataEntry.key = key; 
  9.     vclMetadataEntry.typedValue = vclAbstractValueObject; 
  10.     System.log("Setting key " + key + " with value " + value); 
  11.     return metadata.updateTypedEntry(vclMetadataEntry); 
  12.  
  13. function getMetadataBoolean(obj,key){ 
  14.     ObjMetadata = obj.getMetadata(); 
  15.     Entries = ObjMetadata.getTypedEntries() 
  16.     for each (Entrie in Entries.enumerate()){ 
  17.         if (Entrie.key == key){ 
  18.             value = Entrie.typedValue.getValue(new VclMetadataBooleanValue).value; 
  19.             break
  20.         }else{value = null;} 
  21.     } 
  22.     return value; 
  23.  
  24.  
  25. //get all ProvidervDC 
  26. var AllPvDC = System.getModule("com.vmware.library.vCloud.operation.admin").getProviderVdcsVCloudHostAdmin(vCDHA); 
  27.  
  28. for each (PvDC in AllPvDC){ 
  29.      
  30.     if (getMetadataBoolean(PvDC,"service1") == null){setMetadataBoolean(PvDC,"service1",true);} 
  31.     //get all External Network in ProvidervDC 
  32.     var AllExtNet = System.getModule("com.vmware.library.vCloud.operation.admin").getExternalNetworksProviderVdc(PvDC); 
  33.      
  34.     for each (ExtNet in AllExtNet){ 
  35.          
  36.         System.log(ExtNet.name); 
  37.         System.log(getMetadataBoolean(ExtNet,"service1")); 
  38.         if (getMetadataBoolean(ExtNet,"service1") == null){setMetadataBoolean(ExtNet,"service1",true);} 
  39.          
  40.          
  41.     } 
  42.      

Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>