From 0910848e43c756bf7bb06b9909826f1514a92bf3 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 14 Dec 2015 13:26:25 +0000 Subject: [PATCH] Fixes --- lib/{ => charm}/openstack/__init__.py | 0 lib/{ => charm}/openstack/adapters.py | 0 lib/charm/openstack/base_charm.py | 90 +++++++++++++++++++++++++++ lib/{ => charm}/openstack/ip.py | 0 4 files changed, 90 insertions(+) rename lib/{ => charm}/openstack/__init__.py (100%) rename lib/{ => charm}/openstack/adapters.py (100%) create mode 100644 lib/charm/openstack/base_charm.py rename lib/{ => charm}/openstack/ip.py (100%) diff --git a/lib/openstack/__init__.py b/lib/charm/openstack/__init__.py similarity index 100% rename from lib/openstack/__init__.py rename to lib/charm/openstack/__init__.py diff --git a/lib/openstack/adapters.py b/lib/charm/openstack/adapters.py similarity index 100% rename from lib/openstack/adapters.py rename to lib/charm/openstack/adapters.py diff --git a/lib/charm/openstack/base_charm.py b/lib/charm/openstack/base_charm.py new file mode 100644 index 0000000..ad902bc --- /dev/null +++ b/lib/charm/openstack/base_charm.py @@ -0,0 +1,90 @@ +from charm.openstack.ip import PUBLIC, INTERNAL, ADMIN, canonical_url +from charmhelpers.core.hookenv import config + +class OpenStackCharm(object): + + packages = [] + """Packages to install""" + + api_ports = {} + """ + Dictionary mapping services to ports for public, admin and + internal endpoints + """ + + service_type = None + """Keystone endpoint type""" + + default_service = None + """Default service for the charm""" + + def __init__(self): + self.config = config() + + def install(self): + """ + Install packages related to this charm based on + contents of packages attribute. + """ + packages = filter_installed_packages(self.packages) + if packages: + status_set('maintenance', 'Installing packages') + apt_install(packages, fatal=True) + + def api_port(self, service, endpoint_type=PUBLIC): + """ + Determine the API port for a particular endpoint type + """ + return self.api_ports[service][endpoint_type] + + def configure_source(self): + """Configure installation source""" + configure_installation_source(self.config['openstack-origin']) + apt_update(fatal=True) + + @property + def region(self): + """OpenStack Region""" + return self.config['region'] + + @property + def public_url(self): + """Public Endpoint URL""" + return "{}:{}".format(canonical_url(PUBLIC), + self.api_port(self.default_service, + PUBLIC)) + @property + def admin_url(self): + """Admin Endpoint URL""" + return "{}:{}".format(canonical_url(ADMIN), + self.api_port(self.default_service, + ADMIN)) + @property + def internal_url(self): + """Internal Endpoint URL""" + return "{}:{}".format(canonical_url(INTERNAL), + self.api_port(self.default_service, + INTERNAL)) + +class OpenStackCharmFactory(object): + + releases = {} + """ + Dictionary mapping OpenStack releases to their associated + Charm class for this charm + """ + + first_release = "icehouse" + """ + First OpenStack release which this factory supports Charms for + """ + + @classmethod + def charm(cls, release=None): + """Get the right charm for the configured OpenStack series""" + if release and release in cls.releases: + return cls.releases[release] + else: + return cls.releases[cls.first_release] + + diff --git a/lib/openstack/ip.py b/lib/charm/openstack/ip.py similarity index 100% rename from lib/openstack/ip.py rename to lib/charm/openstack/ip.py