Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions libcloud/storage/drivers/rgw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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 libcloud.common.types import LibcloudError

from libcloud.storage.drivers.s3 import BaseS3Connection, S3Connection,\
S3StorageDriver, API_VERSION

from libcloud.common.aws import SignedAWSConnection, DEFAULT_SIGNATURE_VERSION

S3_RGW_DEFAULT_REGION = 'default'

S3_RGW_OUTSCALE_HOSTS_BY_REGION =\
{'eu-west-1': 'osu.eu-west-1.outscale.com',
'eu-west-2': 'osu.eu-west-2.outscale.com',
'us-west-1': 'osu.us-west-1.outscale.com',
'us-east-2': 'osu.us-east-2.outscale.com',
'cn-southeast-1': 'osu.cn-southeast-1.outscale.hk'}

S3_RGW_OUTSCALE_DEFAULT_REGION = 'eu-west-2'


class S3RGWConnectionAWS4(SignedAWSConnection, BaseS3Connection):
service_name = 's3'
version = API_VERSION

def __init__(self, user_id, key, secure=True, host=None, port=None,
url=None, timeout=None, proxy_url=None, token=None,
retry_delay=None, backoff=None, **kwargs):

super(S3RGWConnectionAWS4, self).__init__(user_id, key,
secure, host,
port, url,
timeout,
proxy_url, token,
retry_delay,
backoff,
4) # force aws4


class S3RGWConnectionAWS2(S3Connection):

def __init__(self, user_id, key, secure=True, host=None, port=None,
url=None, timeout=None, proxy_url=None, token=None,
retry_delay=None, backoff=None, **kwargs):

super(S3RGWConnectionAWS2, self).__init__(user_id, key,
secure, host,
port, url,
timeout,
proxy_url, token,
retry_delay,
backoff)


class S3RGWStorageDriver(S3StorageDriver):

def __init__(self, key, secret=None, secure=True, host=None, port=None,
api_version=None, region=S3_RGW_DEFAULT_REGION, **kwargs):
if host is None:
raise LibcloudError('host required', driver=self)
self.name = 'Ceph RGW S3 (%s)' % (region)
self.ex_location_name = region
self.region_name = region

self.signature_version = str(kwargs.pop('signature_version',
DEFAULT_SIGNATURE_VERSION))

if self.signature_version not in ['2', '4']:
raise ValueError('Invalid signature_version: %s' %
(self.signature_version))

if self.signature_version == '2':
self.connectionCls = S3RGWOutscaleConnectionAWS2
elif self.signature_version == '4':
self.connectionCls = S3RGWOutscaleConnectionAWS4
self.connectionCls.host = host
super(S3RGWStorageDriver, self).__init__(key, secret,
secure, host, port,
api_version, region,
**kwargs)

def _ex_connection_class_kwargs(self):
kwargs = {}
kwargs['signature_version'] = self.signature_version
return kwargs


class S3RGWOutscaleConnectionAWS4(S3RGWConnectionAWS4):
pass


class S3RGWOutscaleConnectionAWS2(S3RGWConnectionAWS2):
pass


class S3RGWOutscaleStorageDriver(S3RGWStorageDriver):

def __init__(self, key, secret=None, secure=True, host=None, port=None,
api_version=None, region=S3_RGW_OUTSCALE_DEFAULT_REGION,
**kwargs):
if region not in S3_RGW_OUTSCALE_HOSTS_BY_REGION:
raise LibcloudError('Unknown region (%s)' % (region), driver=self)

self.name = 'OUTSCALE Ceph RGW S3 (%s)' % (region)
self.ex_location_name = region
self.region_name = region
self.signature_version = str(kwargs.pop('signature_version',
DEFAULT_SIGNATURE_VERSION))

if self.signature_version not in ['2', '4']:
raise ValueError('Invalid signature_version: %s' %
(self.signature_version))

if self.signature_version == '2':
self.connectionCls = S3RGWOutscaleConnectionAWS2
elif self.signature_version == '4':
self.connectionCls = S3RGWOutscaleConnectionAWS4

host = S3_RGW_OUTSCALE_HOSTS_BY_REGION[region]
self.connectionCls.host = host
super(S3RGWStorageDriver, self).__init__(key, secret,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should pass S3RGWOutscaleStorageDriver as the first argument to super(). This will fix pylint issue.

secure, host, port,
api_version, region,
**kwargs)
80 changes: 1 addition & 79 deletions libcloud/storage/drivers/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from libcloud.common.types import InvalidCredsError, LibcloudError
from libcloud.common.base import ConnectionUserAndKey, RawResponse
from libcloud.common.aws import AWSBaseResponse, AWSDriver, \
AWSTokenConnection, SignedAWSConnection, DEFAULT_SIGNATURE_VERSION
AWSTokenConnection, SignedAWSConnection

from libcloud.storage.base import Object, Container, StorageDriver
from libcloud.storage.types import ContainerError
Expand All @@ -60,15 +60,6 @@
S3_AP_NORTHEAST_HOST = S3_AP_NORTHEAST1_HOST
S3_SA_EAST_HOST = 's3-sa-east-1.amazonaws.com'

