Esempio n. 1
0
    def define(self):
        name = underscored(
            deepgetattr(self, 'node.group.environment.name'),
            deepgetattr(self, 'node.name'),
            self.name,
        )

        backing_store_path = None
        backing_store_format = None
        if self.backing_store is not None:
            backing_store_path = self.backing_store.get_path()
            backing_store_format = self.backing_store.format

        if self.source_image is not None:
            capacity = get_file_size(self.source_image)
        else:
            capacity = int(self.capacity * 1024 ** 3)

        pool_name = self.driver.storage_pool_name
        pool = self.driver.conn.storagePoolLookupByName(pool_name)
        xml = LibvirtXMLBuilder.build_volume_xml(
            name=name,
            capacity=capacity,
            vol_format=self.format,
            backing_store_path=backing_store_path,
            backing_store_format=backing_store_format,
        )
        libvirt_volume = pool.createXML(xml, 0)
        self.uuid = libvirt_volume.key()
        super(LibvirtVolume, self).define()

        # Upload predefined image to the volume
        if self.source_image is not None:
            self.upload(self.source_image)
Esempio n. 2
0
    def define(self):
        name = underscored(
            deepgetattr(self, 'node.group.environment.name'),
            deepgetattr(self, 'node.name'),
            self.name,
        )

        backing_store_path = None
        backing_store_format = None
        if self.backing_store is not None:
            backing_store_path = self.backing_store.get_path()
            backing_store_format = self.backing_store.format

        if self.source_image is not None:
            capacity = get_file_size(self.source_image)
        else:
            capacity = int(self.capacity * 1024**3)

        pool_name = self.driver.storage_pool_name
        pool = self.driver.conn.storagePoolLookupByName(pool_name)
        xml = LibvirtXMLBuilder.build_volume_xml(
            name=name,
            capacity=capacity,
            vol_format=self.format,
            backing_store_path=backing_store_path,
            backing_store_format=backing_store_format,
        )
        libvirt_volume = pool.createXML(xml, 0)
        self.uuid = libvirt_volume.key()
        super(LibvirtVolume, self).define()

        # Upload predefined image to the volume
        if self.source_image is not None:
            self.upload(self.source_image)
Esempio n. 3
0
    def network_name(self):
        """Get network name

        :rtype : String
        """
        return underscored(deepgetattr(self, 'group.environment.name'),
                           self.name)
Esempio n. 4
0
    def define(self):
        network_name = underscored(
            deepgetattr(self, 'group.environment.name'),
            self.name,
        )

        bridge_name = 'virbr{0}'.format(self.id)

        # TODO(ddmitriev): check if 'vlan' package installed
        # Define tagged interfaces on the bridge
        for vlanid in self.vlan_ifaces:
            self.iface_define(name=bridge_name, vlanid=vlanid)

        # Define libvirt network
        ip_network_address = None
        ip_network_prefixlen = None
        dhcp_range_start = None
        dhcp_range_end = None
        addresses = []
        if self.address_pool is not None:
            # Reserved names 'l2_network_device' and 'dhcp'
            ip_network_address = self.address_pool.get_ip('l2_network_device')

            # Workaround for fuel-qa compatibility, if 'l2_network_device'
            # address was not reserved in the YAML template
            if not ip_network_address:
                ip_network_address = str(self.address_pool.ip_network[1])

            ip_network_prefixlen = str(self.address_pool.ip_network.prefixlen)
            dhcp_range_start = self.address_pool.ip_range_start('dhcp')
            dhcp_range_end = self.address_pool.ip_range_end('dhcp')

            for interface in self.interfaces:
                for address in interface.addresses:
                    ip_addr = netaddr.IPAddress(address.ip_address)
                    if ip_addr in self.address_pool.ip_network:
                        addresses.append(
                            dict(mac=str(interface.mac_address),
                                 ip=str(address.ip_address),
                                 name=interface.node.name))

        xml = LibvirtXMLBuilder.build_network_xml(
            network_name=network_name,
            bridge_name=bridge_name,
            addresses=addresses,
            forward=self.forward.mode,
            ip_network_address=ip_network_address,
            ip_network_prefixlen=ip_network_prefixlen,
            dhcp_range_start=dhcp_range_start,
            dhcp_range_end=dhcp_range_end,
            stp=self.driver.stp,
            has_pxe_server=self.has_pxe_server,
            has_dhcp_server=self.has_dhcp_server,
            tftp_root_dir=self.tftp_root_dir,
        )
        ret = self.driver.conn.networkDefineXML(xml)
        ret.setAutostart(True)
        self.uuid = ret.UUIDString()

        super(L2NetworkDevice, self).define()
