Search in sources :

Example 1 with NetworkInterfaceStateWithDetails

use of com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails in project photon-model by vmware.

the class VmOverlayTest method findPublicIpAddressWithMacAddresses.

@Test
public void findPublicIpAddressWithMacAddresses() {
    NetworkInterfaceStateWithDetails n1 = new NetworkInterfaceStateWithDetails();
    NetworkInterfaceStateWithDetails n2 = new NetworkInterfaceStateWithDetails();
    String mac1Address = "00:50:56:8b:54:bd";
    String mac2Address = "98:87:fd:9e:ed:6d";
    List<NetworkInterfaceStateWithDetails> nics = new ArrayList();
    nics.add(n1);
    n1.customProperties = new HashMap<>();
    n1.customProperties.put(NIC_MAC_ADDRESS, mac1Address);
    nics.add(n2);
    n2.customProperties = new HashMap<>();
    n2.customProperties.put(NIC_MAC_ADDRESS, mac2Address);
    String publicIpAddress = this.overlay.findPublicIpV4Address(nics);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress != null);
    // test with assignPublicIpAddress
    n1.description = new NetworkInterfaceDescription();
    n1.description.assignPublicIpAddress = true;
    publicIpAddress = this.overlay.findPublicIpV4Address(nics);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress != null);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress.equals("192.168.1.10"));
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) ArrayList(java.util.ArrayList) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) Test(org.junit.Test)

Example 2 with NetworkInterfaceStateWithDetails

use of com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails in project photon-model by vmware.

the class VSphereAdapterInstanceService method createUpdateIPOperationsForComputeAndNics.

private List<Operation> createUpdateIPOperationsForComputeAndNics(String computeLink, String ip, Map<String, List<String>> ipV4Addresses, ProvisionContext ctx) {
    List<Operation> updateIpAddressOperations = new ArrayList<>();
    if (ip != null) {
        ComputeState state = new ComputeState();
        state.address = ip;
        // update compute
        Operation updateIpAddress = Operation.createPatch(PhotonModelUriUtils.createInventoryUri(getHost(), computeLink)).setBody(state);
        updateIpAddressOperations.add(updateIpAddress);
    }
    if (ipV4Addresses != null) {
        int sizeIpV4Addresses = ipV4Addresses.size();
        for (NetworkInterfaceStateWithDetails nic : ctx.nics) {
            String deviceKey = null;
            deviceKey = VmOverlay.getDeviceKey(nic);
            if (deviceKey == null && nic.deviceIndex < sizeIpV4Addresses) {
                deviceKey = Integer.toString(nic.deviceIndex);
            }
            if (deviceKey != null) {
                List<String> ipsV4 = ipV4Addresses.containsKey(deviceKey) ? ipV4Addresses.get(deviceKey) : Collections.emptyList();
                if (ipsV4.size() > 0) {
                    NetworkInterfaceState patchNic = new NetworkInterfaceState();
                    // if nic has multiple ip addresses for ipv4 only pick 1st ip address
                    patchNic.address = ipsV4.get(0);
                    Operation updateAddressNetWorkInterface = Operation.createPatch(PhotonModelUriUtils.createInventoryUri(getHost(), nic.documentSelfLink)).setBody(patchNic);
                    updateIpAddressOperations.add(updateAddressNetWorkInterface);
                } else {
                    log(Level.WARNING, "Address is not going to be updated in network " + "interface state: [%], deviceKey: [%s] was not " + "found in " + "ipV4Addresses: " + "[%s]", nic.documentSelfLink, deviceKey, ipV4Addresses.keySet());
                }
            } else {
                log(Level.WARNING, "Address is not going to be updated in network interface " + "state: [%s] deviceKey is null", nic.documentSelfLink);
            }
        }
    }
    return updateIpAddressOperations;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) ArrayList(java.util.ArrayList) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) Operation(com.vmware.xenon.common.Operation)

Example 3 with NetworkInterfaceStateWithDetails

use of com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails in project photon-model by vmware.

the class VSphereAdapterInstanceService method handleCreateInstance.

