当前位置: 首页>>代码示例>>Python>>正文


Python vim.Network方法代码示例

本文整理汇总了Python中pyVmomi.vim.Network方法的典型用法代码示例。如果您正苦于以下问题:Python vim.Network方法的具体用法?Python vim.Network怎么用?Python vim.Network使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyVmomi.vim的用法示例。


在下文中一共展示了vim.Network方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list_networks

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def list_networks(self):
        si = self.si
        rootFolder = si.content.rootFolder
        networks = {}
        view = si.content.viewManager.CreateContainerView(rootFolder, [vim.dvs.DistributedVirtualPortgroup], True)
        dvslist = collectproperties(si, view=view, objtype=vim.dvs.DistributedVirtualPortgroup, pathset=['name'],
                                    includemors=True)
        view = si.content.viewManager.CreateContainerView(rootFolder, [vim.Network], True)
        netlist = collectproperties(si, view=view, objtype=vim.Network, pathset=['name'], includemors=True)
        for o in netlist:
            network = o['obj']
            cidr, dhcp, domainname = '', '', ''
            mode = 'accesible' if network.summary.accessible else 'notaccessible'
            networks[network.name] = {'cidr': cidr, 'dhcp': dhcp, 'domain': domainname, 'type': 'routed', 'mode': mode}
        for o in dvslist:
            network = o['obj']
            cidr, dhcp, domainname, mode = '', '', '', ''
            networks[network.name] = {'cidr': cidr, 'dhcp': dhcp, 'domain': domainname, 'type': 'routed', 'mode': mode}
        return networks 
开发者ID:karmab,项目名称:kcli,代码行数:21,代码来源:__init__.py

示例2: get_network

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_network(self, network_name, distributed=False):
        """
        Finds and returns the named Network.

        :param str network_name: Name or path of the Network
        :param bool distributed: If the Network is a Distributed PortGroup
        :return: The network found
        :rtype: vim.Network or vim.dvs.DistributedVirtualPortgroup or None
        """
        if not distributed:
            return self.get_obj(container=self.datacenter.networkFolder,
                                vimtypes=[vim.Network],
                                name=str(network_name), recursive=True)
        else:
            return self.get_item(vim.dvs.DistributedVirtualPortgroup,
                                 network_name) 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:18,代码来源:vsphere_class.py

示例3: add_nic

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def add_nic(self, name, network):
        if network == 'default':
            network = 'VM Network'
        si = self.si
        dc = self.dc
        vmFolder = dc.vmFolder
        vm = findvm(si, vmFolder, name)
        if vm is None:
            return {'result': 'failure', 'reason': "VM %s not found" % name}
        spec = vim.vm.ConfigSpec()
        nicnumber = len([dev for dev in vm.config.hardware.device if "addressType" in dir(dev)])
        nicname = 'Network adapter %d' % (nicnumber + 1)
        nicspec = createnicspec(nicname, network)
        nic_changes = [nicspec]
        spec.deviceChange = nic_changes
        t = vm.ReconfigVM_Task(spec=spec)
        waitForMe(t)
        return {'result': 'success'} 
开发者ID:karmab,项目名称:kcli,代码行数:20,代码来源:__init__.py

示例4: get_network

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_network(self, network):
        if network not in self.networks:
            self.networks[network] = self.find_obj(self.content, [vim.Network], network)

        return self.networks[network] 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:7,代码来源:vmware_guest2.py

示例5: gen_nic

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def gen_nic(num, network):
        """
        Get a nic for the specified network
        """
        nic = vim.vm.device.VirtualDeviceSpec()
        nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add  # or edit if a device exists
        nic.device = vim.vm.device.VirtualVmxnet3()
        nic.device.wakeOnLanEnabled = True
        nic.device.addressType = 'assigned'
        nic.device.key = 4000  # 4000 seems to be the value to use for a vmxnet3 device
        nic.device.deviceInfo = vim.Description()
        nic.device.deviceInfo.label = "Network Adapter %d" % num
        nic.device.deviceInfo.summary = "Net summary"
        nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
        nic.device.backing.network = network
        nic.device.backing.deviceName = "Device%d" % num
        nic.device.backing.useAutoDetect = False
        nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
        nic.device.connectable.startConnected = True
        nic.device.connectable.allowGuestControl = True

        return nic 
