diff --git a/openstack/cdn/v1/_proxy.py b/openstack/cdn/v1/_proxy.py new file mode 100644 index 00000000..69ade043 --- /dev/null +++ b/openstack/cdn/v1/_proxy.py @@ -0,0 +1,20 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.cdn.v1 import ping +from openstack import proxy + + +class Proxy(proxy.BaseProxy): + + def ping(self): + return ping.Ping().get(self.session) diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index 7f44d3da..0f278f81 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -18,12 +18,10 @@ from openstack.compute.v2 import limits from openstack.compute.v2 import server from openstack.compute.v2 import server_interface from openstack.compute.v2 import server_ip +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def find_extension(self, name_or_id): return extension.Extension.find(self.session, name_or_id) diff --git a/openstack/connection.py b/openstack/connection.py index 01ab15c1..8142b7a6 100644 --- a/openstack/connection.py +++ b/openstack/connection.py @@ -61,6 +61,7 @@ import logging import sys from openstack import module_loader +from openstack import proxy from openstack import session from openstack import transport as xport @@ -151,8 +152,11 @@ class Connection(object): module = service.get_module() + "._proxy" try: __import__(module) - proxy = getattr(sys.modules[module], "Proxy") - setattr(self, attr_name, proxy(self.session)) + proxy_class = getattr(sys.modules[module], "Proxy") + if not issubclass(proxy_class, proxy.BaseProxy): + raise TypeError("%s.Proxy must inherit from BaseProxy" % + proxy_class.__module__) + setattr(self, attr_name, proxy_class(self.session)) except Exception as e: _logger.warn("Unable to load %s: %s" % (module, e)) diff --git a/openstack/database/v1/_proxy.py b/openstack/database/v1/_proxy.py index 8c17ba76..96e9c18a 100644 --- a/openstack/database/v1/_proxy.py +++ b/openstack/database/v1/_proxy.py @@ -14,12 +14,10 @@ from openstack.database.v1 import database from openstack.database.v1 import flavor from openstack.database.v1 import instance from openstack.database.v1 import user +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_database(self, **data): return database.Database(data).create(self.session) diff --git a/openstack/identity/v2/_proxy.py b/openstack/identity/v2/_proxy.py index 4312a4f2..ff107cfc 100644 --- a/openstack/identity/v2/_proxy.py +++ b/openstack/identity/v2/_proxy.py @@ -13,12 +13,10 @@ from openstack.identity.v2 import role from openstack.identity.v2 import tenant from openstack.identity.v2 import user +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_role(self, **data): return role.Role(data).create(self.session) diff --git a/openstack/identity/v3/_proxy.py b/openstack/identity/v3/_proxy.py index 089176dc..c9f4da96 100644 --- a/openstack/identity/v3/_proxy.py +++ b/openstack/identity/v3/_proxy.py @@ -18,12 +18,10 @@ from openstack.identity.v3 import policy from openstack.identity.v3 import project from openstack.identity.v3 import service from openstack.identity.v3 import user +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_credential(self, **data): return credential.Credential(data).create(self.session) diff --git a/openstack/image/v1/_proxy.py b/openstack/image/v1/_proxy.py index 7dc6098c..6677e102 100644 --- a/openstack/image/v1/_proxy.py +++ b/openstack/image/v1/_proxy.py @@ -11,12 +11,10 @@ # under the License. from openstack.image.v1 import image +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_image(self, **data): return image.Image(data).create(self.session) diff --git a/openstack/keystore/v1/_proxy.py b/openstack/keystore/v1/_proxy.py index 12fb8127..73149f97 100644 --- a/openstack/keystore/v1/_proxy.py +++ b/openstack/keystore/v1/_proxy.py @@ -13,12 +13,10 @@ from openstack.keystore.v1 import container from openstack.keystore.v1 import order from openstack.keystore.v1 import secret +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_container(self, **data): return container.Container(data).create(self.session) diff --git a/openstack/metric/v1/_proxy.py b/openstack/metric/v1/_proxy.py index 49a5ff36..0cc748fa 100644 --- a/openstack/metric/v1/_proxy.py +++ b/openstack/metric/v1/_proxy.py @@ -11,12 +11,10 @@ # under the License. from openstack.metric.v1 import capabilities +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def list_capabilities(self): return capabilities.Capabilities.list(self.session) diff --git a/openstack/network/v2/_proxy.py b/openstack/network/v2/_proxy.py index 92d1f177..d0fcd503 100644 --- a/openstack/network/v2/_proxy.py +++ b/openstack/network/v2/_proxy.py @@ -26,12 +26,10 @@ from openstack.network.v2 import router from openstack.network.v2 import security_group from openstack.network.v2 import security_group_rule from openstack.network.v2 import subnet +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def find_extension(self, name_or_id): return extension.Extension.find(self.session, name_or_id) diff --git a/openstack/object_store/v1/_proxy.py b/openstack/object_store/v1/_proxy.py index ea122146..a1571ae1 100644 --- a/openstack/object_store/v1/_proxy.py +++ b/openstack/object_store/v1/_proxy.py @@ -12,12 +12,10 @@ from openstack.object_store.v1 import container as _container from openstack.object_store.v1 import obj as _obj +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def get_account_metadata(self): """Get metatdata for this account. diff --git a/openstack/orchestration/v1/_proxy.py b/openstack/orchestration/v1/_proxy.py index 3b41db55..a0525ddc 100644 --- a/openstack/orchestration/v1/_proxy.py +++ b/openstack/orchestration/v1/_proxy.py @@ -11,12 +11,10 @@ # under the License. from openstack.orchestration.v1 import stack +from openstack import proxy -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def find_stack(self, name_or_id): return stack.Stack.find(self.session, name_or_id) diff --git a/openstack/proxy.py b/openstack/proxy.py new file mode 100644 index 00000000..7add7b74 --- /dev/null +++ b/openstack/proxy.py @@ -0,0 +1,17 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class BaseProxy(object): + + def __init__(self, session): + self.session = session diff --git a/openstack/telemetry/v2/_proxy.py b/openstack/telemetry/v2/_proxy.py index f9265372..2d50a1a2 100644 --- a/openstack/telemetry/v2/_proxy.py +++ b/openstack/telemetry/v2/_proxy.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from openstack import proxy from openstack.telemetry.v2 import alarm from openstack.telemetry.v2 import alarm_change from openstack.telemetry.v2 import capability @@ -19,10 +20,7 @@ from openstack.telemetry.v2 import sample from openstack.telemetry.v2 import statistics -class Proxy(object): - - def __init__(self, session): - self.session = session +class Proxy(proxy.BaseProxy): def create_alarm(self, **data): return alarm.Alarm(data).create(self.session)