added stubbed cassandra driver

This commit is contained in:
amitgandhinz 2014-02-13 17:09:41 -05:00
parent eb1809eaa1
commit e7aaab2214
8 changed files with 139 additions and 4 deletions

View File

@ -0,0 +1,6 @@
"""MongoDB Storage Driver for Marconi"""
from cdn.storage.cassandra import driver
# Hoist classes into package namespace
StorageDriver = driver.StorageDriver

View File

@ -0,0 +1,27 @@
# Copyright (c) 2013 Red Hat, 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 Cassandra storage 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 cdn.storage.cassandra import hosts
HostController = hosts.HostController

View File

@ -0,0 +1,60 @@
# 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.
"""Cassandra storage driver implementation."""
from cassandra.cluster import Cluster
from cdn.common import decorators
from cdn.openstack.common import log as logging
from cdn import storage
from cdn.storage.cassandra import controllers
from oslo.config import cfg
LOG = logging.getLogger(__name__)
CASSANDRA_OPTIONS = [
cfg.StrOpt('database', default='cdn', help='Database name'),
cfg.StrOpt('cluster', help='Cassandra Cluster contact points'),
cfg.StrOpt('keyspace', default='cdn',
help='Keyspace for all queries made in session'),
]
CASSANDRA_GROUP = 'drivers:storage:cassandra'
def _connection(conf):
cluster = Cluster(conf.cluster)
session = cluster.connect(conf.keyspace)
return session
class StorageDriver(storage.StorageDriverBase):
def __init__(self, conf):
super(StorageDriver, self).__init__(conf)
self.conf.register_opts(CASSANDRA_OPTIONS,
group=CASSANDRA_GROUP)
self.cassandra_conf = self.conf[CASSANDRA_GROUP]
def is_alive(self):
return True
@decorators.lazy_property(write=False)
def host_controller(self):
return controllers.HostController()

View File

@ -0,0 +1,43 @@
# 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.
# stevedore/example/simple.py
from cdn.storage import base
class HostController(base.HostBase):
def list(self):
hostnames = [
{
'hostname': 'www.mywebsite.com',
'description': 'My Sample Website using Cassandra'
},
{
'hostname': 'www.myotherwebsite.com',
'description': 'My Other Website'
}
]
return hostnames
def create(self):
print "create"
def delete(self):
print "delete"
def get(self):
print "get hostname"

View File

@ -20,11 +20,10 @@ from cdn.storage import base
class HostController(base.HostBase):
def list(self):
hostnames = [
{
'hostname': 'www.mywebsite.com',
'description': 'My Sample Website'
'description': 'My Sample Website using MongoDB'
},
{
'hostname': 'www.myotherwebsite.com',
@ -34,7 +33,6 @@ class HostController(base.HostBase):
return hostnames
def create(self):
print "create"

View File

@ -25,6 +25,5 @@ class HostsResource:
"""Handles GET requests
"""
hostnames = self.host_controller.list()
resp.status = falcon.HTTP_200
resp.body = json.dumps(hostnames)

View File

@ -7,6 +7,7 @@ jsonschema>=1.3.0,!=1.4.0
iso8601>=0.1.8
msgpack-python
pymongo>=2.4
cassandra-driver>=1.0.0
python-keystoneclient>=0.4.1
python-memcached
WebOb>=1.2.3,<1.3

View File

@ -31,6 +31,7 @@ cdn.transport =
cdn.storage =
mongodb = cdn.storage.mongodb.driver:StorageDriver
cassandra = cdn.storage.cassandra.driver:StorageDriver
[nosetests]