public static boolean isTraversable(ManagedObjectReference ref) { switch (ref.getType()) { case "Folder": case "Datacenter": case "ComputeResource": case "ClusterComputeResource": // Treat ComputeResource and ClusterComputeResource as one and the same. // It doesn't matter from the perspective of the lister. return true; default: return false; } }
private List<Element> acceptOnly(List<Element> found, String... types) { return found.stream() .filter(e -> { for (String t : types) { if (e.object.getType().equals(t)) { return true; } } return false; }) .collect(Collectors.toList()); }
@Override public String toString() { return "ManagedObjectReferenceWrapper [type=" + mor.getType() + ", value=" + mor.getValue() + "]"; }
public MoRef(ManagedObjectReference ref) { this.type = ref.getType(); this.value = ref.getValue(); }
public String computeUniqueId(ManagedObjectReference mor) { Preconditions .checkNotNull(mor, "ManagedObjectReference cannot be null"); Preconditions.checkArgument( !ManagedObjectTypes.VIRTUAL_MACHINE.equals(mor.getType()), "cannot call computeMacId() with mor.type=VirtualMachine"); return Hashing .sha1() .hashString(getVCenterId() + mor.getType() + mor.getVal(), Charsets.UTF_8) .toString(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(super.toString()); try { sb.append(";type="); sb.append(URLEncoder.encode(moRef.getType(), "UTF-8")); sb.append(";value="); sb.append(URLEncoder.encode(moRef.getValue(), "UTF-8")); } catch (UnsupportedEncodingException e) { // ignore, this cannot happen } return sb.toString(); } }
/** * 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; }
ObjectNode toObjectNode(HostSystem host) { ManagedObjectReference mor = host.getMOR(); HostHardwareInfo hh = host.getHardware(); ObjectNode n = mapper.createObjectNode().put("id", getUniqueId(host)) .put("name", host.getName()).put("vmw_morType", mor.getType()) .put("vmw_morVal", mor.getVal()).put("vmw_hardwareModel", hh.getSystemInfo().getModel()) .put("vmw_cpuCoreCount", hh.getCpuInfo().getNumCpuCores()) .put("vmw_memorySize", hh.getMemorySize()); return n; }
public String toString() { return mor.getType() + ":" + mor.get_value() + " @ " + getServerConnection().getUrl(); }
static void printPermissions(Permission[] ps) { for(int i=0; ps!=null && i< ps.length; i++) { System.out.println("\nEntity:" + ps[i].getEntity().getType() + ":" + ps[i].getEntity().get_value()); System.out.println("IsGroup:" + ps[i].isGroup()); System.out.println("Principal:" + ps[i].getPrincipal()); System.out.println("Propogated:" + ps[i].isPropagate()); System.out.println("RoleId:" + ps[i].getRoleId()); } } }
static void printPermissions(Permission[] ps) { for(int i=0; ps!=null && i< ps.length; i++) { System.out.println("\nEntity:" + ps[i].getEntity().getType() + ":" + ps[i].getEntity().get_value()); System.out.println("IsGroup:" + ps[i].isGroup()); System.out.println("Principal:" + ps[i].getPrincipal()); System.out.println("Propogated:" + ps[i].isPropagate()); System.out.println("RoleId:" + ps[i].getRoleId()); } } }
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps, String[] propsToMatch) { PropertyFilterSpec spec = new PropertyFilterSpec(); ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(objmor); oSpec.setSkip(Boolean.FALSE); spec.getObjectSet().add(oSpec); Set<String> uniqPropSet = new HashSet<>(Arrays.asList(filterProps)); uniqPropSet.addAll(Arrays.asList(propsToMatch)); PropertySpec pSpec = new PropertySpec(); pSpec.getPathSet().addAll(new ArrayList<>(uniqPropSet)); pSpec.setType(objmor.getType()); spec.getPropSet().add(pSpec); return spec; }
public List<Element> list() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { switch (this.start.getType()) { case "Folder": return listFolder(); case "Datacenter": return listDatacenter(); case "ComputeResource": case "ClusterComputeResource": // Treat ComputeResource and ClusterComputeResource as one and the same. // It doesn't matter from the perspective of the lister. return listComputeResource(); case "ResourcePool": return listResourcePool(); default: throw new FinderException("Unlistable type: " + this.start.getType()); } }
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps) { ObjectSpec oSpec = new ObjectSpec(); oSpec.setObj(objmor); oSpec.setSkip(false); PropertySpec pSpec = new PropertySpec(); pSpec.getPathSet().addAll(Arrays.asList(filterProps)); pSpec.setType(objmor.getType()); PropertyFilterSpec spec = new PropertyFilterSpec(); spec.getObjectSet().add(oSpec); spec.getPropSet().add(pSpec); return spec; }
private String getName(ObjectContent cont) throws FinderException { for (DynamicProperty dp : cont.getPropSet()) { if (dp.getName().equals("name")) { return (String) dp.getVal(); } } // probably bad spec throw new FinderException("Name property not found/fetched for " + cont.getObj().getType()); }
private void writeObject(ObjectOutputStream out) throws IOException { ObjectOutputStream.PutField fields = out.putFields(); fields.put("type", moRef.getType()); fields.put("value", moRef.getValue()); out.writeFields(); }
public void watch(ManagedObject[] mos, String[] propNames) { PropertyFilterSpec pfs = new PropertyFilterSpec(); ObjectSpec[] oss = new ObjectSpec[mos.length]; for(int i=0; i<oss.length; i++) { oss[i] = new ObjectSpec(); oss[i].setObj(mos[i].getMOR()); } pfs.setObjectSet(oss); PropertySpec ps = new PropertySpec(); ps.setType(mos[0].getMOR().getType()); ps.setPathSet(propNames); pfs.setPropSet(new PropertySpec[] { ps }); watch(pfs); }