From f48922bc04ab41f9fe9cf57bf7a45afb7d56b0f2 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Thu, 13 Sep 2012 11:17:39 -0400 Subject: [PATCH] updated client names --- PLC/NovaShell.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 PLC/NovaShell.py diff --git a/PLC/NovaShell.py b/PLC/NovaShell.py new file mode 100644 index 00000000..ca07fdb1 --- /dev/null +++ b/PLC/NovaShell.py @@ -0,0 +1,99 @@ +from keystoneclient.v2_0 import client as keystone_client +from glance import client as glance_client +from novaclient.v1_1 import client as nova_client +from PLC.Config import Config +from PLC.Logger import logger + +def parse_novarc(filename): + opts = {} + f = open(filename, 'r') + for line in f: + try: + line = line.replace('export', '').strip() + parts = line.split('=') + if len(parts) > 1: + value = parts[1].replace("\'", "") + value = value.replace('\"', '') + opts[parts[0]] = value + except: + pass + f.close() + return opts + + +class Client: + def __init__(self, username=None, password=None, tenant=None, url=None, config=None): + if config: + config = Config(config) + else: + config = Config() + self.username = config.nova_admin_user + self.password = config.nova_admin_password + self.tenant = config.nova_admin_tenant + self.url = config.nova_url + + if username: + self.username = username + if password: + self.password = password + if tenant: + self.tenant = tenant + if url: + self.url = url + +class KeystoneClient(Client): + def __init__(self, *args, **kwds): + Client.__init__(self, *args, **kwds) + self.client = keystone_client.Client(username=self.username, + password=self.password, + tenant_name=self.tenant, + auth_url=self.url) + + def connect(self, *args, **kwds): + self.__init__(*args, **kwds) + + def __getattr__(self, name): + return getattr(self.client, name) + + +class GlanceClient(Client): + def __init__(self, *args, **kwds): + Client.__init__(self, *args, **kwds) + self.client = glance_client.get_client(host='0.0.0.0', + username=self.username, + password=self.password, + tenant=self.tenant, + auth_url=self.url) + def __getattr__(self, name): + return getattr(self.client, name) + +class NovaClient(Client): + def __init__(self, *args, **kwds): + Client.__init__(self, *args, **kwds) + self.client = nova_client.Client(username=self.username, + api_key=self.password, + project_id=self.tenant, + auth_url=self.url, + region_name='', + extensions=[], + service_type='compute', + service_name='', + ) + + def connect(self, *args, **kwds): + self.__init__(*args, **kwds) + + def __getattr__(self, name): + return getattr(self.client, name) + +class NovaShell: + """ + A simple native shell to a nova backend. + This class can receive all nova calls to the underlying testbed + """ + + def __init__ ( self, config=None) : + # instantiate managers + self.keystone = KeystoneClient(config=config) + self.glance = GlanceClient(config=config) + self.nova = NovaClient(config=config) -- 2.47.0