import boto3
from boto.regioninfo import RegionInfo
-def get_gateway_connection(gateway, credentials):
+def get_gateway_connection(gateway, credentials, region):
""" connect to the given gateway """
# Always create a new connection to the gateway to ensure each set of credentials gets its own connection
- conn = boto.connect_s3(aws_access_key_id = credentials.access_key,
- aws_secret_access_key = credentials.secret,
- host = gateway.host,
- port = gateway.port,
- is_secure = False,
- calling_format = boto.s3.connection.OrdinaryCallingFormat())
+ conn = boto3.client('s3',
+ endpoint_url='http://' + gateway.host + ':' + str(gateway.port),
+ aws_access_key_id=credentials.access_key,
+ aws_secret_access_key=credentials.secret,
+ region_name=region)
if gateway.connection is None:
gateway.connection = conn
return conn
-def get_gateway_secure_connection(gateway, credentials):
+def get_gateway_secure_connection(gateway, credentials, region):
""" secure connect to the given gateway """
if gateway.ssl_port == 0:
return None
if gateway.secure_connection is None:
- gateway.secure_connection = boto.connect_s3(
- aws_access_key_id = credentials.access_key,
- aws_secret_access_key = credentials.secret,
- host = gateway.host,
- port = gateway.ssl_port,
- is_secure = True,
- validate_certs=False,
- calling_format = boto.s3.connection.OrdinaryCallingFormat())
+ gateway.secure_connection = boto3.client('s3',
+ endpoint_url='http://' + gateway.host + ':' + str(gateway.port),
+ aws_access_key_id=credentials.access_key,
+ aws_secret_access_key=credentials.secret,
+ region_name=region)
return gateway.secure_connection
def get_gateway_iam_connection(gateway, credentials, region):
return gateway.sts_connection
-def get_gateway_s3_client(gateway, credentials, region):
- """ connect to boto3 s3 client api of the given gateway """
- # Always create a new connection to the gateway to ensure each set of credentials gets its own connection
- s3_client = boto3.client('s3',
- endpoint_url='http://' + gateway.host + ':' + str(gateway.port),
- aws_access_key_id=credentials.access_key,
- aws_secret_access_key=credentials.secret,
- region_name=region)
- if gateway.s3_client is None:
- gateway.s3_client = s3_client
- return s3_client
-
-
def get_gateway_sns_client(gateway, credentials, region):
""" connect to boto3 s3 client api of the given gateway """
if gateway.sns_client is None:
import json
-from .conn import get_gateway_connection, get_gateway_iam_connection, get_gateway_secure_connection, get_gateway_s3_client, get_gateway_sns_client, get_gateway_sts_connection, get_gateway_temp_s3_client
+from .conn import get_gateway_connection, get_gateway_iam_connection, get_gateway_secure_connection, get_gateway_sns_client, get_gateway_sts_connection, get_gateway_temp_s3_client
class Cluster:
""" interface to run commands against a distinct ceph cluster """
self.secure_connection = None
self.ssl_port = ssl_port
self.iam_connection = None
- self.s3_client = None
self.sns_client = None
self.sts_connection = None
self.credentials = credentials
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)
-
region = "" if self.zone.zonegroup is None else self.zone.zonegroup.name
self.iam_conn = get_gateway_iam_connection(self.zone.gateways[0], self.credentials, region)
- self.s3_client = get_gateway_s3_client(self.zone.gateways[0], self.credentials, region)
+ self.conn = get_gateway_connection(self.zone.gateways[0], self.credentials, region)
+ self.secure_conn = get_gateway_connection(self.zone.gateways[0], self.credentials, region)
self.sns_client = get_gateway_sns_client(self.zone.gateways[0], self.credentials, region)
self.temp_s3_client = None
# 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_connection(gw, self.credentials, region)
+ get_gateway_secure_connection(gw, self.credentials, region)
get_gateway_iam_connection(gw, self.credentials, region)