Exemplo n.º 1
0
 def create_hostdev_interface(pci_id, managed, model):
     """
         Create hostdev type interface xml.
     """
     attrs = create_address_dict(pci_id)
     new_iface = Interface('hostdev')
     new_iface.managed = managed
     if model != "":
         new_iface.model = model
     new_iface.mac_address = utils_net.generate_mac_address_simple()
     new_iface.hostdev_address = new_iface.new_iface_address(**{"attrs": attrs})
     chars = string.ascii_letters + string.digits + '-_'
     alias_name = 'ua-' + ''.join(random.choice(chars) for _ in list(range(64)))
     new_iface.alias = {'name': alias_name}
     return new_iface
Exemplo n.º 2
0
    def create_iface(iface_model, iface_source, **kwargs):
        """
        Create an interface to be attached to vm

        :param iface_model: model of the interface device
        :param iface_source: source of the interface device
        :param kwargs: other k-w args that needed to create device
        :return: the newly created interface object
        """
        iface = Interface('network')
        iface.model = iface_model
        iface.source = eval(iface_source)

        if 'mac' in kwargs:
            iface.mac_address = kwargs['mac']
        else:
            mac = utils_net.generate_mac_address_simple()
            iface.mac_address = mac

        if 'address' in kwargs:
            iface.address = iface.new_iface_address(attrs=eval(kwargs['address']))

        logging.debug('iface: %s', iface)
        return iface