def remove_hosts(cls, client_object, hosts=None):
        """
        Removes hosts from the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hosts: list
        @param hosts: Name of the hosts

        @rtype: str
        @return: Status of the operation
        """
        host_config = []
        host_mor = None
        vds_mor = client_object.vds_mor
        members_name = []
        for member in vds_mor.config.host:
            members_name.append(member.config.host.name)
        for host in hosts:
            if host in members_name:
                host_member_config = client_object.get_host_member_config(
                    host_mor=host_mor, operation="remove")
                host_config.append(host_member_config)
            else:
                pylogger.error("%r not found" % host)
        if len(host_config) == 0:
            pylogger.error("No hosts found on the switch")
            return constants.Result.FAILURE
        dvs = client_object.get_dvs_config_spec()
        dvs.host = host_config
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        vc_soap_util.get_task_state(task)
    def block(cls, client_object):
        """
        Blocks the port on the vdswitch.

        @type client_object: DVPortAPIClient instance
        @param client_object: DVPortgroupAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        dvp = vim.dvs.DistributedVirtualPort.ConfigSpec()
        dvp.operation = "edit"
        setting = vim.dvs.DistributedVirtualPort.Setting()
        bool_policy = vim.BoolPolicy()
        bool_policy.value = True
        setting.blocked = bool_policy
        dvp.setting = setting
        dvp.key = client_object.name
        if isinstance(client_object.parent, DVPGAPIClient):
            policy = vim.dvs.DistributedVirtualPortgroup.PortgroupPolicy()
            policy.blockOverrideAllowed = True
            dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
            dvpg_config.policy = policy
            dvpg_mor = client_object.parent.dvpg_mor
            dvpg_config.configVersion = dvpg_mor.config.configVersion
            task_check = dvpg_mor.ReconfigureDVPortgroup_Task(
                dvpg_config)
            if vc_soap_util.get_task_state(task_check) == SUCCESS:
                vds_mor = client_object.parent.parent.vds_mor
                task = vds_mor.ReconfigureDVPort_Task([dvp])
        elif isinstance(client_object.parent, VDSwitchAPIClient):
            task = client_object.parent.vds_mor.ReconfigureDVPort_Task([dvp])
        return vc_soap_util.get_task_state(task)
    def remove_hosts(cls, client_object, hosts=None):
        """
        Removes hosts from the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hosts: list
        @param hosts: Name of the hosts

        @rtype: str
        @return: Status of the operation
        """
        host_config = []
        host_mor = None
        vds_mor = client_object.vds_mor
        members_name = []
        for member in vds_mor.config.host:
            members_name.append(member.config.host.name)
        for host in hosts:
            if host in members_name:
                host_member_config = client_object.get_host_member_config(
                    host_mor=host_mor, operation="remove")
                host_config.append(host_member_config)
            else:
                pylogger.error("%r not found" % host)
        if len(host_config) == 0:
            pylogger.error("No hosts found on the switch")
            return constants.Result.FAILURE
        dvs = client_object.get_dvs_config_spec()
        dvs.host = host_config
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        vc_soap_util.get_task_state(task)
Exemple #4
0
    def block(cls, client_object):
        """
        Blocks the port on the vdswitch.

        @type client_object: DVPortAPIClient instance
        @param client_object: DVPortgroupAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        dvp = vim.dvs.DistributedVirtualPort.ConfigSpec()
        dvp.operation = "edit"
        setting = vim.dvs.DistributedVirtualPort.Setting()
        bool_policy = vim.BoolPolicy()
        bool_policy.value = True
        setting.blocked = bool_policy
        dvp.setting = setting
        dvp.key = client_object.name
        if isinstance(client_object.parent, DVPGAPIClient):
            policy = vim.dvs.DistributedVirtualPortgroup.PortgroupPolicy()
            policy.blockOverrideAllowed = True
            dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
            dvpg_config.policy = policy
            dvpg_mor = client_object.parent.dvpg_mor
            dvpg_config.configVersion = dvpg_mor.config.configVersion
            task_check = dvpg_mor.ReconfigureDVPortgroup_Task(dvpg_config)
            if vc_soap_util.get_task_state(task_check) == SUCCESS:
                vds_mor = client_object.parent.parent.vds_mor
                task = vds_mor.ReconfigureDVPort_Task([dvp])
        elif isinstance(client_object.parent, VDSwitchAPIClient):
            task = client_object.parent.vds_mor.ReconfigureDVPort_Task([dvp])
        return vc_soap_util.get_task_state(task)
Exemple #5
0
    def apply_profile(cls, client_object, hostname=None,
                      datacenter=None, parameter_id=None,
                      policy_id=None, profile_path=None,
                      parameter_keys=None, parameter_values=None):
        """
        Applies a host profile to a host.

        @type client_object: ProfileAPIClient instance
        @param client_object: ProfileAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type datacenter: str
        @param datacenter: Datacenter name
        @type parameter_id: str
        @param parameter_id: Key for a parameter in the policy specified
            by policyId
        @type policy_id: str
        @param policy_id: Policy option identifier.
        @type profile_path: str
        @param profile_path: Complete path to the leaf profile, relative
            to the root of the host profile document. Eg for vswitch policy,
            profile path is network.vswitch
        @type parameter_keys: list
        @param parameter_keys: List of keys for policy parameters
        @type parameter_values: list
        @param parameter_values: List of values for policy parameters

        @rtype: str
        @return: Status of the operation
        """
        deferred_param_list = []
        host_mor = client_object.parent.get_host_mor(hostname, datacenter)
        profile_mor = client_object.host_profile_manager_mor
        deferred_param = client_object.get_deferred_policy_option(
            parameter_id=parameter_id, policy_id=policy_id,
            profile_path=profile_path, parameter_keys=parameter_keys,
            parameter_values=parameter_values)
        deferred_param_list.append(deferred_param)
        for profile in profile_mor.profile:
            if profile.name == client_object.name:
                result = profile.ExecuteHostProfile(
                    host_mor, deferred_param_list)
                if result.status == constants.Result.SUCCESS.lower():
                    task = host_mor.EnterMaintenanceMode_Task(
                        timeout=120)
                    if vc_soap_util.get_task_state(task) == Success_lower:
                        task = profile_mor.ApplyHostConfig_Task(
                            host_mor, result.configSpec)
                        return vc_soap_util.get_task_state(task)
                    else:
                        pylogger.error("Host could not enter maintenance mode")
                        return
                else:
                    pylogger.error("Execute profile operation failed: ",
                                   result.error)
        pylogger.error("Could not apply profile")
