- def get_nic_details(self):
- nic_details = {}
- nic_details = {
- 'interface': {},
- 'pci': self.sriov[0]['phy_ports'],
- 'phy_driver': self.sriov[0]['phy_driver'],
- 'vf_macs': self.sriov[0]['vf_macs']
- }
- # Make sure that ports are bound to kernel drivers e.g. i40e/ixgbe
- for i, _ in enumerate(nic_details['pci']):
- err, out, _ = self.connection.execute(
- "{dpdk_nic_bind} --force -b {driver} {port}".format(
- dpdk_nic_bind=self.dpdk_nic_bind,
- driver=self.sriov[0]['phy_driver'],
- port=self.sriov[0]['phy_ports'][i]))
- err, out, _ = self.connection.execute(
- "lshw -c network -businfo | grep '{port}'".format(
- port=self.sriov[0]['phy_ports'][i]))
- a = out.split()[1]
- err, out, _ = self.connection.execute(
- "ip -s link show {interface}".format(
- interface=out.split()[1]))
- nic_details['interface'][i] = str(a)
- log.info("{0}".format(nic_details))
- return nic_details
-
- def install_req_libs(self):
- if self.first_run:
- log.info("Installing required libraries...")
- err, out, _ = self.connection.execute("apt-get update")
- log.debug("{0}".format(out))
- err, out, _ = self.connection.execute(
- "apt-get -y install qemu-kvm libvirt-bin")
- log.debug("{0}".format(out))
- err, out, _ = self.connection.execute(
- "apt-get -y install libvirt-dev bridge-utils numactl")
- log.debug("{0}".format(out))
- self.first_run = False
-
- def configure_nics_for_sriov(self, host_driver, nic_details):
- vf_pci = [[], []]
- self.connection.execute(
- "rmmod {0}".format(host_driver))[1].splitlines()
- self.connection.execute(
- "modprobe {0} num_vfs=1".format(host_driver))[1].splitlines()
- nic_details['vf_pci'] = {}
- for i in range(len(nic_details['pci'])):
- self.connection.execute(
- "echo 1 > /sys/bus/pci/devices/{0}/sriov_numvfs".format(
- nic_details['pci'][i]))
- err, out, _ = self.connection.execute(
- "ip link set {interface} vf 0 mac {mac}".format(
- interface=nic_details['interface'][i],
- mac=nic_details['vf_macs'][i]))
- time.sleep(3)
- vf_pci[i] = self.get_vf_datas(
- 'vf_pci',
- nic_details['pci'][i],
- nic_details['vf_macs'][i])
- nic_details['vf_pci'][i] = vf_pci[i]
- log.debug("NIC DETAILS : {0}".format(nic_details))
- return nic_details
-
- def setup_sriov_context(self, pcis, nic_details, host_driver):
- blacklist = "/etc/modprobe.d/blacklist.conf"
-
- # 1 : Blacklist the vf driver in /etc/modprobe.d/blacklist.conf
- vfnic = "{0}vf".format(host_driver)
- lines = self.read_from_file(blacklist)
- if vfnic not in lines:
- vfblacklist = "blacklist {vfnic}".format(vfnic=vfnic)
- self.connection.execute(
- "echo {vfblacklist} >> {blacklist}".format(
- vfblacklist=vfblacklist,
- blacklist=blacklist))
-
- # 2 : modprobe host_driver with num_vfs
- nic_details = self.configure_nics_for_sriov(host_driver, nic_details)
-
- # 3: Setup vm_sriov.xml to launch VM
- cfg_sriov = '/tmp/vm_sriov.xml'
- mac = [0x00, 0x24, 0x81,
- random.randint(0x00, 0x7f),
- random.randint(0x00, 0xff),
- random.randint(0x00, 0xff)]
- mac_address = ':'.join(map(lambda x: "%02x" % x, mac))
- vm_sriov_xml = VM_TEMPLATE.format(
- random_uuid=uuid.uuid4(),
- mac_addr=mac_address,
- vm_image=self.sriov[0]["images"])
- with open(cfg_sriov, 'w') as f:
- f.write(vm_sriov_xml)
-
- vf = nic_details['vf_pci']
- for index in range(len(nic_details['vf_pci'])):
- self.add_sriov_interface(
- index,
- vf[index]['vf_pci'],
- mac_address,
- "/tmp/vm_sriov.xml")
- self.connection.execute(
- "ifconfig {interface} up".format(
- interface=nic_details['interface'][index]))
-
- # 4: Create and start the VM
- self.connection.put(cfg_sriov, cfg_sriov)
- time.sleep(10)
- err, out = self.check_output("virsh list --name | grep -i vm1")
+ # Todo: NFVi deploy (sriov, vswitch, ovs etc) based on the config.
+ StandaloneContextHelper.install_req_libs(self.connection)
+ self.networks = StandaloneContextHelper.get_nic_details(self.connection,
+ self.networks,
+ self.dpdk_nic_bind)
+ self.nodes = self.setup_sriov_context()
+
+ LOG.debug("Waiting for VM to come up...")
+ self.nodes = StandaloneContextHelper.wait_for_vnfs_to_start(self.connection,
+ self.servers,
+ self.nodes)
+
+ def undeploy(self):
+ """don't need to undeploy"""
+
+ if not self.vm_deploy:
+ return
+
+ # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config.
+ for vm in self.vm_names:
+ Libvirt.check_if_vm_exists_and_delete(vm, self.connection)
+
+ # Bind nics back to kernel
+ for ports in self.networks.values():
+ # enable VFs for given...
+ build_vfs = "echo 0 > /sys/bus/pci/devices/{0}/sriov_numvfs"
+ self.connection.execute(build_vfs.format(ports.get('phy_port')))
+
+ def _get_server(self, attr_name):
+ """lookup server info by name from context
+
+ Keyword arguments:
+ attr_name -- A name for a server listed in nodes config file
+ """
+ node_name, name = self.split_name(attr_name)
+ if name is None or self.name != name:
+ return None
+
+ matching_nodes = (n for n in self.nodes if n["name"] == node_name)