Search in sources :

Example 11 with DistributedVirtualPortgroup

use of com.vmware.vim25.mo.DistributedVirtualPortgroup in project cloudstack by apache.

the class DatacenterMO method getDvPortGroupSpec.

public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
    DVPortgroupConfigInfo configSpec = null;
    String nameProperty = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("config");
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
    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);
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                assert (props.size() == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("config")) {
                        configSpec = (DVPortgroupConfigInfo) prop.getVal();
                    } else {
                        nameProperty = prop.getVal().toString();
                    }
                }
                if (nameProperty.equalsIgnoreCase(dvPortGroupName)) {
                    return configSpec;
                }
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo)

Example 12 with DistributedVirtualPortgroup

use of com.vmware.vim25.mo.DistributedVirtualPortgroup in project cloudstack by apache.

the class DatacenterMO method getDvPortBackingInfo.

public VirtualEthernetCardDistributedVirtualPortBackingInfo getDvPortBackingInfo(Pair<ManagedObjectReference, String> networkInfo) throws Exception {
    assert (networkInfo != null);
    assert (networkInfo.first() != null && networkInfo.first().getType().equalsIgnoreCase("DistributedVirtualPortgroup"));
    final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
    final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
    ManagedObjectReference dvsMor = getDvSwitchMor(networkInfo.first());
    String dvSwitchUuid = getDvSwitchUuid(dvsMor);
    dvPortConnection.setSwitchUuid(dvSwitchUuid);
    dvPortConnection.setPortgroupKey(networkInfo.first().getValue());
    dvPortBacking.setPort(dvPortConnection);
    System.out.println("Plugging NIC device into network " + networkInfo.second() + " backed by dvSwitch: " + dvSwitchUuid);
    return dvPortBacking;
}
Also used : VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) DistributedVirtualSwitchPortConnection(com.vmware.vim25.DistributedVirtualSwitchPortConnection) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with DistributedVirtualPortgroup

use of com.vmware.vim25.mo.DistributedVirtualPortgroup in project cloudstack by apache.

the class VirtualMachineMO method getNetworksWithDetails.

public List<NetworkDetails> getNetworksWithDetails() throws Exception {
    List<NetworkDetails> networks = new ArrayList<NetworkDetails>();
    int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC);
    if (gcTagKey == 0) {
        gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
        s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey);
    }
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("vm");
    pSpec.getPathSet().add(String.format("value[%d]", gcTagKey));
    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);
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            ArrayOfManagedObjectReference morVms = null;
            String gcTagValue = null;
            String name = null;
            for (DynamicProperty prop : oc.getPropSet()) {
                if (prop.getName().equals("name"))
                    name = prop.getVal().toString();
                else if (prop.getName().equals("vm"))
                    morVms = (ArrayOfManagedObjectReference) prop.getVal();
                else if (prop.getName().startsWith("value[")) {
                    CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
                    if (val != null)
                        gcTagValue = val.getValue();
                }
            }
            NetworkDetails details = new NetworkDetails(name, oc.getObj(), (morVms != null ? morVms.getManagedObjectReference().toArray(new ManagedObjectReference[morVms.getManagedObjectReference().size()]) : null), gcTagValue);
            networks.add(details);
        }
        s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey);
    }
    return networks;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with DistributedVirtualPortgroup

use of com.vmware.vim25.mo.DistributedVirtualPortgroup in project cloudstack by apache.

the class VirtualMachineMO method getDvPortGroupName.

public String getDvPortGroupName(VirtualEthernetCard nic) throws Exception {
    VirtualEthernetCardDistributedVirtualPortBackingInfo dvpBackingInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo) nic.getBacking();
    DistributedVirtualSwitchPortConnection dvsPort = dvpBackingInfo.getPort();
    String dvPortGroupKey = dvsPort.getPortgroupKey();
    ManagedObjectReference dvPortGroupMor = new ManagedObjectReference();
    dvPortGroupMor.setValue(dvPortGroupKey);
    dvPortGroupMor.setType("DistributedVirtualPortgroup");
    return (String) _context.getVimClient().getDynamicProperty(dvPortGroupMor, "name");
}
Also used : VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) DistributedVirtualSwitchPortConnection(com.vmware.vim25.DistributedVirtualSwitchPortConnection) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

DynamicProperty (com.vmware.vim25.DynamicProperty)8 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)8 ObjectContent (com.vmware.vim25.ObjectContent)8 ObjectSpec (com.vmware.vim25.ObjectSpec)8 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)8 PropertySpec (com.vmware.vim25.PropertySpec)8 TraversalSpec (com.vmware.vim25.TraversalSpec)8 ArrayList (java.util.ArrayList)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)4 DistributedVirtualSwitchPortConnection (com.vmware.vim25.DistributedVirtualSwitchPortConnection)4 VirtualEthernetCardDistributedVirtualPortBackingInfo (com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo)4 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 RemoteException (java.rmi.RemoteException)2 VirtualRoutingResource (com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 VmwareHostService (com.cloud.hypervisor.vmware.manager.VmwareHostService)1 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)1