Skip to content

Commit 8aff42b

Browse files
committed
Move all clients to the base class
1 parent 66b7bd7 commit 8aff42b

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

caso/extract/openstack/base.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
import datetime
2020

21+
import cinderclient.v3.client
22+
import glanceclient.client
2123
import keystoneauth1.exceptions.http
24+
import neutronclient.v2_0.client
25+
import novaclient.client
2226
from oslo_config import cfg
2327
from oslo_log import log
2428

@@ -91,6 +95,27 @@ def _get_keystone_client(self):
9195
client = keystone_client.get_client(CONF, self.project)
9296
return client
9397

98+
def _get_cinder_client(self):
99+
"""Get Cinder client with keystone session."""
100+
session = self._get_keystone_session()
101+
return cinderclient.v3.client.Client(session=session)
102+
103+
def _get_glance_client(self):
104+
"""Get a glance client with a keystone session."""
105+
session = self._get_keystone_session()
106+
return glanceclient.client.Client(2, session=session)
107+
108+
def _get_neutron_client(self):
109+
"""Get a neutron client with a keystone session."""
110+
session = self._get_keystone_session()
111+
return neutronclient.v2_0.client.Client(session=session)
112+
113+
def _get_nova_client(self):
114+
"""Get a nova client with a keystone session."""
115+
region_name = CONF.region_name
116+
session = self._get_keystone_session()
117+
return novaclient.client.Client(2, session=session, region_name=region_name)
118+
94119
def _get_project_id(self):
95120
"""Get the project ID from the project in the object."""
96121
return self.keystone.projects.get(self.project).id

caso/extract/openstack/cinder.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import operator
2020

21-
import cinderclient.v3.client
2221
import dateutil.parser
2322
from oslo_config import cfg
2423
from oslo_log import log
@@ -43,11 +42,6 @@ def __init__(self, project, vo):
4342

4443
self.cinder = self._get_cinder_client()
4544

46-
def _get_cinder_client(self):
47-
"""Get Cinder client with keystone session."""
48-
session = self._get_keystone_session()
49-
return cinderclient.v3.client.Client(session=session)
50-
5145
def _build_record(self, volume, extract_from, extract_to):
5246
"""Build an individual record."""
5347
user = self.users[volume.user_id]

caso/extract/openstack/neutron.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import collections
2020
import ipaddress
2121

22-
import neutronclient.v2_0.client
2322
from oslo_config import cfg
2423
from oslo_log import log
2524

@@ -44,10 +43,6 @@ def __init__(self, project, vo):
4443

4544
self.neutron = self._get_neutron_client()
4645

47-
def _get_neutron_client(self):
48-
session = self._get_keystone_session()
49-
return neutronclient.v2_0.client.Client(session=session)
50-
5146
def _build_ip_record(self, user_id, ip_count, version):
5247
user = self.users[user_id]
5348

caso/extract/openstack/nova.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
from dateutil.relativedelta import relativedelta
2323
from dateutil.rrule import MONTHLY
2424
from dateutil.rrule import rrule
25-
import glanceclient.client
26-
import neutronclient.v2_0.client
27-
import novaclient.client
2825
import novaclient.exceptions
2926
from oslo_config import cfg
3027
from oslo_log import log
@@ -111,22 +108,6 @@ def __init__(self, project, vo):
111108
self.flavors = self._get_flavors()
112109
self.images = self._get_images()
113110

114-
def _get_nova_client(self):
115-
"""Get a nova client with a keystone session."""
116-
region_name = CONF.region_name
117-
session = self._get_keystone_session()
118-
return novaclient.client.Client(2, session=session, region_name=region_name)
119-
120-
def _get_glance_client(self):
121-
"""Get a glance client with a keystone session."""
122-
session = self._get_keystone_session()
123-
return glanceclient.client.Client(2, session=session)
124-
125-
def _get_neutron_client(self):
126-
"""Get a neutron client with a keystone session."""
127-
session = self._get_keystone_session()
128-
return neutronclient.v2_0.client.Client(session=session)
129-
130111
def _build_acc_records(self, server, server_record, extract_from, extract_to):
131112
records = {}
132113
flavor = self.flavors.get(server.flavor["id"])

0 commit comments

Comments
 (0)