use of com.vmware.vim25.PropertySpec in project photon-model by vmware.
the class Lister method listDatacenter.
private List<Element> listDatacenter() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
ObjectSpec ospec = new ObjectSpec();
ospec.setObj(this.start);
ospec.setSkip(true);
// Include every datastore folder in the select set
String[] fields = { "vmFolder", "hostFolder", "datastoreFolder", "networkFolder", "datastore" };
for (String f : fields) {
TraversalSpec tspec = new TraversalSpec();
tspec.setPath(f);
tspec.setSkip(false);
tspec.setType(VimNames.TYPE_DATACENTER);
ospec.getSelectSet().add(tspec);
}
PropertySpec pspec = new PropertySpec();
pspec.setType(VimNames.TYPE_FOLDER);
pspec.getPathSet().add(VimNames.PROPERTY_NAME);
PropertySpec dcspec = new PropertySpec();
dcspec.setType(VimNames.TYPE_DATACENTER);
dcspec.getPathSet().add(VimNames.PROPERTY_NAME);
PropertySpec dsspec = new PropertySpec();
dsspec.setType(VimNames.TYPE_DATASTORE);
dsspec.getPathSet().add(VimNames.PROPERTY_NAME);
PropertyFilterSpec spec = new PropertyFilterSpec();
spec.getObjectSet().add(ospec);
spec.getPropSet().add(pspec);
spec.getPropSet().add(dcspec);
spec.getPropSet().add(dsspec);
return callPropertyCollectorAndConvert(spec);
}
use of com.vmware.vim25.PropertySpec in project photon-model by vmware.
the class EnumerationClient method createVmFilterSpec.
public PropertyFilterSpec createVmFilterSpec(ManagedObjectReference dc) {
ObjectSpec ospec = new ObjectSpec();
ospec.setObj(dc);
ospec.setSkip(false);
ospec.getSelectSet().addAll(buildFullTraversal());
PropertySpec vmSpec = new PropertySpec();
vmSpec.setType(VimNames.TYPE_VM);
vmSpec.getPathSet().addAll(Arrays.asList(VimPath.vm_config_name, VimPath.vm_config_instanceUuid, VimPath.vm_config_changeVersion, VimPath.vm_config_hardware_device, VimPath.vm_config_hardware_memoryMB, VimPath.vm_summary_config_numCpu, VimPath.vm_config_template, VimPath.vm_runtime_host, VimPath.vm_guest_net, VimPath.vm_guest_hostName, VimPath.vm_runtime_powerState, VimPath.vm_runtime_maxCpuUsage, VimPath.vm_runtime_maxMemoryUsage, VimPath.vm_summary_guest_ipAddress, VimPath.vm_summary_guest_hostName, VimPath.vm_snapshot_rootSnapshotList, VimPath.res_resourcePool, VimPath.vm_summary_config_guestFullName));
PropertyFilterSpec filterSpec = new PropertyFilterSpec();
filterSpec.getObjectSet().add(ospec);
filterSpec.getPropSet().add(vmSpec);
return filterSpec;
}
use of com.vmware.vim25.PropertySpec in project photon-model by vmware.
the class InstanceClient method populateCloudConfig.
/**
* Puts the cloud-config user data in the OVF environment
*
* @param spec
* @param currentProps
*/
private boolean populateCloudConfig(VirtualMachineConfigSpec spec, ArrayOfVAppPropertyInfo currentProps) {
if (this.bootDisk == null) {
return false;
}
boolean customizationsApplied = false;
int nextKey = 1;
if (currentProps != null) {
nextKey = currentProps.getVAppPropertyInfo().stream().mapToInt(VAppPropertyInfo::getKey).max().orElse(1);
nextKey++;
}
VmConfigSpec configSpec = new VmConfigSpec();
configSpec.getOvfEnvironmentTransport().add(OvfDeployer.TRANSPORT_ISO);
String cloudConfig = getFileItemByPath(this.bootDisk, CLOUD_CONFIG_PROPERTY_USER_DATA);
if (cloudConfig != null) {
VAppPropertySpec propertySpec = new VAppPropertySpec();
VAppPropertyInfo userDataInfo = null;
if (currentProps != null) {
userDataInfo = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(CLOUD_CONFIG_PROPERTY_USER_DATA)).findFirst().orElse(null);
if (userDataInfo == null) {
// try coreOS key
userDataInfo = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(COREOS_CLOUD_CONFIG_PROPERTY_USER_DATA)).findFirst().orElse(null);
if (userDataInfo != null) {
VAppPropertyInfo coreosEncoding = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(COREOS_CLOUD_CONFIG_PROPERTY_USER_DATA_ENCODING)).findFirst().orElse(null);
if (coreosEncoding != null) {
VAppPropertySpec pSpec = new VAppPropertySpec();
coreosEncoding.setValue(CLOUD_CONFIG_BASE64_ENCODING);
pSpec.setOperation(ArrayUpdateOperation.EDIT);
pSpec.setInfo(coreosEncoding);
configSpec.getProperty().add(pSpec);
}
}
}
}
if (userDataInfo != null) {
propertySpec.setOperation(ArrayUpdateOperation.EDIT);
} else {
userDataInfo = new VAppPropertyInfo();
userDataInfo.setId(CLOUD_CONFIG_PROPERTY_USER_DATA);
userDataInfo.setType("string");
userDataInfo.setKey(nextKey++);
propertySpec.setOperation(ArrayUpdateOperation.ADD);
}
String encodedUserData = Base64.getEncoder().encodeToString(cloudConfig.getBytes());
userDataInfo.setValue(encodedUserData);
propertySpec.setInfo(userDataInfo);
configSpec.getProperty().add(propertySpec);
customizationsApplied = true;
}
String publicKeys = getFileItemByPath(this.bootDisk, CLOUD_CONFIG_PROPERTY_PUBLIC_KEYS);
if (publicKeys != null) {
VAppPropertySpec propertySpec = new VAppPropertySpec();
VAppPropertyInfo sshKeyInfo = null;
if (currentProps != null) {
sshKeyInfo = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(CLOUD_CONFIG_PROPERTY_PUBLIC_KEYS)).findFirst().orElse(null);
}
if (sshKeyInfo != null) {
propertySpec.setOperation(ArrayUpdateOperation.EDIT);
} else {
sshKeyInfo = new VAppPropertyInfo();
sshKeyInfo.setType("string");
sshKeyInfo.setId(CLOUD_CONFIG_PROPERTY_PUBLIC_KEYS);
sshKeyInfo.setKey(nextKey++);
propertySpec.setOperation(ArrayUpdateOperation.ADD);
}
sshKeyInfo.setValue(publicKeys);
propertySpec.setInfo(sshKeyInfo);
configSpec.getProperty().add(propertySpec);
customizationsApplied = true;
}
String hostname = getFileItemByPath(this.bootDisk, CLOUD_CONFIG_PROPERTY_HOSTNAME);
if (hostname != null) {
VAppPropertySpec propertySpec = new VAppPropertySpec();
VAppPropertyInfo hostInfo = null;
if (currentProps != null) {
hostInfo = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(CLOUD_CONFIG_PROPERTY_HOSTNAME)).findFirst().orElse(null);
if (hostInfo == null) {
// try coreOS key
hostInfo = currentProps.getVAppPropertyInfo().stream().filter(p -> p.getId().equals(COREOS_CLOUD_CONFIG_PROPERTY_HOSTNAME)).findFirst().orElse(null);
}
}
if (hostInfo != null) {
propertySpec.setOperation(ArrayUpdateOperation.EDIT);
} else {
hostInfo = new VAppPropertyInfo();
hostInfo.setId(CLOUD_CONFIG_PROPERTY_USER_DATA);
hostInfo.setType("string");
hostInfo.setKey(nextKey++);
propertySpec.setOperation(ArrayUpdateOperation.ADD);
}
hostInfo.setValue(hostname);
propertySpec.setInfo(hostInfo);
configSpec.getProperty().add(propertySpec);
customizationsApplied = true;
}
if (customizationsApplied) {
spec.setVAppConfig(configSpec);
}
return customizationsApplied;
}
use of com.vmware.vim25.PropertySpec in project cloudstack by apache.
the class VirtualMachineMO method getAllDatastores.
public List<DatastoreMO> getAllDatastores() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.getPathSet().add("name");
TraversalSpec vmDatastoreTraversal = new TraversalSpec();
vmDatastoreTraversal.setType("VirtualMachine");
vmDatastoreTraversal.setPath("datastore");
vmDatastoreTraversal.setName("vmDatastoreTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(vmDatastoreTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
List<DatastoreMO> datastores = new ArrayList<DatastoreMO>();
if (CollectionUtils.isNotEmpty(ocs)) {
for (ObjectContent oc : ocs) {
datastores.add(new DatastoreMO(_context, oc.getObj()));
}
}
return datastores;
}
use of com.vmware.vim25.PropertySpec in project cloudstack by apache.
the class VirtualMachineMO method getNetworks.
public String[] getNetworks() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.getPathSet().add("name");
TraversalSpec vm2NetworkTraversal = new TraversalSpec();
vm2NetworkTraversal.setType("VirtualMachine");
vm2NetworkTraversal.setPath("network");
vm2NetworkTraversal.setName("vm2NetworkTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(vm2NetworkTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
List<String> networks = new ArrayList<String>();
if (ocs != null && ocs.size() > 0) {
for (ObjectContent oc : ocs) {
networks.add(oc.getPropSet().get(0).getVal().toString());
}
}
return networks.toArray(new String[0]);
}
Aggregations