Exemple #6
0
    def check_compliance(cls, client_object, profile=None, entity=None):
        """
        Checks if the entity is compliant against the profile.

        @type client_object: ProfileAPIClient instance
        @param client_object: ProfileAPIClient instance
        @type profile: str
        @param profile: Checks compliance of entity against a profile.
            Defaults to hostprofile.
        @type entity: ManagedObject instance
        @param entity: Entity to be checked

        @rtype: str
        @return: Status of the operation
        """
        manager = client_object.get_profile_compliance_manager()
        host_profile = client_object.get_host_profile_manager_mor()
        content = host_profile.profile
        if profile is not None:
            for content in host_profile.profile:
                if content.name == client_object.name:
                    content = [content]
        try:
            task = manager.CheckCompliance_Task(
                content, entity)
            return vc_soap_util.get_task_state(task)
        except Exception as e:
            raise Exception("Could not check profile compliance", e)
    def remove_host(cls, client_object, hostname=None):
        """
        Removes a host from the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hostname: str
        @param hostname: Name of the host

        @rtype: str
        @return: Status of the operation
        """
        host_mor = None
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
            else:
                host_mor = None
        if host_mor is None:
            raise Exception("Host not found on %s" % (client_object.name))
        dvs = client_object.get_dvs_config_spec()
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, operation="remove")
        dvs.host = [host_member_config]
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def add_pvlan_map(cls, client_object, operation=None,
                      primary_vlan_id=None, pvlan_type=None,
                      secondary_vlan_id=None):
        """
        Adds a pvlan map on the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type operation: str
        @param operation: edit, add, or remove
        @type primary_vlan_id: int
        @param primary_vlan_id: The primary VLAN ID. The VLAN IDs of 0 and 4095
            are reserved and cannot be used in this property.
        @type secondary_vlan_id: int
        @param secondary_vlan_id: The secondary VLAN ID. The VLAN IDs of 0 and
            4095 are reserved and cannot be used in this property.
        @type pvlan_type: str
        @param pvlan_type: community, isolated, or promiscuous

        @rtype: str
        @return: status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        pvlan = client_object.get_pvlan_config_spec(
            operation=operation, primary_vlan_id=primary_vlan_id,
            secondary_vlan_id=secondary_vlan_id, pvlan_type=pvlan_type)
        dvs.pvlanConfigSpec = pvlan
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def edit_max_proxy_switchports(cls, client_object,
                                   hostname=None, maxports=None):
        """
        Edit the maximum proxy ports for a host.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type maxports: int
        @param maxports: Specifies the number of proxy ports.

        @rtype: str
        @return: Status of the operation.
        """
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, maxports=maxports)
        dvs = client_object.get_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        dvs.host = [host_member_config]
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def create(cls, client_object):
        """
        Creates a new port on the distributer virtual portgroup.

        @type client_object: DVPortAPIClient instance
        @param client_object: DVPGAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        # Parent of dvport is dvportgroup
        # The first port to get added is assumed to be the new port created
        new_ports = []
        if isinstance(client_object.parent, DVPGAPIClient) is True:
            dvpg_mor = client_object.parent.dvpg_mor
            existing_ports = dvpg_mor.portKeys
            dvpg_spec = vim.DistributedVirtualPortgroup.ConfigSpec()
            dvpg_spec.configVersion = client_object.parent.dvpg_mor.config.configVersion
            dvpg_spec.numPorts = client_object.parent.dvpg_mor.config.numPorts + 1
            task = client_object.parent.dvpg_mor.ReconfigureDVPortgroup_Task(
                dvpg_spec)
            result = vc_soap_util.get_task_state(task)
            if result == "success":
                new_ports = dvpg_mor.portKeys
                for port in list(set(new_ports)-set(existing_ports)):
                    client_object.name = port
                    break
                return result
            else:
                return constants.Result.FAILURE
    def create(cls, client_object, schema_object=None):
        """
        Creates a distributed virtual portgroup on the switch.

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type schema_object: NetworkSchema instance
        @param schema_object: Schema object contating portgroup attributes

        @rtype: str
        @return: Status of the operation
        """
        dvpg_spec = client_object.get_dvpg_config_spec(
            auto_expand=schema_object.auto_expand,
            description=schema_object.description,
            name=client_object.name,
            numports=schema_object.numports,
            portgroup_type=schema_object.portgroup_type,
            resource_pool=schema_object.resource_pool)
        task = client_object.parent.vds_mor.CreateDVPortgroup_Task(dvpg_spec)
        result = vc_soap_util.get_task_state(task)
        if result == SUCCESS:
            client_object.dvpg_mor = task.info.result
            client_object.dvpg_key = client_object.dvpg_mor.key
        return result
    def set_private_vlan(cls, client_object, vlan=None):
        """
        Sets a private vlan on the portgroup.

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type vlan: int
        @param vlan: The VLAN ID for ports. Possible values:
            A value of 0 specifies that you do not want the port
                associated with a VLAN.
            A value from 1 to 4094 specifies a VLAN ID for the port.

        @rtype: str
        @return: Status of the operation
        """
        dvpg_mor = client_object.dvpg_mor
        dvpg_port_config = dvpg_mor.config.defaultPortConfig
        vlan_spec = vim.dvs.VmwareDistributedVirtualSwitch.PvlanSpec()
        vlan_spec.pvlanId = vlan
        dvpg_port_config.vlan = vlan_spec
        dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
        dvpg_config.defaultPortConfig = dvpg_port_config
        dvpg_config.configVersion = dvpg_mor.config.configVersion
        try:
            task = dvpg_mor.ReconfigureDVPortgroup_Task(dvpg_config)
            return vc_soap_util.get_task_state(task)
        except Exception as e:
            raise Exception("Could not set private vlan", e)
    def set_vlan_trunking(cls, client_object, vlan_start=None, vlan_end=None):
        """
        Sets vlan trunking on the portgroup.

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type vlan_start: int
        @param vlan_start: Starting vlan ID
        @type vlan_end: int
        @param vlan_end: Ending vlan ID

        @rtype: str
        @return: Status of the operation
        """
        dvpg_mor = client_object.dvpg_mor
        dvpg_port_config = dvpg_mor.config.defaultPortConfig
        vlan_spec = vim.dvs.VmwareDistributedVirtualSwitch.TrunkVlanSpec()
        num_range = vim.NumericRange()
        num_range.start = vlan_start
        num_range.end = vlan_end
        vlan_spec.vlanId = [num_range]
        dvpg_port_config.vlan = vlan_spec
        dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
        dvpg_config.defaultPortConfig = dvpg_port_config
        dvpg_config.configVersion = dvpg_mor.config.configVersion
        try:
            task = dvpg_mor.ReconfigureDVPortgroup_Task(dvpg_config)
            return vc_soap_util.get_task_state(task)
        except Exception as e:
            raise Exception("Could not set vlan trunking, e")
