diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-08-31 02:32:05 +0200 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-09-03 04:27:00 +0200 |
commit | 1b89628e4571a65245a743e4a85d38438a119b3d (patch) | |
tree | 6b31ac6ab1d5e2197cf2e922ae317d8db237e303 /deploy/environments | |
parent | 98f171c82636c29a9cfd5c94c8e7aac7ca7af41b (diff) |
build, deploy: Remove obsolete Fuel@Openstack code
JIRA: FUEL-278
Change-Id: I30c04c325de5ac97aee172386de43201988646c5
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Diffstat (limited to 'deploy/environments')
-rw-r--r-- | deploy/environments/__init__.py | 8 | ||||
-rw-r--r-- | deploy/environments/execution_environment.py | 102 | ||||
-rw-r--r-- | deploy/environments/libvirt_environment.py | 107 | ||||
-rw-r--r-- | deploy/environments/virtual_fuel.py | 143 |
4 files changed, 0 insertions, 360 deletions
diff --git a/deploy/environments/__init__.py b/deploy/environments/__init__.py deleted file mode 100644 index fb73157f9..000000000 --- a/deploy/environments/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -############################################################################### -# Copyright (c) 2015 Ericsson AB and others. -# szilard.cserey@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################### diff --git a/deploy/environments/execution_environment.py b/deploy/environments/execution_environment.py deleted file mode 100644 index 7a0b4744e..000000000 --- a/deploy/environments/execution_environment.py +++ /dev/null @@ -1,102 +0,0 @@ -############################################################################### -# Copyright (c) 2015 Ericsson AB and others. -# szilard.cserey@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################### - - -from lxml import etree -from dha_adapters.libvirt_adapter import LibvirtAdapter - -from common import ( - exec_cmd, - log, - delete, -) - - -class ExecutionEnvironment(object): - - def __init__(self, storage_dir, dha_file, root_dir): - self.storage_dir = storage_dir - self.dha = LibvirtAdapter(dha_file) - self.root_dir = root_dir - self.parser = etree.XMLParser(remove_blank_text=True) - self.fuel_node_id = self.dha.get_fuel_node_id() - - def delete_vm(self, node_id): - vm_name = self.dha.get_node_property(node_id, 'libvirtName') - r, c = exec_cmd('virsh dumpxml %s' % vm_name, False) - if c: - return - self.undefine_vm_delete_disk(r, vm_name) - - def undefine_vm_delete_disk(self, printout, vm_name): - disk_files = [] - xml_dump = etree.fromstring(printout, self.parser) - disks = xml_dump.xpath('/domain/devices/disk') - for disk in disks: - sources = disk.xpath('source') - for source in sources: - source_file = source.get('file') - if source_file: - disk_files.append(source_file) - log('Deleting VM %s with disks %s' % (vm_name, disk_files)) - exec_cmd('virsh destroy %s' % vm_name, False) - exec_cmd('virsh undefine --managed-save --remove-all-storage %s' % vm_name, False) - for file in disk_files: - delete(file) - - def overwrite_xml(self, vm_xml, vm_definition_overwrite): - if not vm_definition_overwrite: - return - for key, value in vm_definition_overwrite.iteritems(): - if key == 'attribute_equlas': - continue - if key == 'value': - vm_xml.text = str(value) - return - if key == 'attribute': - for attr_key, attr_value in value.iteritems(): - vm_xml.set(attr_key, str(attr_value)) - return - - if isinstance(value, dict): - only_when_attribute = value.get('attribute_equlas') - for xml_element in vm_xml.xpath(key): - if only_when_attribute: - for attr_key, attr_value in \ - only_when_attribute.iteritems(): - if attr_value != xml_element.get(attr_key): - continue - self.overwrite_xml(xml_element, value) - - def define_vm(self, vm_name, temp_vm_file, disk_path, - vm_definition_overwrite): - log('Creating VM %s with disks %s' % (vm_name, disk_path)) - with open(temp_vm_file) as f: - vm_xml = etree.parse(f) - names = vm_xml.xpath('/domain/name') - for name in names: - name.text = vm_name - uuids = vm_xml.xpath('/domain/uuid') - for uuid in uuids: - uuid.getparent().remove(uuid) - self.overwrite_xml(vm_xml.xpath('/domain')[0], - vm_definition_overwrite) - disks = vm_xml.xpath('/domain/devices/disk') - for disk in disks: - if (disk.get('type') == 'file' and - disk.get('device') == 'disk'): - sources = disk.xpath('source') - for source in sources: - disk.remove(source) - source = etree.Element('source') - source.set('file', disk_path) - disk.append(source) - with open(temp_vm_file, 'w') as f: - vm_xml.write(f, pretty_print=True, xml_declaration=True) - exec_cmd('virsh define %s' % temp_vm_file) diff --git a/deploy/environments/libvirt_environment.py b/deploy/environments/libvirt_environment.py deleted file mode 100644 index 07a47fd7e..000000000 --- a/deploy/environments/libvirt_environment.py +++ /dev/null @@ -1,107 +0,0 @@ -############################################################################### -# Copyright (c) 2015 Ericsson AB and others. -# szilard.cserey@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################### - - -from lxml import etree -import glob -from execution_environment import ExecutionEnvironment -import tempfile - -from common import ( - exec_cmd, - log, - check_dir_exists, - check_file_exists, - delete, -) - - -class LibvirtEnvironment(ExecutionEnvironment): - - def __init__(self, storage_dir, dha_file, dea, root_dir): - super(LibvirtEnvironment, self).__init__( - storage_dir, dha_file, root_dir) - self.dea = dea - self.network_dir = '%s/%s' % (self.root_dir, - self.dha.get_virt_net_conf_dir()) - self.node_ids = self.dha.get_all_node_ids() - self.net_names = self.collect_net_names() - - def create_storage(self, node_id, disk_path, disk_sizes): - role = self.dea.get_node_main_role(node_id, self.fuel_node_id) - disk_size = disk_sizes[role] - exec_cmd('qemu-img create -f raw %s %s' % (disk_path, disk_size)) - - def create_vms(self): - temp_dir = tempfile.mkdtemp() - disk_sizes = self.dha.get_disks() - for node_id in self.node_ids: - vm_name = self.dha.get_node_property(node_id, 'libvirtName') - vm_template = '%s/%s' % (self.root_dir, - self.dha.get_node_property( - node_id, 'libvirtTemplate')) - check_file_exists(vm_template) - disk_path = '%s/%s.raw' % (self.storage_dir, vm_name) - self.create_storage(node_id, disk_path, disk_sizes) - temp_vm_file = '%s/%s' % (temp_dir, vm_name) - exec_cmd('cp %s %s' % (vm_template, temp_vm_file)) - vm_definition_overwrite = self.dha.get_vm_definition( - self.dea.get_node_main_role(node_id, self.fuel_node_id)) - self.define_vm(vm_name, temp_vm_file, disk_path, - vm_definition_overwrite) - delete(temp_dir) - - def start_vms(self): - for node_id in self.node_ids: - self.dha.node_power_on(node_id) - - def create_networks(self): - for net_file in glob.glob('%s/*' % self.network_dir): - exec_cmd('virsh net-define %s' % net_file) - for net in self.net_names: - log('Creating network %s' % net) - exec_cmd('virsh net-autostart %s' % net) - exec_cmd('virsh net-start %s' % net) - - def delete_networks(self): - for net in self.net_names: - log('Deleting network %s' % net) - exec_cmd('virsh net-destroy %s' % net, False) - exec_cmd('virsh net-undefine %s' % net, False) - - def get_net_name(self, net_file): - with open(net_file) as f: - net_xml = etree.parse(f) - name_list = net_xml.xpath('/network/name') - for name in name_list: - net_name = name.text - return net_name - - def collect_net_names(self): - net_list = [] - for net_file in glob.glob('%s/*' % self.network_dir): - name = self.get_net_name(net_file) - net_list.append(name) - return net_list - - def delete_vms(self): - for node_id in self.node_ids: - self.delete_vm(node_id) - - - def setup_environment(self): - check_dir_exists(self.network_dir) - self.cleanup_environment() - self.create_networks() - self.create_vms() - self.start_vms() - - def cleanup_environment(self): - self.delete_vms() - self.delete_networks() diff --git a/deploy/environments/virtual_fuel.py b/deploy/environments/virtual_fuel.py deleted file mode 100644 index 5ddd93b51..000000000 --- a/deploy/environments/virtual_fuel.py +++ /dev/null @@ -1,143 +0,0 @@ -############################################################################### -# Copyright (c) 2015 Ericsson AB and others. -# szilard.cserey@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################### - - -from lxml import etree -from execution_environment import ExecutionEnvironment -import tempfile -import os -import re -import time - -from common import ( - exec_cmd, - check_file_exists, - check_if_root, - delete, - log, -) - -VOL_XML_TEMPLATE = '''<volume type='file'> - <name>{name}</name> - <capacity unit='{unit}'>{size!s}</capacity> - <target> - <format type='{format_type}'/> - </target> -</volume>''' - -DEFAULT_POOL = 'jenkins' - -def get_size_and_unit(s): - p = re.compile('^(\d+)\s*(\D+)') - m = p.match(s) - if m == None: - return None, None - size = m.groups()[0] - unit = m.groups()[1] - return size, unit - -class VirtualFuel(ExecutionEnvironment): - - def __init__(self, storage_dir, pxe_bridge, dha_file, root_dir): - super(VirtualFuel, self).__init__(storage_dir, dha_file, root_dir) - self.pxe_bridge = pxe_bridge - self.temp_dir = tempfile.mkdtemp() - self.vm_name = self.dha.get_node_property(self.fuel_node_id, - 'libvirtName') - self.vm_template = '%s/%s' % (self.root_dir, - self.dha.get_node_property( - self.fuel_node_id, 'libvirtTemplate')) - check_file_exists(self.vm_template) - with open(self.vm_template) as f: - self.vm_xml = etree.parse(f) - - self.temp_vm_file = '%s/%s' % (self.temp_dir, self.vm_name) - self.update_vm_template_file() - - def __del__(self): - delete(self.temp_dir) - - def update_vm_template_file(self): - with open(self.temp_vm_file, "wc") as f: - self.vm_xml.write(f, pretty_print=True, xml_declaration=True) - - def del_vm_nics(self): - interfaces = self.vm_xml.xpath('/domain/devices/interface') - for interface in interfaces: - interface.getparent().remove(interface) - - def add_vm_nic(self, bridge): - interface = etree.Element('interface') - interface.set('type', 'bridge') - source = etree.SubElement(interface, 'source') - source.set('bridge', bridge) - model = etree.SubElement(interface, 'model') - model.set('type', 'virtio') - - devices = self.vm_xml.xpath('/domain/devices') - if devices: - device = devices[0] - device.append(interface) - else: - err('No devices!') - - def create_volume(self, pool, name, su, img_type='raw'): - log('Creating image using Libvirt volumes in pool %s, name: %s' % - (pool, name)) - size, unit = get_size_and_unit(su) - if size == None: - err('Could not determine size and unit of %s' % s) - - vol_xml = VOL_XML_TEMPLATE.format(name=name, unit=unit, size=size, - format_type=img_type) - fname = os.path.join(self.temp_dir, '%s_vol.xml' % name) - with file(fname, 'w') as f: - f.write(vol_xml) - - exec_cmd('virsh vol-create --pool %s %s' % (pool, fname)) - vol_path = exec_cmd('virsh vol-path --pool %s %s' % (pool, name)) - - delete(fname) - - return vol_path - - def create_image(self, disk_path, disk_size): - if os.environ.get('LIBVIRT_DEFAULT_URI') == None: - exec_cmd('qemu-img create -f raw %s %s' % (disk_path, disk_size)) - else: - pool = DEFAULT_POOL # FIXME - name = os.path.basename(disk_path) - disk_path = self.create_volume(pool, name, disk_size) - - return disk_path - - def create_vm(self): - stamp = time.strftime("%Y%m%d%H%M%S") - disk_path = '%s/%s-%s.raw' % (self.storage_dir, self.vm_name, stamp) - disk_sizes = self.dha.get_disks() - disk_size = disk_sizes['fuel'] - disk_path = self.create_image(disk_path, disk_size) - - self.del_vm_nics() - for bridge in self.pxe_bridge: - self.add_vm_nic(bridge) - self.update_vm_template_file() - - vm_definition_overwrite = self.dha.get_vm_definition('fuel') - - self.define_vm(self.vm_name, self.temp_vm_file, disk_path, - vm_definition_overwrite) - - def setup_environment(self): - check_if_root() - self.cleanup_environment() - self.create_vm() - - def cleanup_environment(self): - self.delete_vm(self.fuel_node_id) |