/** * @param propertyName The property name of current managed object * @return it will return either an array of related data objects, or an data object itself. * ManagedObjectReference objects are data objects!!! * @throws RemoteException * @throws RuntimeFault * @throws InvalidProperty * @ */ protected Object getCurrentProperty(String propertyName) { ObjectContent objContent = retrieveObjectProperties(new String[] { propertyName }); Object propertyValue = null; if (objContent != null) { DynamicProperty[] dynaProps = objContent.getPropSet(); if ((dynaProps != null) && (dynaProps[0]!= null)) { propertyValue = PropertyCollectorUtil.convertProperty(dynaProps[0].getVal()); } } return propertyValue; }
protected ObjectContent retrieveObjectProperties(String[] properties) { ObjectSpec oSpec = PropertyCollectorUtil.creatObjectSpec( getMOR(), Boolean.FALSE, null); PropertySpec pSpec = PropertyCollectorUtil.createPropertySpec( getMOR().getType(), properties == null || properties.length == 0, //if true, all props of this obj are to be read regardless of propName properties); PropertyFilterSpec pfSpec = new PropertyFilterSpec(); pfSpec.setObjectSet(new ObjectSpec[] { oSpec }); pfSpec.setPropSet(new PropertySpec[] { pSpec }); PropertyCollector pc = getServerConnection().getServiceInstance().getPropertyCollector(); ObjectContent[] objs; try { objs = pc.retrieveProperties(new PropertyFilterSpec[] { pfSpec }); } catch(Exception e) { throw new RuntimeException(e); } if (objs == null || objs[0]==null) return null; else return objs[0]; }
/** * Get multiple properties by their paths * @param propPaths an array of strings for property path * @return a Hashtable holding with the property path as key, and the value. * @throws InvalidProperty * @throws RuntimeFault * @throws RemoteException */ public Hashtable getPropertiesByPaths(String[] propPaths) throws InvalidProperty, RuntimeFault, RemoteException { Hashtable[] pht = PropertyCollectorUtil.retrieveProperties( new ManagedObject[] { this }, getMOR().getType(), propPaths); if(pht.length!=0) return pht[0]; else return null; }
public SortedMap<String, VirtualNetworkInfo> readVirtualNetworks() throws Exception { s_logger.info("Start reading virtual networks from vcenter ..."); SortedMap<String, VirtualNetworkInfo> map = new ConcurrentSkipListMap<String, VirtualNetworkInfo>(); if (contrailDVS == null) { s_logger.error("dvSwitch: " + contrailDvSwitchName + " NOT configured"); return map; } // Extract distributed virtual port groups DistributedVirtualPortgroup[] dvPgs = contrailDVS.getPortgroup(); if (dvPgs == null || dvPgs.length == 0) { s_logger.error("dvSwitch: " + contrailDvSwitchName + " Distributed portgroups NOT configured"); return map; } @SuppressWarnings("rawtypes") Hashtable[] pTables = PropertyCollectorUtil.retrieveProperties(dvPgs, "DistributedVirtualPortgroup", new String[] {"name", "config.key", "config.defaultPortConfig", "config.vendorSpecificConfig", "summary.ipPoolId", "summary.ipPoolName", }); for (int i=0; i < dvPgs.length; i++) { // Extract dvPg configuration info and port setting DVPortSetting portSetting = (DVPortSetting) pTables[i].get("config.defaultPortConfig"); if (doIgnoreVirtualNetwork(portSetting)) { continue; } VirtualNetworkInfo vnInfo = new VirtualNetworkInfo( this, dvPgs[i], pTables[i], contrailDC, contrailDataCenterName, contrailDVS, contrailDvSwitchName); s_logger.info("Read from vcenter " + vnInfo + ", ipPoolId " + vnInfo.getIpPoolId()); VCenterNotify.watchVn(vnInfo); map.put(vnInfo.getUuid(), vnInfo); } s_logger.info("Done reading from vcenter, found " + map.size() + " Virtual Networks"); return map; }
@SuppressWarnings("rawtypes") public VirtualNetworkInfo(Event event, VCenterDB vcenterDB, VncDB vncDB) throws Exception { vmiInfoMap = new ConcurrentSkipListMap<String, VirtualMachineInterfaceInfo>(); if (event.getDatacenter() != null) { dcName = event.getDatacenter().getName(); dc = vcenterDB.getVmwareDatacenter(dcName); } if (event.getDvs() != null) { dvsName = event.getDvs().getName(); dvs = vcenterDB.getVmwareDvs(dvsName, dc, dcName); } else { dvsName = vcenterDB.contrailDvSwitchName; dvs = vcenterDB.getVmwareDvs(dvsName, dc, dcName); } if (event.getNet() != null) { name = event.getNet().getName(); net = vcenterDB.getVmwareNetwork(name, dvs, dvsName, dcName); } dpg = vcenterDB.getVmwareDpg(name, dvs, dvsName, dcName); ManagedObject mo[] = new ManagedObject[1]; mo[0] = dpg; Hashtable[] pTables = PropertyCollectorUtil.retrieveProperties(mo, "DistributedVirtualPortgroup", new String[] {"name", "config.key", "config.defaultPortConfig", "config.vendorSpecificConfig", "summary.ipPoolId", "summary.ipPoolName", }); if (pTables == null || pTables[0] == null) { throw new RemoteException("Could not read properties for network " + name); } populateInfo(vcenterDB, pTables[0]); if (vcenterDB.mode == Mode.VCENTER_AS_COMPUTE) { apiVn = vncDB.findVirtualNetwork(uuid); readIpAm(); } }
private ObjectContent[] retrieveObjectContents(String[][] typeinfo, boolean recurse ) throws InvalidProperty, RuntimeFault, RemoteException { if (typeinfo == null || typeinfo.length == 0) { return null; } PropertyCollector pc = rootEntity.getServerConnection().getServiceInstance().getPropertyCollector(); if (recurse && selectionSpecs==null) { AboutInfo ai = rootEntity.getServerConnection().getServiceInstance().getAboutInfo(); /* The apiVersion values in all the shipped products "2.0.0" VI 3.0 "2.5.0" VI 3.5 (and u1) "2.5u2" VI 3.5u2 (and u3, u4) "4.0" vSphere 4.0 (and u1) "4.1" vSphere 4.1 "5.0" vSphere 5.0 "6.0" vSphere 6.0 ******************************************************/ if(ai.apiVersion.startsWith("4") || ai.apiVersion.startsWith("5") || ai.apiVersion.startsWith("6")) { selectionSpecs = PropertyCollectorUtil.buildFullTraversalV4(); } else { selectionSpecs = PropertyCollectorUtil.buildFullTraversal(); } } PropertySpec[] propspecary = PropertyCollectorUtil.buildPropertySpecArray(typeinfo); ObjectSpec os = new ObjectSpec(); os.setObj(rootEntity.getMOR()); os.setSkip(Boolean.FALSE); os.setSelectSet(selectionSpecs); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.setObjectSet(new ObjectSpec[] { os }); spec.setPropSet(propspecary); return pc.retrieveProperties(new PropertyFilterSpec[] { spec } ); }