use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryWithReboot.
@Test
public void deployFromLibraryWithReboot() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState();
try {
if (vm == null) {
return;
}
// test reboot resource operation
rebootVSphereVMAndWait(vm);
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class EnumerationClientTest method test.
@Test
public void test() throws Exception {
String url = System.getProperty(TestProperties.VC_URL);
if (url == null) {
return;
}
String username = System.getProperty(TestProperties.VC_USERNAME);
String password = System.getProperty(TestProperties.VC_PASSWORD);
String datacenter = System.getProperty(TestProperties.VC_DATECENTER_ID);
ManagedObjectReference datacenterMoRef = VimUtils.convertStringToMoRef(datacenter);
BasicConnection conn = new BasicConnection();
conn.setURI(URI.create(url));
conn.setUsername(username);
conn.setPassword(password);
conn.setIgnoreSslErrors(true);
conn.setRequestTimeout(30, TimeUnit.SECONDS);
conn.connect();
ComputeStateWithDescription parent = new ComputeStateWithDescription();
ComputeDescription desc = new ComputeDescription();
parent.description = desc;
EnumerationClient client = new EnumerationClient(conn, parent);
PropertyFilterSpec spec = client.createResourcesFilterSpec();
for (List<ObjectContent> page : client.retrieveObjects(spec)) {
for (ObjectContent cont : page) {
this.logger.info(VimUtils.convertMoRefToString(cont.getObj()));
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereCloneTaskWithStorage method verifyBootDiskCustomizationWithStoragePolicy.
@Test
public void verifyBootDiskCustomizationWithStoragePolicy() throws Throwable {
ComputeService.ComputeState vm = null;
ComputeService.ComputeState clonedVm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
DiskService.DiskState bootDisk = createDiskWithStoragePolicy("boot", DiskService.DiskType.HDD, 1, getDiskUri(), HDD_DISK_SIZE, buildCustomProperties());
vm = createVmState(vmDescription, true, bootDisk.documentSelfLink);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
// create state & desc of the clone
ComputeDescriptionService.ComputeDescription cloneDescription = createCloneDescription(vm.documentSelfLink);
clonedVm = createCloneVmState(cloneDescription, true, false);
provisionTask = createProvisionTask(clonedVm);
awaitTaskEnd(provisionTask);
clonedVm = getComputeState(clonedVm);
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
verifyDiskProperties(vm, get);
}
} finally {
if (!isMock()) {
cleanUpVm(vm, clonedVm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class StatsClientTest method test.
@Test
public void test() throws Exception {
String url = System.getProperty(TestProperties.VC_URL);
if (url == null) {
return;
}
String username = System.getProperty(TestProperties.VC_USERNAME);
String password = System.getProperty(TestProperties.VC_PASSWORD);
BasicConnection conn = new BasicConnection();
conn.setURI(URI.create(url));
conn.setUsername(username);
conn.setPassword(password);
conn.setIgnoreSslErrors(true);
conn.setRequestTimeout(30, TimeUnit.SECONDS);
conn.connect();
StatsClient client = new StatsClient(conn);
List<ServiceStat> metrics;
ManagedObjectReference vm = new ManagedObjectReference();
vm.setType(VimNames.TYPE_VM);
vm.setValue("vm-49");
metrics = client.retrieveMetricsForVm(vm);
this.logger.info("vm metrics " + metrics);
ManagedObjectReference host = new ManagedObjectReference();
host.setType(VimNames.TYPE_HOST);
host.setValue("host-504");
metrics = client.retrieveMetricsForHost(host);
this.logger.info("host metrics " + metrics);
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class VSphereRegionEnumerationAdapterService method handlePost.
@Override
public void handlePost(Operation post) {
if (!post.hasBody()) {
post.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointState request = post.getBody(EndpointState.class);
DeferredResult<AuthCredentialsServiceState> credentialsDr;
if (request.authCredentialsLink == null) {
credentialsDr = new DeferredResult<>();
credentialsDr.complete(new AuthCredentialsServiceState());
} else {
Operation getCredentials = Operation.createGet(createInventoryUri(this.getHost(), request.authCredentialsLink));
credentialsDr = sendWithDeferredResult(getCredentials, AuthCredentialsServiceState.class);
}
credentialsDr.whenComplete((AuthCredentialsServiceState creds, Throwable t) -> {
if (t != null) {
post.fail(t);
return;
}
VSphereIOThreadPoolAllocator.getPool(this).submit(() -> {
BasicConnection connection = new BasicConnection();
try {
EndpointAdapterUtils.Retriever retriever = EndpointAdapterUtils.Retriever.of(request.endpointProperties);
VSphereEndpointAdapterService.endpoint().accept(request, retriever);
VSphereEndpointAdapterService.credentials().accept(creds, retriever);
connection.setURI(URI.create("https://" + request.endpointProperties.get(HOST_NAME_KEY) + "/sdk"));
connection.setUsername(creds.privateKeyId);
connection.setPassword(EncryptionUtils.decrypt(creds.privateKey));
connection.setIgnoreSslErrors(true);
connection.connect();
DatacenterLister lister = new DatacenterLister(connection);
RegionEnumerationResponse res = new RegionEnumerationResponse();
res.regions = lister.listAllDatacenters().stream().map(dc -> new RegionEnumerationResponse.RegionInfo(DatacenterLister.prettifyPath(dc.path), VimUtils.convertMoRefToString(dc.object))).collect(Collectors.toList());
post.setBody(res);
post.complete();
} catch (Exception e) {
post.fail(e);
} finally {
connection.closeQuietly();
}
});
});
}
Aggregations