Esempio n. 5
0
    def network_name(self):
        """Get network name

        :rtype : String
        """
        return underscored(
            deepgetattr(self, 'group.environment.name'),
            self.name)
Esempio n. 6
0
    def add_address(self):
        """Assign an IP address to the interface

        Try to get an IP from reserved IP with name '<group>_<node>'
        , or generate next IP if reserved IP wasn't found.
        Next IP is generated from the DHCP ip_range, or from the
        network range [+2:-2] of all available addresses in the address pool.
        """
        reserved_ip_name = helpers.underscored(self.node.group.name,
                                               self.node.name)
        reserved_ip = self.l2_network_device.address_pool.get_ip(
            reserved_ip_name)
        ip = reserved_ip or self.l2_network_device.address_pool.next_ip()
        Address.objects.create(
            ip_address=str(ip),
            interface=self,
        )
Esempio n. 7
0
    def define(self):
        """Define node

            :rtype : None
        """
        name = underscored(
            deepgetattr(self, 'group.environment.name'),
            self.name,
        )

        local_disk_devices = []
        for disk in self.disk_devices:
            local_disk_devices.append(dict(
                disk_type=disk.type,
                disk_device=disk.device,
                disk_volume_format=disk.volume.format,
                disk_volume_path=disk.volume.get_path(),
                disk_bus=disk.bus,
                disk_target_dev=disk.target_dev,
                disk_serial=uuid.uuid4().hex,
            ))

        local_interfaces = []
        for interface in self.interfaces:
            if interface.type != 'network':
                raise NotImplementedError(
                    message='Interface types different from network are not '
                            'implemented yet')

            l2_dev = interface.l2_network_device
            filter_name = underscored(
                deepgetattr(self, 'group.environment.name'),
                l2_dev.name,
                interface.mac_address
            )
            target_dev = self.driver.get_available_device_name('virnet')
            local_interfaces.append(dict(
                interface_type=interface.type,
                interface_mac_address=interface.mac_address,
                interface_network_name=l2_dev.network_name,
                interface_target_dev=target_dev,
                interface_model=interface.model,
                interface_filter=filter_name,
            ))

        emulator = self.driver.get_capabilities().find(
            'guest/arch[@name="{0:>s}"]/'
            'domain[@type="{1:>s}"]/emulator'.format(
                self.architecture, self.hypervisor)).text
        node_xml = LibvirtXMLBuilder.build_node_xml(
            name=name,
            hypervisor=self.hypervisor,
            use_host_cpu=self.driver.use_host_cpu,
            vcpu=self.vcpu,
            memory=self.memory,
            use_hugepages=self.driver.use_hugepages,
            hpet=self.driver.hpet,
            os_type=self.os_type,
            architecture=self.architecture,
            boot=self.boot,
            reboot_timeout=self.driver.reboot_timeout,
            bootmenu_timeout=self.bootmenu_timeout,
            emulator=emulator,
            has_vnc=self.has_vnc,
            vnc_password=self.driver.vnc_password,
            local_disk_devices=local_disk_devices,
            interfaces=local_interfaces,
            acpi=self.driver.enable_acpi,
            numa=self.numa,
        )
        logger.debug(node_xml)
        self.uuid = self.driver.conn.defineXML(node_xml).UUIDString()

        super(LibvirtNode, self).define()
Esempio n. 8
0
 def nwfilter_name(self):
     return underscored(
         self.node.group.environment.name,
         self.l2_network_device.name,
         self.mac_address)
Esempio n. 9
0
 def test_underscored(self):
     result = helpers.underscored('single')
     self.assertEqual(result, 'single')
     result = helpers.underscored('m', 'u', 'l', 't', 'i', 'p', 'l', 'e')
     self.assertEqual(result, 'm_u_l_t_i_p_l_e')