Exemple #14
0
    def create(cls, client_object):
        """
        Creates a new port on the distributer virtual portgroup.

        @type client_object: DVPortAPIClient instance
        @param client_object: DVPGAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        # Parent of dvport is dvportgroup
        # The first port to get added is assumed to be the new port created
        new_ports = []
        if isinstance(client_object.parent, DVPGAPIClient) is True:
            dvpg_mor = client_object.parent.dvpg_mor
            existing_ports = dvpg_mor.portKeys
            dvpg_spec = vim.DistributedVirtualPortgroup.ConfigSpec()
            dvpg_spec.configVersion = client_object.parent.dvpg_mor.config.configVersion
            dvpg_spec.numPorts = client_object.parent.dvpg_mor.config.numPorts + 1
            task = client_object.parent.dvpg_mor.ReconfigureDVPortgroup_Task(
                dvpg_spec)
            result = vc_soap_util.get_task_state(task)
            if result == "success":
                new_ports = dvpg_mor.portKeys
                for port in list(set(new_ports) - set(existing_ports)):
                    client_object.name = port
                    break
                return result
            else:
                return constants.Result.FAILURE
    def remove_host(cls, client_object, hostname=None):
        """
        Removes a host from the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hostname: str
        @param hostname: Name of the host

        @rtype: str
        @return: Status of the operation
        """
        host_mor = None
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
            else:
                host_mor = None
        if host_mor is None:
            raise Exception("Host not found on %s" % (client_object.name))
        dvs = client_object.get_dvs_config_spec()
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, operation="remove")
        dvs.host = [host_member_config]
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def edit_max_proxy_switchports(cls,
                                   client_object,
                                   hostname=None,
                                   maxports=None):
        """
        Edit the maximum proxy ports for a host.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type maxports: int
        @param maxports: Specifies the number of proxy ports.

        @rtype: str
        @return: Status of the operation.
        """
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, maxports=maxports)
        dvs = client_object.get_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        dvs.host = [host_member_config]
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def add_pvlan_map(cls,
                      client_object,
                      operation=None,
                      primary_vlan_id=None,
                      pvlan_type=None,
                      secondary_vlan_id=None):
        """
        Adds a pvlan map on the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type operation: str
        @param operation: edit, add, or remove
        @type primary_vlan_id: int
        @param primary_vlan_id: The primary VLAN ID. The VLAN IDs of 0 and 4095
            are reserved and cannot be used in this property.
        @type secondary_vlan_id: int
        @param secondary_vlan_id: The secondary VLAN ID. The VLAN IDs of 0 and
            4095 are reserved and cannot be used in this property.
        @type pvlan_type: str
        @param pvlan_type: community, isolated, or promiscuous

        @rtype: str
        @return: status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        pvlan = client_object.get_pvlan_config_spec(
            operation=operation,
            primary_vlan_id=primary_vlan_id,
            secondary_vlan_id=secondary_vlan_id,
            pvlan_type=pvlan_type)
        dvs.pvlanConfigSpec = pvlan
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def create(cls, client_object, schema_object=None):
        """
        Creates a distributed virtual portgroup on the switch.

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type schema_object: NetworkSchema instance
        @param schema_object: Schema object contating portgroup attributes

        @rtype: str
        @return: Status of the operation
        """
        dvpg_spec = client_object.get_dvpg_config_spec(
            auto_expand=schema_object.auto_expand,
            description=schema_object.description,
            name=client_object.name,
            numports=schema_object.numports,
            portgroup_type=schema_object.portgroup_type,
            resource_pool=schema_object.resource_pool)
        task = client_object.parent.vds_mor.CreateDVPortgroup_Task(dvpg_spec)
        result = vc_soap_util.get_task_state(task)
        if result == SUCCESS:
            client_object.dvpg_mor = task.info.result
            client_object.dvpg_key = client_object.dvpg_mor.key
        return result