private void handleCreateInstance(ProvisionContext ctx) {
    ctx.pool.submit(ctx.getAdapterManagementReference(), ctx.vSphereCredentials, (connection, ce) -> {
        if (ctx.fail(ce)) {
            return;
        }
        try {
            InstanceClient client = new InstanceClient(connection, ctx);
            ComputeState state;
            if (ctx.templateMoRef != null) {
                state = client.createInstanceFromTemplate(ctx.templateMoRef);
            } else if (ctx.image != null) {
                ManagedObjectReference moRef = CustomProperties.of(ctx.image).getMoRef(CustomProperties.MOREF);
                if (moRef != null) {
                    // the image is backed by a template VM
                    state = client.createInstanceFromTemplate(moRef);
                } else {
                    // library item
                    state = client.createInstanceFromLibraryItem(ctx.image);
                }
            } else if (ctx.snapshotMoRef != null) {
                state = client.createInstanceFromSnapshot();
            } else {
                state = client.createInstance();
            }
            if (state == null) {
                // assume they will patch the task if they have provisioned the vm
                return;
            }
            // populate state, MAC address being very important
            VmOverlay vmOverlay = client.enrichStateFromVm(state);
            Operation[] finishTask = new Operation[1];
            for (NetworkInterfaceStateWithDetails nic : ctx.nics) {
                // request guest customization while vm of powered off
                SubnetState subnet = nic.subnet;
                if (subnet != null && nic.description != null && nic.description.assignment == IpAssignment.STATIC) {
                    CustomizationClient cc = new CustomizationClient(connection, ctx.child, vmOverlay.getGuestId());
                    CustomizationSpec template = new CustomizationSpec();
                    cc.customizeNic(vmOverlay.getPrimaryMac(), ctx.child.hostName, nic.address, subnet, template);
                    cc.customizeDns(subnet.dnsServerAddresses, subnet.dnsSearchDomains, template);
                    ManagedObjectReference task = cc.customizeGuest(client.getVm(), template);
                    TaskInfo taskInfo = VimUtils.waitTaskEnd(connection, task);
                    if (taskInfo.getState() == TaskInfoState.ERROR) {
                        VimUtils.rethrow(taskInfo.getError());
                    }
                }
            }
            // power on machine before enrichment
            if (ctx.child.powerState == PowerState.ON) {
                new PowerStateClient(connection).changePowerState(client.getVm(), PowerState.ON, null, 0);
                state.powerState = PowerState.ON;
                Operation op = ctx.mgr.createTaskPatch(TaskStage.FINISHED);
                Boolean awaitIp = CustomProperties.of(ctx.child).getBoolean(ComputeProperties.CUSTOM_PROP_COMPUTE_AWAIT_IP, true);
                if (awaitIp) {
                    Runnable runnable = createCheckForIpTask(ctx.pool, op, client.getVm(), connection.createUnmanagedCopy(), ctx.child.documentSelfLink, ctx);
                    ctx.pool.schedule(runnable, IP_CHECK_INTERVAL_SECONDS, TimeUnit.SECONDS);
                } else {
                    finishTask[0] = op;
                }
            } else {
                // only finish the task without waiting for IP
                finishTask[0] = ctx.mgr.createTaskPatch(TaskStage.FINISHED);
            }
            updateNicsAfterProvisionSuccess(vmOverlay.getNics(), ctx);
            updateDiskLinksAfterProvisionSuccess(state, vmOverlay.getDisks(), ctx);
            state.lifecycleState = LifecycleState.READY;
            // Find the host link where the computed is provisioned and patch the
            // compute state.
            queryHostDocumentAndUpdateCompute(ctx, vmOverlay.getHost()).thenCompose(computeState -> {
                ComputeState hostState = computeState.iterator().next();
                CustomProperties.of(state).put(VC_UUID, CustomProperties.of(hostState).getString(VC_UUID)).put(DATACENTER_SELF_LINK, CustomProperties.of(hostState).getString(DATACENTER_SELF_LINK)).put(COMPUTE_HOST_LINK_PROP_NAME, hostState.documentSelfLink);
                return createComputeResourcePatch(state, ctx.computeReference);
            }).whenComplete((o, e) -> {
                if (e != null) {
                    ctx.fail(e);
                    return;
                }
                if (finishTask.length > 0) {
                    finishTask[0].sendWith(this);
                }
            });
        } catch (Exception e) {
            ctx.fail(e);
        }
    });
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) VirtualEthernetCardOpaqueNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo) QueryTask(com.vmware.xenon.services.common.QueryTask) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) COMPUTE_HOST_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.COMPUTE_HOST_LINK_PROP_NAME) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) VirtualDevice(com.vmware.vim25.VirtualDevice) TaskInfo(com.vmware.vim25.TaskInfo) NsxProperties(com.vmware.photon.controller.model.adapters.vsphere.network.NsxProperties) CustomizationSpec(com.vmware.vim25.CustomizationSpec) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Collectors(java.util.stream.Collectors) ClientUtils.handleVirtualDiskUpdate(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.handleVirtualDiskUpdate) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) ClientUtils.handleVirtualDeviceUpdate(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.handleVirtualDeviceUpdate) VC_UUID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.VC_UUID) VirtualFloppy(com.vmware.vim25.VirtualFloppy) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) StringUtil(io.netty.util.internal.StringUtil) DvsProperties(com.vmware.photon.controller.model.adapters.vsphere.network.DvsProperties) VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) VirtualCdrom(com.vmware.vim25.VirtualCdrom) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) ClientUtils.findMatchingDiskState(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingDiskState) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) DATACENTER_SELF_LINK(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DATACENTER_SELF_LINK) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) TimeUnit(java.util.concurrent.TimeUnit) VirtualDisk(com.vmware.vim25.VirtualDisk) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Collections(java.util.Collections) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) Operation(com.vmware.xenon.common.Operation) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) TaskInfo(com.vmware.vim25.TaskInfo) CustomizationSpec(com.vmware.vim25.CustomizationSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with NetworkInterfaceStateWithDetails

use of com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails in project photon-model by vmware.

the class InstanceClient method customizeAfterClone.

private void customizeAfterClone() throws Exception {
    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    // is takes precedence
    if (this.ctx.child.description.cpuCount > 0) {
        spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
    }
    String gt = CustomProperties.of(this.ctx.child).getString(CustomProperties.GUEST_ID, null);
    if (gt != null) {
        spec.setGuestId(gt);
    }
    if (this.ctx.child.description.totalMemoryBytes > 0) {
        spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));
    }
    recordTimestamp(spec.getExtraConfig());
    // set ovf environment
    ArrayOfVAppPropertyInfo infos = this.get.entityProp(this.vm, VimPath.vm_config_vAppConfig_property);
    populateCloudConfig(spec, infos);
    // remove nics and attach to proper networks if nics are configured
    ArrayOfVirtualDevice devices = null;
    if (this.ctx.nics != null && this.ctx.nics.size() > 0) {
        devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualEthernetCard).forEach(nic -> {
            VirtualDeviceConfigSpec removeNicChange = new VirtualDeviceConfigSpec();
            removeNicChange.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
            removeNicChange.setDevice(nic);
            spec.getDeviceChange().add(removeNicChange);
        });
        for (NetworkInterfaceStateWithDetails niState : this.ctx.nics) {
            VirtualDevice nic = createNic(niState, null);
            addDeviceToVm(spec, nic);
        }
    }
    // Find whether it has HDD disk
    if (this.imageDisks != null && !this.imageDisks.isEmpty()) {
        // Iterate over each of the VirtualDisk and reconfigure if needed
        if (devices == null) {
            devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        }
        spec.getDeviceChange().addAll(getCustomizationConfigSpecs(devices, this.imageDisks));
    }
    // set the maximum snapshot limit if specified
    final String snapshotLimit = CustomProperties.of(this.ctx.child).getString(CustomProperties.SNAPSHOT_MAXIMUM_LIMIT);
    recordSnapshotLimit(spec.getExtraConfig(), snapshotLimit);
    ManagedObjectReference task = getVimPort().reconfigVMTask(this.vm, spec);
    TaskInfo info = waitTaskEnd(task);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
    // If there are any data disks then attach then to the VM
    if (this.dataDisks != null && !this.dataDisks.isEmpty()) {
        attachDisks(this.dataDisks, false);
    }
    // If there are any external disks, then attach then to the VM
    attachExternalDisks();
}
Also used : ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) VirtualDiskSpec(com.vmware.vim25.VirtualDiskSpec) ClientUtils.fillInControllerUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.findFreeScsiUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeScsiUnit) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ClientUtils.getFirstIdeController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstIdeController) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) Utils(com.vmware.xenon.common.Utils) Document(org.w3c.dom.Document) Map(java.util.Map) VirtualDevice(com.vmware.vim25.VirtualDevice) EnumSet(java.util.EnumSet) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) ClientUtils.createHdd(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd) ClientUtils.getFirstScsiController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstScsiController) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ClientUtils.nextUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.nextUnitNumber) ClientUtils.getFirstSioController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstSioController) ClientUtils.getDatastorePathForDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastorePathForDisk) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) DuplicateNameFaultMsg(com.vmware.vim25.DuplicateNameFaultMsg) ArrayUpdateOperation(com.vmware.vim25.ArrayUpdateOperation) UriUtils(com.vmware.xenon.common.UriUtils) ClientUtils.detachDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk) VirtualFloppy(com.vmware.vim25.VirtualFloppy) ClientUtils.getStorageIOAllocationInfo(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getStorageIOAllocationInfo) Finder(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Finder) OvfDeployer(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController) OptionValue(com.vmware.vim25.OptionValue) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) VirtualCdrom(com.vmware.vim25.VirtualCdrom) STORAGE_REFERENCE(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_REFERENCE) OvfRetriever(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever) ClientUtils.getDiskProvisioningType(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskProvisioningType) DISK_DATASTORE_NAME(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_DATASTORE_NAME) VirtualMachineRelocateDiskMoveOptions(com.vmware.vim25.VirtualMachineRelocateDiskMoveOptions) InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) DiskStatus(com.vmware.photon.controller.model.resources.DiskService.DiskStatus) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) ClientUtils.getDiskMode(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskMode) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClientUtils.findFreeUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeUnit) ClientUtils.insertCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertCdrom) MethodFault(com.vmware.vim25.MethodFault) Lock(java.util.concurrent.locks.Lock) VirtualDisk(com.vmware.vim25.VirtualDisk) Paths(java.nio.file.Paths) InvalidNameFaultMsg(com.vmware.vim25.InvalidNameFaultMsg) ClientUtils.insertFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertFloppy) VAppPropertySpec(com.vmware.vim25.VAppPropertySpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualEthernetCardMacType(com.vmware.vim25.VirtualEthernetCardMacType) OvfParser(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser) BaseHelper(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BaseHelper) LoggerFactory(org.slf4j.LoggerFactory) ClientUtils.toKb(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.toKb) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VAppPropertyInfo(com.vmware.vim25.VAppPropertyInfo) ClientUtils.getPbmProfileSpec(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getPbmProfileSpec) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VM_PATH_FORMAT(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) DuplicateName(com.vmware.vim25.DuplicateName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualPCIController(com.vmware.vim25.VirtualPCIController) ClientUtils.createCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom) Entry(java.util.Map.Entry) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) FileAlreadyExists(com.vmware.vim25.FileAlreadyExists) ClientUtils.makePathToVmdkFile(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.makePathToVmdkFile) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) NetworkDeviceBackingFactory(com.vmware.photon.controller.model.adapters.vsphere.network.NetworkDeviceBackingFactory) ClientUtils.getDatastoreFromStoragePolicy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastoreFromStoragePolicy) Logger(org.slf4j.Logger) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ReentrantLock(java.util.concurrent.locks.ReentrantLock) VirtualE1000(com.vmware.vim25.VirtualE1000) Operation(com.vmware.xenon.common.Operation) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER) ClientUtils.createFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) DISK_PARENT_DIRECTORY(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_PARENT_DIRECTORY) TimeUnit(java.util.concurrent.TimeUnit) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) VirtualSCSISharing(com.vmware.vim25.VirtualSCSISharing) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Collections(java.util.Collections) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with NetworkInterfaceStateWithDetails