Esempio n. 10
0
    def define(self):
        """Define node

            :rtype : None
        """
        name = underscored(
            deepgetattr(self, 'group.environment.name'),
            self.name,
        )

        local_disk_devices = []
        for disk in self.disk_devices:
            local_disk_devices.append(
                dict(
                    disk_type=disk.type,
                    disk_device=disk.device,
                    disk_volume_format=disk.volume.format,
                    disk_volume_path=disk.volume.get_path(),
                    disk_bus=disk.bus,
                    disk_target_dev=disk.target_dev,
                    disk_serial=uuid.uuid4().hex,
                ))

        local_interfaces = []
        for interface in self.interfaces:
            if interface.type != 'network':
                raise NotImplementedError(
                    message='Interface types different from network are not '
                    'implemented yet')

            l2_dev = interface.l2_network_device
            filter_name = underscored(
                deepgetattr(self, 'group.environment.name'), l2_dev.name,
                interface.mac_address)
            target_dev = self.driver.get_available_device_name('virnet')
            local_interfaces.append(
                dict(
                    interface_type=interface.type,
                    interface_mac_address=interface.mac_address,
                    interface_network_name=l2_dev.network_name,
                    interface_target_dev=target_dev,
                    interface_model=interface.model,
                    interface_filter=filter_name,
                ))

        emulator = self.driver.get_capabilities().find(
            'guest/arch[@name="{0:>s}"]/'
            'domain[@type="{1:>s}"]/emulator'.format(self.architecture,
                                                     self.hypervisor)).text
        node_xml = LibvirtXMLBuilder.build_node_xml(
            name=name,
            hypervisor=self.hypervisor,
            use_host_cpu=self.driver.use_host_cpu,
            vcpu=self.vcpu,
            memory=self.memory,
            use_hugepages=self.driver.use_hugepages,
            hpet=self.driver.hpet,
            os_type=self.os_type,
            architecture=self.architecture,
            boot=self.boot,
            reboot_timeout=self.driver.reboot_timeout,
            bootmenu_timeout=self.bootmenu_timeout,
            emulator=emulator,
            has_vnc=self.has_vnc,
            vnc_password=self.driver.vnc_password,
            local_disk_devices=local_disk_devices,
            interfaces=local_interfaces,
            acpi=self.driver.enable_acpi,
            numa=self.numa,
        )
        logger.debug(node_xml)
        self.uuid = self.driver.conn.defineXML(node_xml).UUIDString()

        super(LibvirtNode, self).define()
Esempio n. 11
0
 def nwfilter_name(self):
     return underscored(self.node.group.environment.name,
                        self.l2_network_device.name, self.mac_address)
Esempio n. 12
0
 def test_underscored(self):
     result = helpers.underscored('single')
     self.assertEqual(result, 'single')
     result = helpers.underscored('m', 'u', 'l', 't', 'i', 'p', 'l', 'e')
     self.assertEqual(result, 'm_u_l_t_i_p_l_e')
Esempio n. 13
0
    def define(self):
        network_name = underscored(
            deepgetattr(self, 'group.environment.name'),
            self.name,
        )

        bridge_name = 'virbr{0}'.format(self.id)

        # TODO(ddmitriev): check if 'vlan' package installed
        # Define tagged interfaces on the bridge
        for vlanid in self.vlan_ifaces:
            self.iface_define(name=bridge_name, vlanid=vlanid)

        # Define libvirt network
        ip_network_address = None
        ip_network_prefixlen = None
        dhcp_range_start = None
        dhcp_range_end = None
        addresses = []
        if self.address_pool is not None:
            # Reserved names 'l2_network_device' and 'dhcp'
            ip_network_address = self.address_pool.get_ip('l2_network_device')

            # Workaround for fuel-qa compatibility, if 'l2_network_device'
            # address was not reserved in the YAML template
            if not ip_network_address:
                ip_network_address = str(self.address_pool.ip_network[1])

            ip_network_prefixlen = str(self.address_pool.ip_network.prefixlen)
            dhcp_range_start = self.address_pool.ip_range_start('dhcp')
            dhcp_range_end = self.address_pool.ip_range_end('dhcp')

            for interface in self.interfaces:
                for address in interface.addresses:
                    ip_addr = netaddr.IPAddress(address.ip_address)
                    if ip_addr in self.address_pool.ip_network:
                        addresses.append(dict(
                            mac=str(interface.mac_address),
                            ip=str(address.ip_address),
                            name=interface.node.name
                        ))

        xml = LibvirtXMLBuilder.build_network_xml(
            network_name=network_name,
            bridge_name=bridge_name,
            addresses=addresses,
            forward=self.forward.mode,
            ip_network_address=ip_network_address,
            ip_network_prefixlen=ip_network_prefixlen,
            dhcp_range_start=dhcp_range_start,
            dhcp_range_end=dhcp_range_end,
            stp=self.driver.stp,
            has_pxe_server=self.has_pxe_server,
            has_dhcp_server=self.has_dhcp_server,
            tftp_root_dir=self.tftp_root_dir,
        )
        ret = self.driver.conn.networkDefineXML(xml)
        ret.setAutostart(True)
        self.uuid = ret.UUIDString()

        super(L2NetworkDevice, self).define()