Exemple #19
0
    def configure_pci_passthrough(
            cls, client_object, key=None, device=None,
            controller_key=None, operation=None):
        """
        Adds or removes a pci passthrough for the VM.

        @type client_object: VMAPIClient instance
        @param client_object: VMAPIClient instance
        @type key: int
        @param key: A unique key that distinguishes this device from
            other devices in the same virtual machine.
        @type device: str
        @param device: Name of pnic, eg vmnic0
        @type controller_key: str
        @param controller_key: Object key for the controller object for this
            device. This property contains the key property value of the
            controller device object.
        @type operation: str
        @param operation: add or remove

        @rtype: str
        @param: Status of the operation
        """
        host_mor = client_object.parent.get_host_mor()
        network_sys = host_mor.configManager.networkSystem
        backing_spec = vim.vm.device.VirtualPCIPassthrough.DeviceBackingInfo()
        for pnic in network_sys.networkInfo.pnic:
            if pnic.device == device:
                pci = pnic.pci
                for pci_device in host_mor.hardware.pciDevice:
                    if pci_device.id == pci:
                        vm_mor = client_object.get_api()
                        config_spec = vim.vm.ConfigSpec()
                        device_spec = vim.vm.device.VirtualDeviceSpec()
                        device_spec.operation = operation
                        passthru = vim.vm.device.VirtualPCIPassthrough()
                        if operation == ADD:
                            backing_spec.deviceId = str(pci_device.deviceId)
                            backing_spec.id = pci
                            backing_spec.vendorId = pci_device.vendorId
                            uuid = host_mor.hardware.systemId.uuid
                            backing_spec.systemId = uuid
                            passthru.backing = backing_spec
                            passthru.controllerKey = controller_key
                            passthru.key = key
                            device_spec.device = passthru
                            config_spec.deviceChange = [device_spec]
                        elif operation == REMOVE:
                            passthru.key = key
                            device_spec.device = passthru
                            config_spec.deviceChange = [device_spec]
                        else:
                            raise Exception("Specifiy operation type")
                        try:
                            return vc_soap_util.get_task_state(
                                vm_mor.ReconfigVM_Task(config_spec))
                        except Exception as e:
                            raise Exception("Could not add passthrough", e)
        pylogger.error("Could not find %r" % device)
    def set_nic_teaming(cls, client_object, check_beacon=None,
                        check_duplex=None, notify_switches=None,
                        policy=None, reverse_policy=None,
                        rolling_order=None, active_uplink_port=None,
                        standby_uplink_port=None):
        """
        Configure nic teaming policy on the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type check_beacon: bool
        @param check_beacon: The flag to indicate whether or not to enable this
            property to enable beacon probing as a method to validate the link
            status of a physical network adapter
        @type check_duplex: bool
        @param check_duplex: The flag to indicate whether or not to use the
            link duplex reported by the driver as link selection criteria
        @type notify_switches: bool
        @param notify_switches: Flag to specify whether or not to notify the
            physical switch if a link fails
        @type policy: str
        @param policy: failover_explicit, loadbalance_ip, loadbalance_loadbased
            ,loadbalance_srcid, loadbalance_srcmac
        @type reverse_policy: bool
        @param reverse_policy: The flag to indicate whether or not the teaming
            policy is applied to inbound frames as well
        @type rolling_order: bool
        @param rolling_order: The flag to indicate whether or not to use a
            rolling policy when restoring links
        @type active_uplink_port: str
        @param active_uplink_port: List of active uplink ports used for load
            balancing
        @type standby_uplink_port: str
        @param standby_uplink_port: Standby uplink ports used for failover

        @rtype: str
        @return: Status of the operation.
        """
        failure = client_object.get_dvs_failure_criteria(
            check_beacon=check_beacon, check_duplex=check_duplex)
        notify = client_object.get_notify_switches(
            notify_switches)
        policy = client_object.get_uplink_port_policy(policy)
        reverse = client_object.get_reverse_policy(reverse_policy)
        rolling = client_object.get_rolling_policy(rolling_order)
        uplink_port_order = client_object.get_vmware_uplink_port_order_policy(
            active_uplink_port=active_uplink_port,
            standby_uplink_port=standby_uplink_port)
        port_config = client_object.get_vmware_port_config_policy()
        uplink_teaming = client_object.get_uplink_port_teaming_policy(
            failure=failure, notify=notify, policy=policy,
            reverse=reverse, rolling=rolling,
            uplink_port_order=uplink_port_order)
        port_config.uplinkTeamingPolicy = uplink_teaming
        dvs = client_object.get_dvs_config_spec()
        dvs.defaultPortConfig = port_config
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
Exemple #21
0
 def rename_vm(cls, client_object, name=None):
     vm_mor = client_object.get_api()
     config_spec = vim.vm.ConfigSpec()
     config_spec.name = name
     try:
         return vc_soap_util.get_task_state(
             vm_mor.ReconfigVM_Task(config_spec))
     except Exception as e:
         raise Exception("Could not rename the vm", e)
Exemple #22
0
 def rename_vm(cls, client_object, name=None):
     vm_mor = client_object.get_api()
     config_spec = vim.vm.ConfigSpec()
     config_spec.name = name
     try:
         return vc_soap_util.get_task_state(
             vm_mor.ReconfigVM_Task(config_spec))
     except Exception as e:
         raise Exception("Could not rename the vm", e)
    def configure_ipfix(cls,
                        client_object,
                        active_flow_timeout=None,
                        collector_ip=None,
                        collector_port=None,
                        idle_flow_timeout=None,
                        internal_flows_only=None,
                        observation_domain_id=None,
                        sampling_rate=None):
        """
        Configures ipfix on the switch.

        @type client_object: client instance
        @param client_object: VDSwitchAPIClient instance
        @type active_flow_timeout: int
        @param active_flow_timeout: Number of seconds after which "active"
            flows are forced to be exported to the collector. Legal value
            range is 60-3600. Default 60.
        @type collector_ip: str
        @param collector_ip: IP address for the ipfix collector, using IPv4
            or IPv6
        @type collector_port: int
        @param collector_port: Port for the ipfix collector
        @type idle_flow_timeout: int
        @param idle_flow_timeout: The number of seconds after which "idle"
            flows are forced to be exported to the collector
        @type internal_flows_only: bool
        @param internal_flows_only: Whether to limit analysis to traffic
            that has both source and destination served by the same host.
            Default false
        @type observation_domain_id: long
        @param observation_domain_id: Observation Domain Id for the ipfix
            collector.
        @type sampling_rate: int
        @param sampling_rate: The ratio of total number of packets to the
            number of packets analyzed. Set to 0 to disable sampling.
            Legal value range is 0-1000. Default 0.

        @rtype: str
        @return: Status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        ipfix = client_object.get_ipfix_config(
            active_flow_timeout=active_flow_timeout,
            collector_ip=collector_ip,
            collector_port=collector_port,
            idle_flow_timeout=idle_flow_timeout,
            internal_flows_only=internal_flows_only,
            observation_domain_id=observation_domain_id,
            sampling_rate=sampling_rate)
        dvs.ipfixConfig = ipfix
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def delete(cls, client_object):
        """
        Deletes the datacenter.

        @type client_object: DatacenterAPIClient instance
        @param client_object: DatacenterAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        datacenter = client_object.get_datacenter_mor()
        return vc_soap_util.get_task_state(datacenter.Destroy_Task())
    def delete(cls, client_object):
        """
        Deletes the switch from the inventory.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        task = client_object.vds_mor.Destroy_Task()
        return vc_soap_util.get_task_state(task)
Exemple #26
0
    def delete(cls, client_object):
        """
        Deletes a folder.

        @type client_object: FolderAPIClient instance
        @param client_object: FolderAPIClient instance

        @rtype: NoneType
        @return: None
        """
        folder = client_object.parent.get_folder(name=client_object.name)
        return vc_soap_util.get_task_state(folder.Destroy_Task())
    def disconnect_host(cls, client_object):
        """
