summaryrefslogtreecommitdiffstats
path: root/build/opnfv-apex-common.spec
blob: 05926031053dddee3fb41ee057819dce2d80552c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Name:		opnfv-apex-common
Version:	2.3
Release:	%{release}
Summary:	Scripts for OPNFV deployment using RDO Manager

Group:		System Environment
License:	Apache 2.0
URL:		https://gerrit.opnfv.org/gerrit/apex.git
Source0:	opnfv-apex-common.tar.gz

BuildArch:	noarch
BuildRequires:	openvswitch qemu-kvm python-docutils
Requires:	opnfv-apex-sdn opnfv-apex-undercloud openvswitch qemu-kvm bridge-utils libguestfs-tools
Requires:	initscripts net-tools iputils iproute iptables

%description
Scripts for OPNFV deployment using RDO Manager
https://wiki.opnfv.org/apex

%prep
%setup -q

%build
rst2html docs/installation-instructions/index.rst docs/installation-instructions.html
rst2html docs/release-notes/release-notes.rst docs/release-notes.html

%install
mkdir -p %{buildroot}%{_bindir}/
install ci/deploy.sh %{buildroot}%{_bindir}/opnfv-deploy
install ci/clean.sh %{buildroot}%{_bindir}/opnfv-clean
install ci/util.sh %{buildroot}%{_bindir}/opnfv-util

mkdir -p %{buildroot}%{_sysconfdir}/opnfv-apex/
install config/deploy/os-nosdn-nofeature-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-nosdn-nofeature-ha.yaml
install config/deploy/os-odl_l2-nofeature-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-odl_l2-nofeature-ha.yaml
install config/deploy/os-odl_l2-bgpvpn-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-odl_l2-bgpvpn-ha.yaml
install config/deploy/os-odl_l2-sfc-noha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-odl_l2-sfc-noha.yaml
install config/deploy/os-odl_l3-nofeature-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-odl_l3-nofeature-ha.yaml
install config/deploy/os-onos-nofeature-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-onos-nofeature-ha.yaml
install config/deploy/os-opencontrail-nofeature-ha.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/os-opencontrail-nofeature-ha.yaml
install config/deploy/network/network_settings.yaml %{buildroot}%{_sysconfdir}/opnfv-apex/network_settings.yaml

mkdir -p %{buildroot}%{_var}/opt/opnfv/lib/
install lib/common-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/
install lib/utility-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/
mkdir -p %{buildroot}%{_var}/opt/opnfv/lib/installer/onos/
install lib/installer/onos/onos_gw_mac_update.sh %{buildroot}%{_var}/opt/opnfv/lib/installer/onos/

mkdir -p %{buildroot}%{_docdir}/opnfv/
install LICENSE.rst %{buildroot}%{_docdir}/opnfv/
install docs/installation-instructions.html %{buildroot}%{_docdir}/opnfv/
install docs/release-notes/index.rst %{buildroot}%{_docdir}/opnfv/release-notes.rst
install docs/release-notes.html %{buildroot}%{_docdir}/opnfv/
install config/deploy/deploy_settings.yaml %{buildroot}%{_docdir}/opnfv/deploy_settings.yaml.example
install config/deploy/network/network_settings.yaml %{buildroot}%{_docdir}/opnfv/network_settings.yaml.example
install config/inventory/pod_example_settings.yaml %{buildroot}%{_docdir}/opnfv/inventory.yaml.example

%files
%defattr(644, root, root, -)
%attr(755,root,root) %{_bindir}/opnfv-deploy
%attr(755,root,root) %{_bindir}/opnfv-clean
%attr(755,root,root) %{_bindir}/opnfv-util
%{_var}/opt/opnfv/lib/common-functions.sh
%{_var}/opt/opnfv/lib/utility-functions.sh
%{_var}/opt/opnfv/lib/installer/onos/onos_gw_mac_update.sh
%{_sysconfdir}/opnfv-apex/os-nosdn-nofeature-ha.yaml
%{_sysconfdir}/opnfv-apex/os-odl_l2-nofeature-ha.yaml
%{_sysconfdir}/opnfv-apex/os-odl_l2-sfc-noha.yaml
%{_sysconfdir}/opnfv-apex/os-odl_l2-bgpvpn-ha.yaml
%{_sysconfdir}/opnfv-apex/os-odl_l3-nofeature-ha.yaml
%{_sysconfdir}/opnfv-apex/os-onos-nofeature-ha.yaml
%{_sysconfdir}/opnfv-apex/os-opencontrail-nofeature-ha.yaml
%{_sysconfdir}/opnfv-apex/network_settings.yaml
%doc %{_docdir}/opnfv/LICENSE.rst
%doc %{_docdir}/opnfv/installation-instructions.html
%doc %{_docdir}/opnfv/release-notes.rst
%doc %{_docdir}/opnfv/release-notes.html
%doc %{_docdir}/opnfv/deploy_settings.yaml.example
%doc %{_docdir}/opnfv/network_settings.yaml.example
%doc %{_docdir}/opnfv/inventory.yaml.example