S3_RGW_OUTSCALE_HOSTS_BY_REGION =\
{'eu-west-1': 'osu.eu-west-1.outscale.com',
'eu-west-2': 'osu.eu-west-2.outscale.com',
'us-west-1': 'osu.us-west-1.outscale.com',
'us-east-2': 'osu.us-east-2.outscale.com',
'cn-southeast-1': 'osu.cn-southeast-1.outscale.hk'}

S3_RGW_OUTSCALE_DEFAULT_REGION = 'eu-west-2'

API_VERSION = '2006-03-01'
NAMESPACE = 'http://s3.amazonaws.com/doc/%s/' % (API_VERSION)

Expand Down Expand Up @@ -1013,72 +1004,3 @@ class S3SAEastStorageDriver(S3StorageDriver):
name = 'Amazon S3 (sa-east-1)'
connectionCls = S3SAEastConnection
ex_location_name = 'sa-east-1'


class S3RGWOutscaleConnectionAWS4(SignedAWSConnection, BaseS3Connection):
service_name = 's3'
version = API_VERSION

def __init__(self, user_id, key, secure=True, host=None, port=None,
url=None, timeout=None, proxy_url=None, token=None,
retry_delay=None, backoff=None, **kwargs):

super(S3RGWOutscaleConnectionAWS4, self).__init__(user_id, key,
secure, host,
port, url,
timeout,
proxy_url, token,
retry_delay,
backoff,
4) # force aws4


class S3RGWOutscaleConnectionAWS2(S3Connection):

def __init__(self, user_id, key, secure=True, host=None, port=None,
url=None, timeout=None, proxy_url=None, token=None,
retry_delay=None, backoff=None, **kwargs):

super(S3RGWOutscaleConnectionAWS2, self).__init__(user_id, key,
secure, host,
port, url,
timeout,
proxy_url, token,
retry_delay,
backoff)


class S3RGWOutscaleStorageDriver(S3StorageDriver):

def __init__(self, key, secret=None, secure=True, host=None, port=None,
api_version=None, region=S3_RGW_OUTSCALE_DEFAULT_REGION,
**kwargs):
if region not in S3_RGW_OUTSCALE_HOSTS_BY_REGION:
raise LibcloudError('Unknown region (%s)' % (region), driver=self)

self.name = 'OUTSCALE Ceph RGW S3 (%s)' % (region)
self.ex_location_name = region
self.region_name = region
self.signature_version = str(kwargs.pop('signature_version',
DEFAULT_SIGNATURE_VERSION))

if self.signature_version not in ['2', '4']:
raise ValueError('Invalid signature_version: %s' %
(self.signature_version))

if self.signature_version == '2':
self.connectionCls = S3RGWOutscaleConnectionAWS2
elif self.signature_version == '4':
self.connectionCls = S3RGWOutscaleConnectionAWS4

host = S3_RGW_OUTSCALE_HOSTS_BY_REGION[region]
self.connectionCls.host = host
super(S3RGWOutscaleStorageDriver, self).__init__(key, secret,
secure, host, port,
api_version, region,
**kwargs)

def _ex_connection_class_kwargs(self):
kwargs = {}
kwargs['signature_version'] = self.signature_version
return kwargs
4 changes: 3 additions & 1 deletion libcloud/storage/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
('libcloud.storage.drivers.s3', 'S3APNE2StorageDriver'),
Provider.S3_SA_EAST:
('libcloud.storage.drivers.s3', 'S3SAEastStorageDriver'),
Provider.S3_RGW:
('libcloud.storage.drivers.rgw', 'S3RGWStorageDriver'),
Provider.S3_RGW_OUTSCALE:
('libcloud.storage.drivers.s3', 'S3RGWOutscaleStorageDriver'),
('libcloud.storage.drivers.rgw', 'S3RGWOutscaleStorageDriver'),
Provider.NINEFOLD:
('libcloud.storage.drivers.ninefold', 'NinefoldStorageDriver'),
Provider.GOOGLE_STORAGE:
Expand Down
6 changes: 4 additions & 2 deletions libcloud/storage/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class Provider(object):
:cvar S3_AP_NORTHEAST_HOST: Amazon S3 Asia South East (Tokyo)
:cvar S3_AP_SOUTHEAST_HOST: Amazon S3 Asia South East (Singapore)
:cvar S3_EU_WEST: Amazon S3 EU West (Ireland)
:cvar S3_RGW_OUTSCALE: OUTSCALE RGW S3
:cvar S3_US_WEST: Amazon S3 US West (Northern California)
:cvar S3_US_WEST_OREGON: Amazon S3 US West 2 (Oregon)
:cvar S3_RGW: S3 RGW
:cvar S3_RGW_OUTSCALE: OUTSCALE S3 RGW
"""
DUMMY = 'dummy'
ALIYUN_OSS = 'aliyun_oss'
Expand All @@ -71,10 +72,11 @@ class Provider(object):
S3_AP_NORTHEAST2 = 's3_ap_northeast_2'
S3_AP_SOUTHEAST = 's3_ap_southeast'
S3_EU_WEST = 's3_eu_west'
S3_RGW_OUTSCALE = 's3_rgw_outscale'
S3_SA_EAST = 's3_sa_east'
S3_US_WEST = 's3_us_west'
S3_US_WEST_OREGON = 's3_us_west_oregon'
S3_RGW = 's3_rgw'
S3_RGW_OUTSCALE = 's3_rgw_outscale'

# Deperecated
CLOUDFILES_US = 'cloudfiles_us'
Expand Down