开发者ID:grycap,项目名称:im,代码行数:24,代码来源:vSphere.py

示例6: remove_nic

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def remove_nic(self, nic_number):
        """Deletes a vNIC based on it's number.
        :param int nic_number: Number of the vNIC to delete
        :return: If removal succeeded
        :rtype: bool
        """
        nic_label = "Network adapter " + str(nic_number)
        self._log.debug("Removing Virtual %s from '%s'", nic_label, self.name)
        virtual_nic_device = self.get_nic_by_name(nic_label)
        if virtual_nic_device is not None:
            virtual_nic_spec = vim.vm.device.VirtualDeviceSpec()
            virtual_nic_spec.operation = \
                vim.vm.device.VirtualDeviceSpec.Operation.remove
            virtual_nic_spec.device = virtual_nic_device

            # Apply change to VM
            self._edit(vim.vm.ConfigSpec(deviceChange=[virtual_nic_spec]))
            return True
        else:
            self._log.error("Virtual %s could not be found for '%s'",
                            nic_label, self.name)
            return False 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:24,代码来源:vm.py

示例7: get_net_item

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_net_item(self, object_type, name):
        """
        Retrieves a network object of the specified type and name from a host.

        :param str object_type: Type of object to get:
        (portgroup | vswitch | proxyswitch | vnic | pnic)
        :param str name: Name of network object [default: first object found]
        :return: The network object
        :rtype: vim.Network or vim.VirtualSwitch
        or vim.VirtualEthernetCard or None
        .. todo:: determine what possible return types there are
        """
        if name:
            return self.get_net_obj(object_type, name)
        else:
            return self.get_net_objs(object_type)[0] 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:18,代码来源:host.py

示例8: find_object_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def find_object_by_name(module,content, object_name):
    try:
    	if(object_name == module.params['datacenter']):
    	    vmware_objects = get_all_objs(module,content,[vim.Datacenter])
    	elif (object_name == module.params['cluster']):
    	    vmware_objects = get_all_objs(module,content,[vim.ComputeResource])
    	elif (object_name == module.params['datastore']):
            vmware_objects = get_all_objs(module,content,[vim.Datastore])
    	elif (object_name == module.params['portgroup1'] or module.params['portgroup2'] or module.params['portgroup3'] ):
            vmware_objects = get_all_objs(module,content,[vim.dvs.DistributedVirtualPortgroup, vim.Network])
 
    	for object in vmware_objects:
            if object.name == object_name:
            	logger.info('object: %s',object.name)
            	return object
    	return None
    except Exception as err:
       module.fail_json(changed=False, msg= "Error Occured while Finding the Object by name. Error is %s" %(to_native(err))) 
开发者ID:vmware-archive,项目名称:ansible-module-chaperone,代码行数:20,代码来源:nsxt_vcenter_moids.py

示例9: find_network_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def find_network_by_name(content, network_name):
    return find_object_by_name(content, network_name, [vim.Network]) 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:4,代码来源:vmware.py

示例10: get_all_host_objs

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_all_host_objs(self, cluster_name=None, esxi_host_name=None):
        """
        Function to get all host system managed object

        Args:
            cluster_name: Name of Cluster
            esxi_host_name: Name of ESXi server

        Returns: A list of all host system managed objects, else empty list

        """
        host_obj_list = []
        if not self.is_vcenter():
            hosts = get_all_objs(self.content, [vim.HostSystem]).keys()
            if hosts:
                host_obj_list.append(list(hosts)[0])
        else:
            if cluster_name:
                cluster_obj = self.find_cluster_by_name(cluster_name=cluster_name)
                if cluster_obj:
                    host_obj_list = [host for host in cluster_obj.host]
                else:
                    self.module.fail_json(changed=False, msg="Cluster '%s' not found" % cluster_name)
            elif esxi_host_name:
                if isinstance(esxi_host_name, str):
                    esxi_host_name = [esxi_host_name]

                for host in esxi_host_name:
                    esxi_host_obj = self.find_hostsystem_by_name(host_name=host)
                    if esxi_host_obj:
                        host_obj_list = [esxi_host_obj]
                    else:
                        self.module.fail_json(changed=False, msg="ESXi '%s' not found" % host)

        return host_obj_list

    # Network related functions 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:39,代码来源:vmware.py

