def build_node_xml(self, node, emulator): """Generate node XML :type node: Node :type emulator: String :rtype : String """ node_xml = XMLBuilder("domain", type=node.hypervisor) node_xml.name( self._get_name(node.environment and node.environment.name or '', node.name)) with node_xml.cpu(mode='host-model'): node_xml.model(fallback='forbid') node_xml.vcpu(str(node.vcpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') node_xml.clock(offset='utc') with node_xml.clock.timer(name='rtc', tickpolicy='catchup', track='wall'): node_xml.catchup(threshold='123', slew='120', limit='10000') node_xml.clock.timer(name='pit', tickpolicy='delay') node_xml.clock.timer(name='hpet', present='yes' if self.driver.hpet else 'no') with node_xml.os: node_xml.type(node.os_type, arch=node.architecture) for boot_dev in json.loads(node.boot): node_xml.boot(dev=boot_dev) if self.driver.reboot_timeout: node_xml.bios( rebootTimeout='{0}'.format(self.driver.reboot_timeout)) if node.disk_devices.filter(bus='usb'): node_xml.bootmenu(enable='yes', timeout='3000') with node_xml.devices: node_xml.controller(type='usb', model='nec-xhci') node_xml.emulator(emulator) if node.has_vnc: if node.vnc_password: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes', passwd=node.vnc_password) else: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') for disk_device in node.disk_devices: self._build_disk_device(node_xml, disk_device) for interface in node.interfaces: self._build_interface_device(node_xml, interface) with node_xml.video: node_xml.model(type='vga', vram='9216', heads='1') with node_xml.serial(type='pty'): node_xml.target(port='0') with node_xml.console(type='pty'): node_xml.target(type='serial', port='0') return str(node_xml)
def make_story_xml(self, name=None, description=None, story_type=None, owned_by=None, requested_by=None, estimate=None, current_state=None, labels=None): story = XMLBuilder('story') if name is not None: story.name(name) if description is not None: story.description(description) if requested_by is not None: story.requested_by(requested_by) if owned_by is not None: story.owned_by(owned_by) if story_type is not None: story.story_type(story_type) if estimate is not None: story.estimate(str(estimate), type='integer') if current_state is not None: story.current_state(current_state) if labels is not None: label_string = ',' if labels: label_string = ','.join(labels) story.labels(label_string) return str(story)
def build_network_xml(self, network): """ :type network: Network :rtype : String """ network_xml = XMLBuilder('network') network_xml.name(self._get_name( network.environment and network.environment.name or '', network.name)) if not (network.forward is None): network_xml.forward(mode=network.forward) if not (network.ip_network is None): ip_network = IPNetwork(network.ip_network) with network_xml.ip(address=str(ip_network[1]), prefix=str(ip_network.prefixlen)): if network.has_pxe_server: network_xml.tftp(root=network.tftp_root_dir) if network.has_dhcp_server: with network_xml.dhcp: network_xml.range(start=str(network.ip_pool_start), end=str(network.ip_pool_end)) for interface in network.interfaces: for address in interface.addresses: if IPAddress(address.ip_address) in ip_network: network_xml.host( mac=str(interface.mac_address), ip=str(address.ip_address), name=interface.node.name ) if network.has_pxe_server: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def build_network_xml(self, network): """ :type network: Network :rtype : String """ network_xml = XMLBuilder('network') network_xml.name( self._get_name( network.environment and network.environment.name or '', network.name)) if not (network.forward is None): network_xml.forward(mode=network.forward) if not (network.ip_network is None): ip_network = IPNetwork(network.ip_network) with network_xml.ip(address=str(ip_network[1]), prefix=str(ip_network.prefixlen)): if network.has_pxe_server: network_xml.tftp(root=network.tftp_root_dir) if network.has_dhcp_server: with network_xml.dhcp: network_xml.range(start=str(network.ip_pool_start), end=str(network.ip_pool_end)) for interface in network.interfaces: for address in interface.addresses: if IPAddress(address.ip_address) in ip_network: network_xml.host( mac=str(interface.mac_address), ip=str(address.ip_address), name=interface.node.name) if network.has_pxe_server: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def build_node_xml(self, node, emulator): """ :rtype : String :type node: Node """ node_xml = XMLBuilder("domain", type=node.hypervisor) node_xml.name( self._get_name(node.environment and node.environment.name or '', node.name)) node_xml.vcpu(str(node.vcpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(node.os_type, arch=node.architecture) for boot_dev in json.loads(node.boot): node_xml.boot(dev=boot_dev) with node_xml.devices: node_xml.emulator(emulator) if node.has_vnc: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') for disk_device in node.disk_devices: self._build_disk_device(node_xml, disk_device) for interface in node.interfaces: self._build_interface_device(node_xml, interface) return str(node_xml)
def build_node_xml(self, node, emulator): """Generate node XML :type node: Node :type emulator: String :rtype : String """ node_xml = XMLBuilder("domain", type=node.hypervisor) node_xml.name( self._get_name(node.environment and node.environment.name or '', node.name)) with node_xml.cpu(mode='host-model'): node_xml.model(fallback='forbid') node_xml.vcpu(str(node.vcpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') node_xml.clock(offset='utc') node_xml.clock.timer( name='hpet', present='yes' if self.driver.hpet else 'no') with node_xml.os: node_xml.type(node.os_type, arch=node.architecture) for boot_dev in json.loads(node.boot): node_xml.boot(dev=boot_dev) if self.driver.reboot_timeout: node_xml.bios(rebootTimeout='{0}'.format( self.driver.reboot_timeout)) with node_xml.devices: node_xml.emulator(emulator) if node.has_vnc: if node.vnc_password: node_xml.graphics( type='vnc', listen='0.0.0.0', autoport='yes', passwd=node.vnc_password) else: node_xml.graphics( type='vnc', listen='0.0.0.0', autoport='yes') for disk_device in node.disk_devices: self._build_disk_device(node_xml, disk_device) for interface in node.interfaces: self._build_interface_device(node_xml, interface) with node_xml.video: node_xml.model(type='vga', vram='9216', heads='1') with node_xml.serial(type='pty'): node_xml.target(port='0') with node_xml.console(type='pty'): node_xml.target(type='serial', port='0') return str(node_xml)
def build_snapshot_xml(self, name=None, description=None): """ :rtype : String :type name: String :type description: String """ xml_builder = XMLBuilder('domainsnapshot') if not (name is None): xml_builder.name(name) if not (description is None): xml_builder.description(description) return str(xml_builder)
def to_subread_ds_xml(ds): x = XMLBuilder('dataset', id=ds.id, datasetTypeId="pacbio.datasets.subread_dataset") with x.metadata: x.createdAt(ds.createdAt) x.version(ds.version) x.name(ds.name) x.numRecords("1234") x.totalLength("12345") with x.dataset: x.cellId(str(ds.cellId)) x.numCells(str(ds.numCells)) return x
def build_volume_xml(self, volume): """ :type volume: Volume :rtype : String """ volume_xml = XMLBuilder('volume') volume_xml.name( self._get_name(volume.environment and volume.environment.name or '', volume.name)) volume_xml.capacity(str(volume.capacity)) with volume_xml.target: volume_xml.format(type=volume.format) if volume.backing_store is not None: with volume_xml.backingStore: volume_xml.path(self.driver.volume_path(volume.backing_store)) volume_xml.format(type=volume.backing_store.format) return str(volume_xml)
def build_volume_xml(self, volume): """ :type volume: Volume :rtype : String """ volume_xml = XMLBuilder('volume') volume_xml.name( self._get_name( volume.environment and volume.environment.name or '', volume.name)) volume_xml.capacity(str(volume.capacity)) with volume_xml.target: volume_xml.format(type=volume.format) if volume.backing_store is not None: with volume_xml.backingStore: volume_xml.path(self.driver.volume_path(volume.backing_store)) volume_xml.format(type=volume.backing_store.format) return str(volume_xml)
def build_network_xml(self, network): """Generate network XML :type network: Network :rtype : String """ network_xml = XMLBuilder('network') network_xml.name(self._get_name( network.environment and network.environment.name or '', network.name)) stp_val = 'off' if self.driver.stp: stp_val = 'on' network_xml.bridge( name="fuelbr{0}".format(network.id), stp=stp_val, delay="0") if network.forward is not None: network_xml.forward(mode=network.forward) if network.ip_network is not None: ip_network = IPNetwork(network.ip_network) with network_xml.ip( address=str(ip_network[1]), prefix=str(ip_network.prefixlen)): if network.has_pxe_server: network_xml.tftp(root=network.tftp_root_dir) if network.has_dhcp_server: with network_xml.dhcp: network_xml.range(start=str(network.ip_pool_start), end=str(network.ip_pool_end)) for interface in network.interfaces: for address in interface.addresses: if IPAddress(address.ip_address) in ip_network: network_xml.host( mac=str(interface.mac_address), ip=str(address.ip_address), name=interface.node.name ) if network.has_pxe_server: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def build_node_xml(self, node, emulator): """ :rtype : String :type node: Node """ node_xml = XMLBuilder("domain", type=node.hypervisor) node_xml.name( self._get_name(node.environment and node.environment.name or '', node.name)) with node_xml.cpu(mode='host-model'): node_xml.model(fallback='forbid') node_xml.vcpu(str(node.vcpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(node.os_type, arch=node.architecture) for boot_dev in json.loads(node.boot): node_xml.boot(dev=boot_dev) with node_xml.devices: node_xml.emulator(emulator) if node.has_vnc: if node.vnc_password: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes', passwd=node.vnc_password) else: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') for disk_device in node.disk_devices: self._build_disk_device(node_xml, disk_device) for interface in node.interfaces: self._build_interface_device(node_xml, interface) with node_xml.video: node_xml.model(type='vga', vram='9216', heads='1') with node_xml.serial(type='pty'): node_xml.target(port='0') with node_xml.console(type='pty'): node_xml.target(type='serial', port='0') return str(node_xml)
def build_network_xml(self, network): """Generate network XML :type network: Network :rtype : String """ network_xml = XMLBuilder('network') network_xml.name( self._get_name( network.environment and network.environment.name or '', network.name)) stp_val = 'off' if self.driver.stp: stp_val = 'on' network_xml.bridge(name="fuelbr{0}".format(network.id), stp=stp_val, delay="0") if network.forward is not None: network_xml.forward(mode=network.forward) if network.ip_network is not None: ip_network = IPNetwork(network.ip_network) with network_xml.ip(address=str(ip_network[1]), prefix=str(ip_network.prefixlen)): if network.has_pxe_server: network_xml.tftp(root=network.tftp_root_dir) if network.has_dhcp_server: with network_xml.dhcp: network_xml.range(start=str(network.ip_pool_start), end=str(network.ip_pool_end)) for interface in network.interfaces: for address in interface.addresses: if IPAddress(address.ip_address) in ip_network: network_xml.host( mac=str(interface.mac_address), ip=str(address.ip_address), name=interface.node.name) if network.has_pxe_server: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def create_snapshot(self, domain, snapshot_name, \ snapshot_description): """Create VM snapshot connection: object with a connection to the Hypervisor domain: VM name snapshot_name snapshot_description """ try: libvirt_domain = self.libvirt_connection.lookupByName(domain) xml_base = XMLBuilder('domainsnapshot') xml_base.name(snapshot_name) xml_base.description(snapshot_description) xml = str(xml_base) libvirt_domain.snapshotCreateXML(xml) except: print 'Unable to create snapshot' sys.exit(1) print 'Snapshot has been created successfully.'
def build_network_xml(self, network): network_xml = XMLBuilder('network') network_xml.name(network.id) if not network.forward is None: network_xml.forward(mode=network.forward) if hasattr(network, 'ip_addresses') and not network.ip_addresses is None: with network_xml.ip(address=str(network.ip_addresses[1]), prefix=str(network.ip_addresses.prefixlen)): if network.pxe: network_xml.tftp(root=network.tftp_root_dir) if network.dhcp_server: with network_xml.dhcp: if hasattr(network, 'dhcp_dynamic_address_start'): start = network.dhcp_dynamic_address_start else: start = network.ip_addresses[2] if hasattr(network, 'dhcp_dynamic_address_end'): end = network.dhcp_dynamic_address_end else: end = network.ip_addresses[ network.ip_addresses.numhosts - 2] allowed_addresses = list( network.ip_addresses )[2:network.ip_addresses.numhosts - 2] network_xml.range(start=str(start), end=str(end)) for interface in network.interfaces: address = find(lambda ip: ip in allowed_addresses, interface.ip_addresses) if address and interface.mac_address: network_xml.host(mac=str( interface.mac_address), ip=str(address), name=interface.node.name) if network.pxe: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def build_snapshot_xml(self, name=None, description=None, node=None, disk_only=False, external=False, external_dir=None): """Generate snapshot XML :rtype : String :type name: String :type description: String """ xml_builder = XMLBuilder('domainsnapshot') if name is not None: xml_builder.name(name) if description is not None: xml_builder.description(description) if external: domain = self.driver.conn.lookupByUUIDString(node.uuid) # Add memory file for active machines if domain.isActive() and not disk_only: memory_file = '{0}/snapshot-memory-{1}_{2}.{3}'.format( external_dir, node.environment.name, node.name, name) file_count = 0 tmp_memory_file = memory_file while os.path.exists(tmp_memory_file): tmp_memory_file = memory_file + '-' + str(file_count) file_count += 1 xml_builder.memory( file=tmp_memory_file, snapshot='external') else: xml_builder.memory(snapshot='no') for disk in node.disk_devices: if disk.device == 'disk': with xml_builder.disks: xml_builder.disk(name=disk.target_dev, file=disk.volume.get_path(), snapshot='external') return str(xml_builder)
def build_network_xml(self, network): network_xml = XMLBuilder('network') network_xml.name(network.id) if not network.forward is None: network_xml.forward(mode=network.forward) if hasattr(network, 'ip_addresses') and not network.ip_addresses is None: with network_xml.ip( address=str(network.ip_addresses[1]), prefix=str(network.ip_addresses.prefixlen) ): if network.pxe: network_xml.tftp(root=network.tftp_root_dir) if network.dhcp_server: with network_xml.dhcp: if hasattr(network, 'dhcp_dynamic_address_start'): start = network.dhcp_dynamic_address_start else: start = network.ip_addresses[2] if hasattr(network, 'dhcp_dynamic_address_end'): end = network.dhcp_dynamic_address_end else: end = network.ip_addresses[ network.ip_addresses.numhosts - 2] allowed_addresses = list(network.ip_addresses)[2: network.ip_addresses.numhosts - 2] network_xml.range(start=str(start), end=str(end)) for interface in network.interfaces: address = find( lambda ip: ip in allowed_addresses, interface.ip_addresses) if address and interface.mac_address: network_xml.host( mac=str(interface.mac_address), ip=str(address), name=interface.node.name) if network.pxe: network_xml.bootp(file="pxelinux.0") return str(network_xml)
def update_dhcpd(self): mac = re.sub('-',':',self.fuel['mac']) fuel = self.fuel ip = vlans[self.vlan]['network'] filename = "/tmp/deploy." + str(os.getpid()) x = XMLBuilder('network') x.name("lab" + str(self.vlan)) x.bridge(name = "br"+self.vlan, stp="off", delay="0") with x.forward(mode = "route", dev="eth0"): x.interface(dev="eth0") with x.ip(address = str(ip.ip+1), netmask="255.255.255.192"): with x.dhcp: x.host(mac=mac, ip=str(ip.ip+2)) x.bootp(file="pxelinux.0") x.tftp(root="/var/lib/tftpboot") print str(x)+"\n" f=open(filename,"w") f.write(str(x)+"\n") f.close() os.system("sudo ifconfig br%s down" % self.vlan) os.system("virsh net-destroy lab%s" % self.vlan) os.system("virsh net-create %s" % filename) os.system("sudo brctl addif br%s eth1.%s" % (self.vlan, self.vlan))
def build_node_xml(self, node, emulator): """Generate node XML :type node: Node :type emulator: String :rtype : String """ node_xml = XMLBuilder("domain", type=node.hypervisor) node_xml.name( self._get_name(node.environment and node.environment.name or '', node.name)) if self.driver.use_host_cpu: node_xml.cpu(mode='host-passthrough') node_xml.vcpu(str(node.vcpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') if self.driver.use_hugepages: with node_xml.memoryBacking: node_xml.hugepages node_xml.clock(offset='utc') with node_xml.clock.timer(name='rtc', tickpolicy='catchup', track='wall'): node_xml.catchup( threshold='123', slew='120', limit='10000') node_xml.clock.timer( name='pit', tickpolicy='delay') node_xml.clock.timer( name='hpet', present='yes' if self.driver.hpet else 'no') with node_xml.os: node_xml.type(node.os_type, arch=node.architecture) for boot_dev in json.loads(node.boot): node_xml.boot(dev=boot_dev) if self.driver.reboot_timeout: node_xml.bios(rebootTimeout='{0}'.format( self.driver.reboot_timeout)) if node.should_enable_boot_menu: node_xml.bootmenu(enable='yes', timeout='3000') with node_xml.devices: node_xml.controller(type='usb', model='nec-xhci') node_xml.emulator(emulator) if node.has_vnc: if node.vnc_password: node_xml.graphics( type='vnc', listen='0.0.0.0', autoport='yes', passwd=node.vnc_password) else: node_xml.graphics( type='vnc', listen='0.0.0.0', autoport='yes') for disk_device in node.disk_devices: self._build_disk_device(node_xml, disk_device) for interface in node.interfaces: self._build_interface_device(node_xml, interface) with node_xml.video: node_xml.model(type='vga', vram='9216', heads='1') with node_xml.serial(type='pty'): node_xml.target(port='0') with node_xml.console(type='pty'): node_xml.target(type='serial', port='0') return str(node_xml)
def build_node_xml(self, node, spec): node_xml = XMLBuilder("domain", type=spec.hypervisor) node_xml.name(node.id) node_xml.vcpu(str(node.cpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(spec.os_type, arch=node.arch) for boot_dev in node.boot: if boot_dev == 'disk': node_xml.boot(dev="hd") else: node_xml.boot(dev=boot_dev) ide_disk_names = deque( ['hd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) serial_disk_names = deque( ['sd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) def disk_name(bus='ide'): if str(bus) == 'ide': return ide_disk_names.popleft() return serial_disk_names.popleft() with node_xml.devices: node_xml.emulator(spec.emulator) if len(node.disks) > 0: node_xml.controller(type="ide") for disk in node.disks: with node_xml.disk(type="file", device="disk"): node_xml.driver( name="qemu", type=disk.format, cache="unsafe") node_xml.source(file=disk.path) node_xml.target(dev=disk_name(disk.bus), bus=disk.bus) if node.cdrom: with node_xml.disk(type="file", device="cdrom"): node_xml.driver(name="qemu", type="raw") node_xml.source(file=node.cdrom.isopath) node_xml.target( dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus) for interface in node.interfaces: with node_xml.interface(type="network"): node_xml.source(network=interface.network.id) if not (interface.type is None): node_xml.model(type=interface.type) for interface in node.bridged_interfaces: with node_xml.interface(type="bridge"): node_xml.source(bridge=interface.bridge) if not (interface.type is None): node_xml.model(type=interface.type) if node.vnc: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') return str(node_xml)
def build_node_xml(self, node, spec): node_xml = XMLBuilder("domain", type=spec.hypervisor) node_xml.name(node.id) node_xml.vcpu(str(node.cpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(spec.os_type, arch=node.arch) for boot_dev in node.boot: if boot_dev == 'disk': node_xml.boot(dev="hd") else: node_xml.boot(dev=boot_dev) ide_disk_names = deque( ['hd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) serial_disk_names = deque( ['sd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) def disk_name(bus='ide'): if str(bus) == 'ide': return ide_disk_names.popleft() return serial_disk_names.popleft() with node_xml.devices: node_xml.emulator(spec.emulator) if len(node.disks) > 0: node_xml.controller(type="ide") for disk in node.disks: with node_xml.disk(type="file", device="disk"): node_xml.driver(name="qemu", type=disk.format, cache="unsafe") node_xml.source(file=disk.path) node_xml.target(dev=disk_name(disk.bus), bus=disk.bus) if node.cdrom: with node_xml.disk(type="file", device="cdrom"): node_xml.driver(name="qemu", type="raw") node_xml.source(file=node.cdrom.isopath) node_xml.target(dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus) for interface in node.interfaces: with node_xml.interface(type="network"): node_xml.source(network=interface.network.id) if not (interface.type is None): node_xml.model(type=interface.type) for interface in node.bridged_interfaces: with node_xml.interface(type="bridge"): node_xml.source(bridge=interface.bridge) if not (interface.type is None): node_xml.model(type=interface.type) if node.vnc: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') return str(node_xml)