Adds support for CloudFront provider
Change-Id: Ib7cde6525242041a244ce6f6e3b866b365582cc0
This commit is contained in:
committed by
Obulpathi
parent
a28b9c78d1
commit
a6ab9e8612
21
poppy/provider/cloudfront/__init__.py
Normal file
21
poppy/provider/cloudfront/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2014 Rackspace, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""CloudFront CDN Extension for CDN"""
|
||||
|
||||
from poppy.provider.cloudfront import driver
|
||||
|
||||
# Hoist classes into package namespace
|
||||
Driver = driver.CDNProvider
|
||||
27
poppy/provider/cloudfront/controllers.py
Normal file
27
poppy/provider/cloudfront/controllers.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Copyright (c) 2014 Rackspace, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Exports CloudFront CDN controllers.
|
||||
|
||||
Field Mappings:
|
||||
In order to reduce the disk / memory space used,
|
||||
fields name will be, most of the time, the first
|
||||
letter of their long name. Fields mapping will be
|
||||
updated and documented in each controller class.
|
||||
"""
|
||||
|
||||
from poppy.provider.cloudfront import services
|
||||
|
||||
ServiceController = services.ServiceController
|
||||
59
poppy/provider/cloudfront/driver.py
Normal file
59
poppy/provider/cloudfront/driver.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2014 Rackspace, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""CloudFront CDN Provider implementation."""
|
||||
|
||||
import boto
|
||||
from oslo.config import cfg
|
||||
|
||||
from poppy.openstack.common import log as logging
|
||||
from poppy.provider import base
|
||||
from poppy.provider.cloudfront import controllers
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
CLOUDFRONT_OPTIONS = [
|
||||
cfg.StrOpt('aws_access_key_id', help='CloudFront Access Key ID'),
|
||||
cfg.StrOpt('aws_secret_access_key', help='CloudFront Secret Acces Key'),
|
||||
]
|
||||
|
||||
CLOUDFRONT_GROUP = 'drivers:provider:cloudfront'
|
||||
|
||||
|
||||
class CDNProvider(base.Driver):
|
||||
|
||||
def __init__(self, conf):
|
||||
super(CDNProvider, self).__init__(conf)
|
||||
|
||||
self._conf.register_opts(CLOUDFRONT_OPTIONS, group=CLOUDFRONT_GROUP)
|
||||
self.cloudfront_conf = self._conf[CLOUDFRONT_GROUP]
|
||||
self.cloudfront_client = boto.connect_cloudfront(
|
||||
aws_access_key_id=self.cloudfront_conf.aws_access_key_id,
|
||||
aws_secret_access_key=self.cloudfront_conf.aws_secret_access_key)
|
||||
|
||||
def is_alive(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def provider_name(self):
|
||||
return 'CloudFront'
|
||||
|
||||
def client(self):
|
||||
return self.cloudfront_client
|
||||
|
||||
@property
|
||||
def service_controller(self):
|
||||
return controllers.ServiceController(self)
|
||||
70
poppy/provider/cloudfront/services.py
Normal file
70
poppy/provider/cloudfront/services.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# Copyright (c) 2014 Rackspace, Inc.
|
||||
#
|
||||
# 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 boto import cloudfront
|
||||
|
||||
from poppy.provider import base
|
||||
|
||||
|
||||
class ServiceController(base.ServiceBase):
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
return self.driver.client
|
||||
|
||||
def __init__(self, driver):
|
||||
super(ServiceController, self).__init__(driver)
|
||||
|
||||
self.driver = driver
|
||||
self.current_customer = self.client.get_current_customer()
|
||||
|
||||
# TODO(obulpathi): get service
|
||||
def get(self, service_name):
|
||||
return {'domains': [], 'origins': [], 'caching': []}
|
||||
|
||||
# TODo(obulpathi): update service
|
||||
def update(self, service_name, service_json):
|
||||
return self.responder.updated(service_name)
|
||||
|
||||
def create(self, service_name, service_json):
|
||||
# TODO(obulpathi): create a single distribution for multiple origins
|
||||
origin = service_json['origins'][0]
|
||||
try:
|
||||
# Create the origin for this domain:
|
||||
aws_origin = cloudfront.origin.CustomOrigin(
|
||||
dns_name=origin['origin'],
|
||||
http_port=origin['port'],
|
||||
https_port=origin['ssl'],
|
||||
origin_protocol_policy='match-viewer')
|
||||
distribution = self.client.create_distribution(
|
||||
origin=aws_origin,
|
||||
enabled=True)
|
||||
except cloudfront.exception.CloudFrontServerError as e:
|
||||
return self.responder.failed(str(e))
|
||||
except Exception as e:
|
||||
return self.responder.failed(str(e))
|
||||
|
||||
links = [{'href': distribution.domain_name, 'rel': 'access_url'}]
|
||||
return self.responder.created(distribution.id, links)
|
||||
|
||||
def delete(self, service_name):
|
||||
# NOTE(obulpathi): distribution_id is the equivalent of service_name
|
||||
distribution_id = service_name
|
||||
try:
|
||||
self.client.delete_distribution(distribution_id)
|
||||
|
||||
return self.responder.deleted(distribution_id)
|
||||
except Exception as e:
|
||||
return self.responder.failed(str(e))
|
||||
Reference in New Issue
Block a user