示例11: get_networks

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_networks(content, datacenter):
        """
        Returns all metworks
        """
        nets = {}
        poolmgr = vim.IpPoolManager()
        ippools = poolmgr.QueryIpPools(datacenter)
        container = content.viewManager.CreateContainerView(content.rootFolder, [vim.Network], True)
        for c in container.view:
            is_public = None
            for ippool in ippools:
                if c.summary.ipPoolName == ippool.name:
                    is_public = not any([IPAddress(ippool.ipv4Config.subnetAddress) in IPNetwork(
                        mask) for mask in Config.PRIVATE_NET_MASKS])
                    break

            nets[c.name] = (c, is_public, ippool.ipv4Config)

        return nets 
开发者ID:grycap,项目名称:im,代码行数:21,代码来源:vSphere.py

示例12: CreateContainerView

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def CreateContainerView(self, rootFolder, type_list, flag):
        container = MagicMock()
        c = MagicMock()
        container.view = [c]
        if type_list[0] == vim.Datastore:
            c.name = "datastore"
        elif type_list[0] == vim.Network:
            c.name = "vsnet1"
            c.summary.ipPoolName = "ippool1"
            c2 = MagicMock()
            c2.name = "vsnet2"
            c2.summary.ipPoolName = "ippool2"
            container.view.append(c2)
        elif type_list[0] == vim.VirtualMachine:
            c.name = "vm-template"
            c.Clone.return_value = vim.Task("CreateVM")
            c.Suspend.return_value = vim.Task("SuspendVM")
            c.PowerOn.return_value = vim.Task("PowerOnVM")
            c.Reset.return_value = vim.Task("ResetVM")
            c.PowerOff.return_value = vim.Task("PowerOffVM")
            c.Destroy.return_value = vim.Task("DestroyVM")
            c.summary.runtime.powerState = self.vm_state
            c.runtime.powerState = self.vm_state
            nic1 = MagicMock()
            nic1.ipAddress = "10.0.0.1"
            nic2 = MagicMock()
            nic2.ipAddress = "8.8.8.8"
            c.guest.net = [nic1, nic2]
            dev1 = MagicMock()
            dev2 = vim.vm.device.VirtualSCSIController()
            c.config.hardware.device = [dev1, dev2]
            dev1.backing.fileName = ""
            dev1.unitNumber = 1
        else:
            raise Exception("Invalid type")

        return container 
开发者ID:grycap,项目名称:im,代码行数:39,代码来源:vSphere.py

示例13: detect_stdportgroup

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def detect_stdportgroup(context, host_name, network_name):
    """Find Distributed Switch based on host and network name"""
    # Ensure the standard switch is available on the host
    names = set([host_name])

    # Use vAPI find the Host managed identities
    host_summaries = context.client.vcenter.Host.list(
        Host.FilterSpec(names=names))

    for host_summary in host_summaries:
        # Convert the host identifier into a ManagedObject
        host = host_summary.host
        host_mo = vim.HostSystem(host, context.soap_stub)

        for network_mo in host_mo.network:
            if (type(network_mo) == vim.Network and
                        network_mo.name == network_name):
                network = network_mo._moId
                print(
                    "Detected Standard Portgroup '{}' as {} on Host '{}' ({})".
                    format(network_name, network, host_name, host))
                context.testbed.entities['HOST_STANDARD_SWITCH_IDS'][
                    host_name] = network
                return True

    print("Standard Portgroup '{}' missing on Host '{}'".
          format(network_name, host_name))
    return False 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:30,代码来源:network.py

示例14: list_networks

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def list_networks(self):
        """Fetch the list of network names

        Returns: A list of Network names
        """
        return [str(h.name) for h in self.get_obj_list(vim.Network)] 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:8,代码来源:virtualcenter.py

示例15: get_network

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Network [as 别名]
def get_network(self, network_name):
        """Fetch the network object from specified network name

        Args:
            network_name: The name of the network from Vmware
        Returns: A object of vim.Network object
        """
        network = self.get_obj(vimtype=vim.Network, name=network_name)
        if not network:
            raise NotFoundError
        return network 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:13,代码来源:virtualcenter.py


注:本文中的pyVmomi.vim.Network方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。