from abc import ABCMeta, abstractmethod
-from six import StringIO
+from io import StringIO
import json
-from .conn import get_gateway_connection
+from .conn import get_gateway_connection, get_gateway_iam_connection, get_gateway_secure_connection
class Cluster:
""" interface to run commands against a distinct ceph cluster """
""" interface to control a single radosgw instance """
__metaclass__ = ABCMeta
- def __init__(self, host = None, port = None, cluster = None, zone = None, proto = 'http', connection = None):
+ def __init__(self, host = None, port = None, cluster = None, zone = None, ssl_port = 0):
self.host = host
self.port = port
self.cluster = cluster
self.zone = zone
- self.proto = proto
- self.connection = connection
+ self.connection = None
+ self.secure_connection = None
+ self.ssl_port = ssl_port
+ self.iam_connection = None
@abstractmethod
def start(self, args = []):
pass
def endpoint(self):
- return '%s://%s:%d' % (self.proto, self.host, self.port)
+ return 'http://%s:%d' % (self.host, self.port)
class SystemObject:
""" interface for system objects, represented in json format and
data and retcode """
s, r = self.command(cluster, cmd, args or [], **kwargs)
if r == 0:
- output = s.decode('utf-8')
- output = output[output.find('{'):] # trim extra output before json
- data = json.loads(output)
+ data = json.loads(s)
self.load_from_json(data)
self.data = data
return self.data, r
def tier_type(self):
raise NotImplementedError
+ def syncs_from(self, zone_name):
+ return zone_name != self.name
+
def has_buckets(self):
return True
+ def has_roles(self):
+ return True
+
def get_conn(self, credentials):
return ZoneConn(self, credentials) # not implemented, but can be used
if self.zone.gateways is not None:
self.conn = get_gateway_connection(self.zone.gateways[0], self.credentials)
+ self.secure_conn = get_gateway_secure_connection(self.zone.gateways[0], self.credentials)
+
+ self.iam_conn = get_gateway_iam_connection(self.zone.gateways[0], self.credentials)
+
+ # create connections for the rest of the gateways (if exist)
+ for gw in list(self.zone.gateways):
+ get_gateway_connection(gw, self.credentials)
+ get_gateway_secure_connection(gw, self.credentials)
+
+ get_gateway_iam_connection(gw, self.credentials)
+
def get_connection(self):
return self.conn
+ def get_iam_connection(self):
+ return self.iam_conn
+
def get_bucket(self, bucket_name, credentials):
raise NotImplementedError
return ['--access-key', self.access_key, '--secret', self.secret]
class User(SystemObject):
- def __init__(self, uid, data = None, name = None, credentials = None):
+ def __init__(self, uid, data = None, name = None, credentials = None, tenant = None):
self.name = name
self.credentials = credentials or []
+ self.tenant = tenant
super(User, self).__init__(data, uid)
def user_arg(self):
""" command-line argument to specify this user """
- return ['--uid', self.id]
+ args = ['--uid', self.id]
+ if self.tenant:
+ args += ['--tenant', self.tenant]
+ return args
def build_command(self, command):
""" build a command line for the given command and args """