use of com.vmware.photon.controller.model.adapters.vsphere.VSphereIOThreadPool.ConnectionCallback in project photon-model by vmware.
the class CreatePortgroupFlow method createPortgroupInVsphere.
private ConnectionCallback createPortgroupInVsphere(DeferredResult<Void> result) {
return (connection, error) -> {
if (error != null) {
result.fail(error);
return;
}
// extract moref of the parent DVS switch
ManagedObjectReference dvsRef = CustomProperties.of(this.networkState).getMoRef(CustomProperties.MOREF);
DVPortgroupConfigSpec pgSpec = createDefaultPortgroupSpec();
ManagedObjectReference task;
try {
task = connection.getVimPort().createDVPortgroupTask(dvsRef, pgSpec);
} catch (Exception e) {
result.fail(e);
return;
}
TaskInfo taskInfo;
try {
taskInfo = VimUtils.waitTaskEnd(connection, task);
} catch (Exception e) {
result.fail(e);
return;
}
if (taskInfo.getState() != TaskInfoState.SUCCESS) {
IllegalStateException e = new IllegalStateException(taskInfo.getError().getLocalizedMessage());
result.fail(e);
return;
}
ManagedObjectReference pg = (ManagedObjectReference) taskInfo.getResult();
AssertUtil.assertNotNull(pg, "MoRef of dvPortGroup");
String pgKey = null;
String dvsUuid = null;
try {
GetMoRef get = new GetMoRef(connection);
Map<String, Object> propValues = get.entityProps(pg, VimPath.pg_config_key, VimPath.pg_config_distributedVirtualSwitch);
pgKey = (String) propValues.get(VimPath.pg_config_key);
ManagedObjectReference parentDvSwitch = (ManagedObjectReference) propValues.get(VimPath.pg_config_distributedVirtualSwitch);
if (parentDvSwitch != null) {
dvsUuid = get.entityProp(parentDvSwitch, VimPath.dvs_uuid);
}
} catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg ignore) {
getService().logWarning("Cannot retrieve dvPortGroup properties of [%s]: %s", VimUtils.convertMoRefToString(pg), ignore.getLocalizedMessage());
}
// store the moref as custom property
CustomProperties.of(this.subnetState).put(CustomProperties.MOREF, pg).put(DvsProperties.PORT_GROUP_KEY, pgKey).put(DvsProperties.DVS_UUID, dvsUuid);
OperationContext.setFrom(getOperationContext());
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(getService().getHost(), this.subnetState.documentSelfLink)).setBody(this.subnetState).setCompletion((o, e) -> {
if (e != null) {
result.fail(e);
return;
}
result.complete(null);
getTaskManager().patchTask(TaskStage.FINISHED);
}).sendWith(getService());
};
}
Aggregations