`       Disconnects host.

        @type client_object: client instance
        @param client_object: Hypervisor client instance

        @rtype: str
        @return: Operation result.
        """
        host_mor = client_object.get_host_mor()
        return vc_soap_util.get_task_state(host_mor.DisconnectHost_Task())
Exemple #28
0
    def delete(cls, client_object):
        """
        Deletes the datacenter.

        @type client_object: DatacenterAPIClient instance
        @param client_object: DatacenterAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        datacenter = client_object.get_datacenter_mor()
        return vc_soap_util.get_task_state(datacenter.Destroy_Task())
    def delete(cls, client_object):
        """
        Deletes the switch from the inventory.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance

        @rtype: str
        @return: Status of the operation
        """
        task = client_object.vds_mor.Destroy_Task()
        return vc_soap_util.get_task_state(task)
    def delete(cls, client_object):
        """
        Deletes a folder.

        @type client_object: FolderAPIClient instance
        @param client_object: FolderAPIClient instance

        @rtype: NoneType
        @return: None
        """
        folder = client_object.parent.get_folder(name=client_object.name)
        return vc_soap_util.get_task_state(folder.Destroy_Task())
    def edit_traffic_shaping(cls,
                             client_object,
                             avg_bandwidth=None,
                             burst_size=None,
                             enabled=None,
                             peak_bandwidth=None,
                             mode=None):
        """
        Edits the traffic shaping policy.

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type avg_bandwidth: long
        @param avg_bandwidth: The average bandwidth in bits per second if
            shaping is enabled on the port.
        @type burst_size: long
        @param burst_size: The maximum burst size allowed in bytes if
            shaping is enabled on the port.
        @type enabled: bool
        @param enabled: The flag to indicate whether or not traffic
            shaper is enabled on the port.
        @type peak_bandwidth: long
        @param peak_bandwidth: The peak bandwidth during bursts in bits
            per second if traffic shaping is enabled on the port.
        @type mode: str
        @param mode: inbound or  ourbound
        @rtype: str
        @return: Status of the operation
        """
        dvpg_mor = client_object.dvpg_mor
        dvpg_port_config = dvpg_mor.config.defaultPortConfig
        shaping_policy = client_object.get_traffic_shaping_policy(
            avg_bandwidth=avg_bandwidth,
            burst_size=burst_size,
            enabled=enabled,
            peak_bandwidth=peak_bandwidth,
            mode=mode)
        if mode == INBOUND:
            dvpg_port_config.inShapingPolicy = shaping_policy
        if mode == OUTBOUND:
            dvpg_port_config.outShapingPolicy = shaping_policy
        dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
        dvpg_config.defaultPortConfig = dvpg_port_config
        dvpg_config.configVersion = dvpg_mor.config.configVersion
        try:
            task = dvpg_mor.ReconfigureDVPortgroup_Task(dvpg_config)
            return vc_soap_util.get_task_state(task)
        except Exception as e:
            raise Exception("Could not edit traffic shaping policy", e)
Exemple #32
0
    def _wait_for_task(cls, task):
        """
        Helper function to wait for task completion and log results.

        The method takes in the task object returned by the API and
        waits till the task has been completed to log the result.

        @type task: instance
        @param task: Task object returned by API.

        @rtype: str
        @return: Status of the operation
        """
        result = vc_soap_util.get_task_state(task)
        return result
Exemple #33
0
    def _wait_for_task(cls, task):
        """
        Helper function to wait for task completion and log results.

        The method takes in the task object returned by the API and
        waits till the task has been completed to log the result.

        @type task: instance
        @param task: Task object returned by API.

        @rtype: str
        @return: Status of the operation
        """
        result = vc_soap_util.get_task_state(task)
        return result
    def remove_component(cls, client_object, component=None):
        """
        Removes a component on the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type component: str
        @param component: Name of the component to be removed

        @rtype: str
        @return: Status of the operation
        """
        vds_mor = client_object.vds_mor
        for portgroup in vds_mor.portgroup:
            if portgroup.name == component:
                return vc_soap_util.get_task_state(portgroup.Destroy_Task())
    def configure_ipfix(cls, client_object, active_flow_timeout=None,
                        collector_ip=None, collector_port=None,
                        idle_flow_timeout=None, internal_flows_only=None,
                        observation_domain_id=None, sampling_rate=None):
        """
        Configures ipfix on the switch.

        @type client_object: client instance
        @param client_object: VDSwitchAPIClient instance
        @type active_flow_timeout: int
        @param active_flow_timeout: Number of seconds after which "active"
            flows are forced to be exported to the collector. Legal value
            range is 60-3600. Default 60.
        @type collector_ip: str
        @param collector_ip: IP address for the ipfix collector, using IPv4
            or IPv6
        @type collector_port: int
        @param collector_port: Port for the ipfix collector
        @type idle_flow_timeout: int
        @param idle_flow_timeout: The number of seconds after which "idle"
            flows are forced to be exported to the collector
        @type internal_flows_only: bool
        @param internal_flows_only: Whether to limit analysis to traffic
            that has both source and destination served by the same host.
            Default false
        @type observation_domain_id: long
        @param observation_domain_id: Observation Domain Id for the ipfix
            collector.
        @type sampling_rate: int
        @param sampling_rate: The ratio of total number of packets to the
            number of packets analyzed. Set to 0 to disable sampling.
            Legal value range is 0-1000. Default 0.

        @rtype: str
        @return: Status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        ipfix = client_object.get_ipfix_config(
            active_flow_timeout=active_flow_timeout, collector_ip=collector_ip,
            collector_port=collector_port, idle_flow_timeout=idle_flow_timeout,
            internal_flows_only=internal_flows_only,
            observation_domain_id=observation_domain_id,
            sampling_rate=sampling_rate)
        dvs.ipfixConfig = ipfix
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def _do_power_action(cls, task):
        """
        Helper method to wait for task completion and return result.

        This method takes in the task object and waits till the
        task is completed and returns the result of the task.

        @type task: instance
        @param task: Task object.

        @rtype: str
        @return: The result of the power operation performed.
        """
        if task is None:
            return
        result = vc_soap_util.get_task_state(task)
        return result
    def remove_component(cls, client_object, component=None):
        """
        Removes a component on the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type component: str
        @param component: Name of the component to be removed

        @rtype: str
        @return: Status of the operation
        """
        vds_mor = client_object.vds_mor
        for portgroup in vds_mor.portgroup:
            if portgroup.name == component:
                return vc_soap_util.get_task_state(
                    portgroup.Destroy_Task())
    def bind_pnic(cls,
                  client_object,
                  pnic=None,
                  hostname=None,
                  uplink_portgroup=None,
                  uplink_port=None,
                  operation=None):
        """
        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type pnic: str
        @param pnic: Name of the pnic
        @type hostname: str
        @param hostname: Host name
        @type uplink_portgroup: str
        @param uplink_portgroup: Uplink portgroup to bind to
        @type uplink_port: str
        @param uplink_port: Uplink port to bind to
        @type operation: str
        @param operation: add, remove, edit

        @rtype: str
        @return: Status of the operation
        """
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
            else:
                host_mor = None
        if host_mor is None:
            raise Exception("Host not found on %s" % (client_object.name))
        pnic_spec = client_object.get_dvs_host_pnic_spec(
            pnic=pnic,
            uplink_portgroup=uplink_portgroup,
            uplink_port=uplink_port)
        backing = client_object.get_dvs_host_pnic_backing(pnic_spec)
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, backing=backing)
        dvs = client_object.get_dvs_config_spec()
        dvs.host = [host_member_config]
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def set_mtu(cls, client_object, mtu=None):
        """
        Sets the mtu for the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object; VDSwitchAPIClient instance
        @type mtu: int
        @param mtu: Maximum transmission unit for the switch

        @rtype: str
        @return: Status of the operation
        """
        vmware_dvs_spec = vim.dvs.VmwareDistributedVirtualSwitch.ConfigSpec()
        vds_mor = client_object.vds_mor
        vmware_dvs_spec.configVersion = vds_mor.config.configVersion
        vmware_dvs_spec.maxMtu = mtu
        task = client_object.vds_mor.ReconfigureDvs_Task(vmware_dvs_spec)
        return vc_soap_util.get_task_state(task)
    def set_mtu(cls, client_object, mtu=None):
        """
        Sets the mtu for the switch.

        @type client_object: VDSwitchAPIClient instance
        @param client_object; VDSwitchAPIClient instance
        @type mtu: int
        @param mtu: Maximum transmission unit for the switch

        @rtype: str
        @return: Status of the operation
        """
        vmware_dvs_spec = vim.dvs.VmwareDistributedVirtualSwitch.ConfigSpec()
        vds_mor = client_object.vds_mor
        vmware_dvs_spec.configVersion = vds_mor.config.configVersion
        vmware_dvs_spec.maxMtu = mtu
        task = client_object.vds_mor.ReconfigureDvs_Task(vmware_dvs_spec)
        return vc_soap_util.get_task_state(task)
Exemple #41
0
    def update_answer_file(cls, client_object, hostname=None,
                           datacenter=None, parameter_id=None,
                           policy_id=None, profile_path=None,
                           parameter_keys=None,
                           parameter_values=None):
        """
        Updates the answer file.

        @type client_object: ProfileAPIClient instance
        @param client_object: ProfileAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type datacenter: str
        @param datacenter: Datacenter name
        @type parameter_id: str
        @param parameter_id: Key for a parameter in the policy specified
            by policyId
        @type policy_id: str
        @param policy_id: Policy option identifier
        @type profile_path: str
        @param profile_path: Complete path to the leaf profile, relative to
            the root of the host profile document
        @type parameter_keys: list
        @param parameter_keys: keys of the parameter for the policy
        @type parameter_values: list
        @param parameter_values: Values corresponding to parameter_keys

        @rtype: str
        @return: Status of the operation
        """
        spec = client_object.get_answer_file_option_create(
            parameter_id=parameter_id, policy_id=policy_id,
            profile_path=profile_path,
            parameter_keys=parameter_keys,
            parameter_values=parameter_values)
        host_mor = client_object.parent.get_host_mor(
            hostname, datacenter)
        profile_mor = client_object.host_profile_manager_mor
        task = profile_mor.UpdateAnswerFile_Task(host_mor,
                                                 spec)
        return vc_soap_util.get_task_state(task)
    def configure_discovery_protocol(cls, client_object,
                                     mode=None, protocol=None):
        """
        Configures the discovery protocol on the switch.

        @type client_object: client instance
        @param client_object: VDSwitch client instance
        @type mode: str
        @param mode: Whether to advertise or listen
        @type protocol: str
        @param protocol: cdp or lldp

        @rtype: str
        @return: Status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        dvs.linkDiscoveryProtocolConfig = client_object.get_ldp_config_spec(
            mode=mode, protocol=protocol)
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def remove_vspan_session(cls, client_object, session_id=None):
        """
        Removes the specified mirror session.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type session_id: str
        @param session_id: ID of the mirrored session

        @rtype: str
        @return: Status of the operation
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        vspan_spec = vim.dvs.VmwareDistributedVirtualSwitch.VspanConfigSpec()
        vspan_session = vim.dvs.VmwareDistributedVirtualSwitch.VspanSession()
        vspan_session.key = session_id
        vspan_spec.vspanSession = vspan_session
        vspan_spec.operation = "remove"
        dvs.vspanConfigSpec = [vspan_spec]
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def edit_security_policy(cls,
                             client_object,
                             forged_transmits=None,
                             allow_promiscuous=None,
                             mac_changes=None):
        """
        Edits the security policy of the DVPortgroup

        @type client_object: DVPortgroupAPIClient instance
        @param client_object: DVPortgroupAPIClient instance
        @type forged_transmits: bool
        @param forged_transmits: The flag to indicate whether or not the
            virtual network adapter should be allowed to send network
            traffic with a different MAC address than that of the
            virtual network adapter.
        @type allow_promiscuous: bool
        @param allow_promiscuous: The flag to indicate whether or not all
            traffic is seen on the port
        @type mac_changes: bool
        @param mac_changes: The flag to indicate whether or not the
            Media Access Control (MAC) address can be changed.

        @rtype: str
        @return: Status of the operation
        """
        dvpg_mor = client_object.dvpg_mor
        dvpg_port_config = dvpg_mor.config.defaultPortConfig
        dvpg_port_config.securityPolicy = client_object.get_security_policy(
            forged_transmits=forged_transmits,
            mac_changes=mac_changes,
            allow_promiscuous=allow_promiscuous)
        dvpg_config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
        dvpg_config.defaultPortConfig = dvpg_port_config
        dvpg_config.configVersion = dvpg_mor.config.configVersion
        try:
            task = dvpg_mor.ReconfigureDVPortgroup_Task(dvpg_config)
            return vc_soap_util.get_task_state(task)
        except Exception as e:
            raise Exception("Could not edit security policy", e)
    def remove_vspan_session(cls, client_object, session_id=None):
        """
        Removes the specified mirror session.

        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type session_id: str
        @param session_id: ID of the mirrored session

        @rtype: str
        @return: Status of the operation
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        vspan_spec = vim.dvs.VmwareDistributedVirtualSwitch.VspanConfigSpec()
        vspan_session = vim.dvs.VmwareDistributedVirtualSwitch.VspanSession()
        vspan_session.key = session_id
        vspan_spec.vspanSession = vspan_session
        vspan_spec.operation = "remove"
        dvs.vspanConfigSpec = [vspan_spec]
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def bind_pnic(cls, client_object, pnic=None, hostname=None,
                  uplink_portgroup=None, uplink_port=None, operation=None):
        """
        @type client_object: VDSwitchAPIClient instance
        @param client_object: VDSwitchAPIClient instance
        @type pnic: str
        @param pnic: Name of the pnic
        @type hostname: str
        @param hostname: Host name
        @type uplink_portgroup: str
        @param uplink_portgroup: Uplink portgroup to bind to
        @type uplink_port: str
        @param uplink_port: Uplink port to bind to
        @type operation: str
        @param operation: add, remove, edit

        @rtype: str
        @return: Status of the operation
        """
        vds_mor = client_object.vds_mor
        for member in vds_mor.config.host:
            if member.config.host.name == hostname:
                host_mor = member.config.host
                break
            else:
                host_mor = None
        if host_mor is None:
            raise Exception("Host not found on %s" % (client_object.name))
        pnic_spec = client_object.get_dvs_host_pnic_spec(
            pnic=pnic, uplink_portgroup=uplink_portgroup,
            uplink_port=uplink_port)
        backing = client_object.get_dvs_host_pnic_backing(pnic_spec)
        host_member_config = client_object.get_host_member_config(
            host_mor=host_mor, backing=backing)
        dvs = client_object.get_dvs_config_spec()
        dvs.host = [host_member_config]
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
    def configure_discovery_protocol(cls,
                                     client_object,
                                     mode=None,
                                     protocol=None):
        """
        Configures the discovery protocol on the switch.

        @type client_object: client instance
        @param client_object: VDSwitch client instance
        @type mode: str
        @param mode: Whether to advertise or listen
        @type protocol: str
        @param protocol: cdp or lldp

        @rtype: str
        @return: Status of the operation.
        """
        dvs = client_object.get_vmware_dvs_config_spec()
        dvs.configVersion = client_object.vds_mor.config.configVersion
        dvs.linkDiscoveryProtocolConfig = client_object.get_ldp_config_spec(
            mode=mode, protocol=protocol)
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
Exemple #48
0
    def export_answer_file(cls, client_object, hostname=None,
                           datacenter=None):
        """
        Exports a host's answer file in a serialized form.

        @type client_object: ProfileAPIClient instance
        @param client_object: ProfileAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type datacenter: str
        @param datacenter: Datacemter name

        @rtype: str
        @return: Serialized form of the answer file
        """
        host_mor = client_object.parent.get_host_mor(
            hostname, datacenter)
        profile_mor = client_object.host_profile_manager_mor
        task = profile_mor.ExportAnswerFile_Task(host_mor)
        result = vc_soap_util.get_task_state(task)
        if result == constants.Result.SUCCESS.lower():
            return task.info.result
        else:
            pylogger.error("Could not successfully export answer file")
Exemple #49
0
    def import_answer_file(cls, client_object, hostname=None,
                           datacenter=None, answer_file=None):
        """
        Imports the answer file to the host.

        @type client_object: ProfileAPIClient instance
        @param client_object: ProfileAPIClient instance
        @type hostname: str
        @param hostname: Hostname
        @type datacenter: str
        @param datacenter: Datacenter name
        @type answer_file: str
        @param answer_file: Serialized answer file to be imported

        @rtype: str
        @return: Status of the operation
        """
        host_mor = client_object.parent.get_host_mor(
            hostname, datacenter)
        profile_mor = client_object.host_profile_manager_mor
        spec = vim.profile.host.ProfileManager.AnswerFileSerializedCreateSpec()
        spec.answerFileConfigString = answer_file
        task = profile_mor.UpdateAnswerFile_Task(host_mor, spec)
        return vc_soap_util.get_task_state(task)
    def configure_mirror_session(cls, client_object, description=None,
                                 enabled=None, encap_vlan_id=None,
                                 session_id=None, mirrored_packet_length=None,
                                 name=None, normal_traffic_allowed=None,
                                 sampling_rate=None, session_type=None,
                                 strip_original_vlan=None, dest_ip=None,
                                 dest_port_key=None, dest_vlans=None,
                                 dest_uplink_port_name=None,
                                 dest_wildcard_port_connected_type=None,
                                 src_ip_rx=None, src_port_key_rx=None,
                                 src_uplink_port_name_rx=None,
                                 src_vlans_rx=None,
                                 src_wildcard_port_connected_type_rx=None,
                                 src_ip_tx=None, src_port_key_tx=None,
                                 src_uplink_port_name_tx=None,
                                 src_vlans_tx=None, operation=None,
                                 src_wildcard_port_connected_type_tx=None):
        """
        Configures mirror session on the switch.

        @type client_object: client instance
        @param client_object: VDSwitch client instance
        @type description: str
        @param description: Description of the session
        @type enabled: bool
        @param enabled: Flag to specify if session is enabled
        @type encap_vlan_id: int
        @param encap_vlan_id: VLAN ID used to encapsulate mirrored traffic
        @type session_id: str
        @param session_id: Identifier of the session
        @type mirrored_packet_length: int
        @param mirrored_packet_length: Size of each frame to mirror
        @type name: str
        @param name: Display name of the session
        @type normal_traffic_allowed: bool
        @param normal_traffic_allowed: Flag to specify if destination ports
            can send and receive normal traffic.
        @type sampling_rate: int
        @param sampling_rate: Sampling rate of the session
        @type session_type: str
        @param session_type: Type of the session
        @type strip_original_vlan: bool
        @param strip_original_vlan: Flag to specifiy if original VLAN tag is
            to be stripped.
        @type dest_ip: list
        @param dest_ip: IP address for the destination of encapsulated remote
            mirror source session
        @type dest_port_key: list
        @param dest_port_key: Individual ports to participate in the
            Distributed Port Mirroring session
        @type dest_vlans: list
        @param dest_vlans: Vlan Ids for ingress source of Remote Mirror
            destination session
        @type dest_uplink_port_name: list
        @param dest_uplink_port_name: Uplink ports used as destination ports
            to participate in the Distributed Port Mirroring session
        @type dest_wildcard_port_connected_type: list
        @param dest_wildcard_port_connected_type: Wild card specification
            for source ports participating in the Distributed Port Mirroring
            session
        @type src_ip_rx: list
        @param src_ip_rx: IP address for the destination of encapsulated
            remote mirror source session
        @type src_port_key_rx: list
        @param src_port_key_rx: Individual ports to participate in the
            Distributed Port Mirroring session
        @type src_uplink_port_name_rx: list
        @param src_uplink_port_name_rx: Uplink ports used as destination
            ports to participate in the Distributed Port Mirroring session
        @type src_vlans_rx: list
        @param src_vlans_rx: Vlan Ids for ingress source of Remote Mirror
            destination session
        @type src_wildcard_port_connected_type_rx: list
        @param src_wildcard_port_connected_type_rx: Wild card specification
            for source ports participating in the Distributed Port Mirroring
            session
        @type src_ip_tx: list
        @param src_ip_tx: IP address for the destination of encapsulated
            remote mirror source session
        @type src_port_key_tx: list
        @param src_port_key_tx: Individual ports to participate in the
        Distributed Port Mirroring session
        @type src_uplink_port_name_tx: list
        @param src_uplink_port_name_tx: Uplink ports used as destination ports
            to participate in the Distributed Port Mirroring session
        @type src_vlans_tx: list
        @param src_vlans_tx: Vlan Ids for ingress source of Remote Mirror
            destination session
        @type src_wildcard_port_connected_type_tx: list
        param src_wildcard_port_connected_type_tx: Wild card specification for
            source ports participating in the Distributed Port Mirroring
            session

        @rtype: str
        @return: Status of the operation.
        """
        param = cls._args_filter(locals())
        dvs = client_object.get_vmware_dvs_config_spec(**param)
        dvs.configVersion = client_object.vds_mor.config.configVersion
        task = client_object.vds_mor.ReconfigureDvs_Task(dvs)
        return vc_soap_util.get_task_state(task)
Exemple #51
0
    def configure_pci_passthrough(cls,
                                  client_object,
                                  key=None,
                                  device=None,
                                  controller_key=None,
                                  operation=None):
        """
        Adds or removes a pci passthrough for the VM.

        @type client_object: VMAPIClient instance
        @param client_object: VMAPIClient instance
        @type key: int
        @param key: A unique key that distinguishes this device from
            other devices in the same virtual machine.
        @type device: str
        @param device: Name of pnic, eg vmnic0
        @type controller_key: str
        @param controller_key: Object key for the controller object for this
            device. This property contains the key property value of the
            controller device object.
        @type operation: str
        @param operation: add or remove

        @rtype: str
        @param: Status of the operation
        """
        host_mor = client_object.parent.get_host_mor()
        network_sys = host_mor.configManager.networkSystem
        backing_spec = vim.vm.device.VirtualPCIPassthrough.DeviceBackingInfo()
        for pnic in network_sys.networkInfo.pnic:
            if pnic.device == device:
                pci = pnic.pci
                for pci_device in host_mor.hardware.pciDevice:
                    if pci_device.id == pci:
                        vm_mor = client_object.get_api()
                        config_spec = vim.vm.ConfigSpec()
                        device_spec = vim.vm.device.VirtualDeviceSpec()
                        device_spec.operation = operation
                        passthru = vim.vm.device.VirtualPCIPassthrough()
                        if operation == ADD:
                            backing_spec.deviceId = str(pci_device.deviceId)
                            backing_spec.id = pci
                            backing_spec.vendorId = pci_device.vendorId
                            uuid = host_mor.hardware.systemId.uuid
                            backing_spec.systemId = uuid
                            passthru.backing = backing_spec
                            passthru.controllerKey = controller_key
                            passthru.key = key
                            device_spec.device = passthru
                            config_spec.deviceChange = [device_spec]
                        elif operation == REMOVE:
                            passthru.key = key
                            device_spec.device = passthru
                            config_spec.deviceChange = [device_spec]
                        else:
                            raise Exception("Specifiy operation type")
                        try:
                            return vc_soap_util.get_task_state(
                                vm_mor.ReconfigVM_Task(config_spec))
                        except Exception as e:
                            raise Exception("Could not add passthrough", e)
        pylogger.error("Could not find %r" % device)