%changelog
* Mon Apr 24 2016 Tim Rozet <trozet@redhat.com> - 2.3-0
- Brahmaputra SR2
* Mon Apr 11 2016 Tim Rozet <trozet@redhat.com> - 2.2-1
- adding opnfv-util
* Mon Apr 04 2016 Dan Radez <dradez@redhat.com> - 2.2-0
- Brahmaputra SR1
- adding dependencies initscripts net-tools iputils iproute iptables
* Wed Jan 27 2016 Tim Rozet <trozet@redhat.com> - 2.1-4
- Adds example inventory file and nosdn scenario
* Wed Jan 20 2016 Dan Radez <dradez@redhat.com> - 2.1-3
- Updating the installation instructions
* Thu Jan 14 2016 Dan Radez <dradez@redhat.com> - 2.1-2
- Package Split
/span> import credentials from .log import LOG from . import utils class ComputeCleaner(object): """A cleaner for compute resources.""" def __init__(self, nova_client, instance_prefix): self.nova_client = nova_client LOG.info('Discovering instances %s...', instance_prefix) all_servers = self.nova_client.servers.list() self.servers = [server for server in all_servers if server.name.startswith(instance_prefix)] def get_resource_list(self): return [["Instance", server.name, server.id] for server in self.servers] def get_cleaner_code(self): return "instances" def clean_needed(self, clean_options): if clean_options is None: return True code = self.get_cleaner_code() return code[0] in clean_options def clean(self, clean_options): if self.clean_needed(clean_options): if self.servers: for server in self.servers: utils.delete_server(self.nova_client, server) utils.waiting_servers_deletion(self.nova_client, self.servers) class NetworkCleaner(object): """A cleaner for network resources.""" def __init__(self, neutron_client, network_name_prefixes): self.neutron_client = neutron_client LOG.info('Discovering networks...') all_networks = self.neutron_client.list_networks()['networks'] self.networks = [] net_ids = [] for net in all_networks: netname = net['name'] for prefix in network_name_prefixes: if prefix and netname.startswith(prefix): self.networks.append(net) net_ids.append(net['id']) break if net_ids: LOG.info('Discovering ports...') all_ports = self.neutron_client.list_ports()['ports'] self.ports = [port for port in all_ports if port['network_id'] in net_ids] LOG.info('Discovering floating ips...') all_floating_ips = self.neutron_client.list_floatingips()['floatingips'] self.floating_ips = [floating_ip for floating_ip in all_floating_ips if floating_ip['floating_network_id'] in net_ids and "nfvbench" in floating_ip['description']] else: self.ports = [] self.floating_ips = [] def get_resource_list(self): res_list = [["Network", net['name'], net['id']] for net in self.networks] res_list.extend([["Port", port['name'], port['id']] for port in self.ports]) res_list.extend( [["Floating IP", floating_ip['description'], floating_ip['id']] for floating_ip in self.floating_ips]) return res_list def get_cleaner_code(self): return "networks, ports and floating ips" def clean_needed(self, clean_options): if clean_options is None: return True code = self.get_cleaner_code() return code[0] in clean_options def clean(self, clean_options): if self.clean_needed(clean_options): for port in self.ports: LOG.info("Deleting port %s...", port['id']) try: self.neutron_client.delete_port(port['id']) except Exception: LOG.exception("Port deletion failed") for floating_ip in self.floating_ips: LOG.info("Deleting floating ip %s...", floating_ip['id']) try: self.neutron_client.delete_floatingip(floating_ip['id']) except Exception: LOG.exception("Floating IP deletion failed") # associated subnets are automatically deleted by neutron for net in self.networks: LOG.info("Deleting network %s...", net['name']) try: self.neutron_client.delete_network(net['id']) except Exception: LOG.exception("Network deletion failed") class RouterCleaner(object): """A cleaner for router resources.""" def __init__(self, neutron_client, router_names): self.neutron_client = neutron_client LOG.info('Discovering routers...') all_routers = self.neutron_client.list_routers()['routers'] self.routers = [] self.ports = [] self.routes = [] rtr_ids = [] for rtr in all_routers: rtrname = rtr['name'] for name in router_names: if rtrname == name: self.routers.append(rtr) rtr_ids.append(rtr['id']) LOG.info('Discovering router routes for router %s...', rtr['name']) all_routes = rtr['routes'] for route in all_routes: LOG.info("destination: %s, nexthop: %s", route['destination'], route['nexthop']) LOG.info('Discovering router ports for router %s...', rtr['name']) self.ports.extend(self.neutron_client.list_ports(device_id=rtr['id'])['ports']) break def get_resource_list(self): res_list = [["Router", rtr['name'], rtr['id']] for rtr in self.routers] return res_list def get_cleaner_code(self): return "router" def clean_needed(self, clean_options): if clean_options is None: return True code = self.get_cleaner_code() return code[0] in clean_options def clean(self, clean_options): if self.clean_needed(clean_options): # associated routes needs to be deleted before deleting routers for rtr in self.routers: LOG.info("Deleting routes for %s...", rtr['name']) try: body = { 'router': { 'routes': [] } } self.neutron_client.update_router(rtr['id'], body) except Exception: LOG.exception("Router routes deletion failed") LOG.info("Deleting ports for %s...", rtr['name']) try: for port in self.ports: body = { 'port_id': port['id'] } self.neutron_client.remove_interface_router(rtr['id'], body) except Exception: LOG.exception("Router ports deletion failed") LOG.info("Deleting router %s...", rtr['name']) try: self.neutron_client.delete_router(rtr['id']) except Exception: LOG.exception("Router deletion failed") class FlavorCleaner(object): """Cleaner for NFVbench flavor.""" def __init__(self, nova_client, name): self.name = name LOG.info('Discovering flavor %s...', name) try: self.flavor = nova_client.flavors.find(name=name) except NotFound: self.flavor = None def get_resource_list(self): if self.flavor: return [['Flavor', self.name, self.flavor.id]] return None def get_cleaner_code(self): return "flavor" def clean_needed(self, clean_options): if clean_options is None: return True code = self.get_cleaner_code() return code[0] in clean_options def clean(self, clean_options): if self.clean_needed(clean_options): if self.flavor: LOG.info("Deleting flavor %s...", self.flavor.name) try: self.flavor.delete() except Exception: LOG.exception("Flavor deletion failed") class Cleaner(object): """Cleaner for all NFVbench resources.""" def __init__(self, config): cred = credentials.Credentials(config.openrc_file, None, False) session = cred.get_session() self.neutron_client = nclient.Client('2.0', session=session) self.nova_client = Client(2, session=session) network_names = [inet['name'] for inet in config.internal_networks.values()] network_names.extend([inet['name'] for inet in config.edge_networks.values()]) network_names.append(config.management_network['name']) network_names.append(config.floating_network['name']) router_names = [rtr['router_name'] for rtr in config.edge_networks.values()] # add idle networks as well if config.idle_networks.name: network_names.append(config.idle_networks.name) self.cleaners = [ComputeCleaner(self.nova_client, config.loop_vm_name), FlavorCleaner(self.nova_client, config.flavor_type), NetworkCleaner(self.neutron_client, network_names), RouterCleaner(self.neutron_client, router_names)] def show_resources(self): """Show all NFVbench resources.""" table = [["Type", "Name", "UUID"]] for cleaner in self.cleaners: res_list = cleaner.get_resource_list() if res_list: table.extend(res_list) count = len(table) - 1 if count: LOG.info('Discovered %d NFVbench resources:\n%s', count, tabulate(table, headers="firstrow", tablefmt="psql")) else: LOG.info('No matching NFVbench resources found') return count def clean(self, prompt): """Clean all resources.""" LOG.info("NFVbench will delete resources shown...") clean_options = None if prompt: answer = input("Do you want to delete all ressources? (y/n) ") if answer.lower() != 'y': print("What kind of resources do you want to delete?") all_option = "" all_option_codes = [] for cleaner in self.cleaners: code = cleaner.get_cleaner_code() print(("%s: %s" % (code[0], code))) all_option += code[0] all_option_codes.append(code) print(("a: all resources - a shortcut for '%s'" % all_option)) all_option_codes.append("all resources") print("q: quit") answer_res = input(":").lower() # Check only first character because answer_res can be "flavor" and it is != all if answer_res[0] == "a": clean_options = all_option elif answer_res[0] != 'q': # if user write complete code instead of shortcuts # Get only first character of clean code to avoid false clean request # i.e "networks and ports" and "router" have 1 letter in common and router clean # will be called even if user ask for networks and ports if answer_res in all_option_codes: clean_options = answer_res[0] else: clean_options = answer_res else: LOG.info("Exiting without deleting any resource") sys.exit(0) for cleaner in self.cleaners: cleaner.clean(clean_options)