use of com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails in project photon-model by vmware.

the class InstanceClient method buildVirtualMachineConfigSpec.

/**
 * Creates a spec used to create the VM.
 *
 * @param datastoreName
 * @return
 * @throws InvalidPropertyFaultMsg
 * @throws FinderException
 * @throws RuntimeFaultFaultMsg
 */
private VirtualMachineConfigSpec buildVirtualMachineConfigSpec(String datastoreName) throws InvalidPropertyFaultMsg, FinderException, RuntimeFaultFaultMsg {
    String displayName = this.ctx.child.name;
    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    spec.setName(displayName);
    spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
    spec.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST_64.value());
    spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));
    VirtualMachineFileInfo files = new VirtualMachineFileInfo();
    // Use a full path to the config file to avoid creating a VM with the same name
    String path = String.format("[%s] %s/%s.vmx", datastoreName, displayName, displayName);
    files.setVmPathName(path);
    spec.setFiles(files);
    for (NetworkInterfaceStateWithDetails ni : this.ctx.nics) {
        VirtualDevice nic = createNic(ni, null);
        addDeviceToVm(spec, nic);
    }
    VirtualDevice scsi = createScsiController();
    addDeviceToVm(spec, scsi);
    return spec;
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Aggregations

NetworkInterfaceStateWithDetails (com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails)11 ArrayList (java.util.ArrayList)9 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 VirtualDevice (com.vmware.vim25.VirtualDevice)5 Operation (com.vmware.xenon.common.Operation)5 List (java.util.List)5 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)4 VimPath (com.vmware.photon.controller.model.adapters.vsphere.util.VimPath)4 Connection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection)4 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)4 DiskStateExpanded (com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded)4 DiskType (com.vmware.photon.controller.model.resources.DiskService.DiskType)4 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)4 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)4 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)4 TaskInfo (com.vmware.vim25.TaskInfo)4 TaskInfoState (com.vmware.vim25.TaskInfoState)4 VirtualCdrom (com.vmware.vim25.VirtualCdrom)4 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)4