renamed hosts to services

This commit is contained in:
amitgandhinz
2014-06-17 17:33:42 -04:00
parent 58216e16d7
commit 2c5fa4f7db
20 changed files with 296 additions and 211 deletions

View File

@@ -4,5 +4,4 @@ from cdn.storage import base
# Hoist classes into package namespace
StorageDriverBase = base.StorageDriverBase
HostBase = base.HostBase
ServicesBase = base.ServicesBase

View File

@@ -19,8 +19,8 @@ import six
from oslo.config import cfg
_LIMITS_OPTIONS = [
cfg.IntOpt('default_hostname_paging', default=10,
help='Default hostname pagination size')
cfg.IntOpt('default_services_paging', default=10,
help='Default services pagination size')
]
_LIMITS_GROUP = 'limits:storage'
@@ -67,7 +67,7 @@ class StorageDriverBase(DriverBase):
raise NotImplementedError
@abc.abstractproperty
def host_controller(self):
def service_controller(self):
"""Returns the driver's hostname controller."""
raise NotImplementedError
@@ -84,14 +84,13 @@ class ControllerBase(object):
@six.add_metaclass(abc.ABCMeta)
class HostBase(ControllerBase):
"""This class is responsible for managing hostnames.
Hostname operations include CRUD, etc.
class ServicesBase(ControllerBase):
"""This class is responsible for managing Services
"""
__metaclass__ = abc.ABCMeta
def __init__(self, driver):
super(HostBase, self).__init__(driver)
super(ServicesBase, self).__init__(driver)
self.wrapper = ProviderWrapper()
@@ -119,12 +118,12 @@ class HostBase(ControllerBase):
class ProviderWrapper(object):
def create(self, ext, service_name, service_json):
return ext.obj.host_controller.create(service_name, service_json)
return ext.obj.service_controller.create(service_name, service_json)
def update(self, ext, service_name):
return ext.obj.host_controller.update(service_name)
return ext.obj.service_controller.update(service_name)
def delete(self, ext, service_name):
return ext.obj.host_controller.delete(service_name)
return ext.obj.service_controller.delete(service_name)

View File

@@ -23,6 +23,6 @@ Field Mappings:
updated and documented in each controller class.
"""
from cdn.storage.cassandra import hosts
from cdn.storage.cassandra import services
HostController = hosts.HostController
ServicesController = services.ServicesController

View File

@@ -61,9 +61,9 @@ class StorageDriver(storage.StorageDriverBase):
return _connection(self.cassandra_conf)
@decorators.lazy_property(write=False)
def host_controller(self):
return controllers.HostController(self)
def service_controller(self):
return controllers.ServicesController(self)
@decorators.lazy_property(write=False)
def host_database(self):
def service_database(self):
return self.connection

View File

@@ -1,80 +0,0 @@
# 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.
import uuid
from cdn.storage import base
CQL_CREATE_SERVICE = '''
INSERT INTO services (servicename, serviceid)
VALUES (%s, %s)
'''
class HostController(base.HostBase):
def __init__(self, *args, **kwargs):
super(HostController, self).__init__(*args, **kwargs)
self._session = self.driver.host_database
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 get(self):
# get the requested hostname from storage
print "get hostname"
def create(self, service_name, service_json):
# create the hostname in storage
service = service_json
"""Creates a new service"""
args = (service_name, uuid.uuid1())
res = self._session.execute(CQL_CREATE_SERVICE, args)
print "stored new record in cassandra"
# create at providers
providers = super(HostController, self).create(service_name, service)
return providers
def update(self, service_name, service_json):
# update configuration in storage
# update at providers
return super(HostController, self).update(service_name, service_json)
def delete(self, service_name):
# delete local configuration from storage
# delete from providers
return super(HostController, self).delete(service_name)

View File

@@ -0,0 +1,123 @@
# 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.
import uuid
from cdn.storage import base
CQL_CREATE_SERVICE = '''
INSERT INTO services (servicename, serviceid)
VALUES (%s, %s)
'''
class ServicesController(base.ServicesBase):
def __init__(self, *args, **kwargs):
super(ServicesController, self).__init__(*args, **kwargs)
self._session = self.driver.service_database
def list(self):
services = {
"links": [
{
"rel": "next",
"href": "/v1.0/services?marker=www.myothersite.com&limit=20"
}
],
"services" : [
{
"domains": [
{
"domain": "www.mywebsite.com"
}
],
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
}
],
"caching": [
{ "name" : "default", "ttl" : 3600 },
{
"name" : "home",
"ttl" : 17200,
"rules" : [
{ "name" : "index", "request_url" : "/index.htm" }
]
},
{
"name" : "images",
"ttl" : 12800,
"rules" : [
{ "name" : "images", "request_url" : "*.png" }
]
}
],
"restrictions" : [
{
"name" : "website only",
"rules" : [ { "name" : "mywebsite.com", "http_host" : "www.mywebsite.com" } ]
}
],
"links" : [
{
"href": "/v1.0/services/mywebsite",
"rel" : "self"
}
]
}
]
}
return services
def get(self):
# get the requested service from storage
print "get service"
def create(self, service_name, service_json):
# create the service in storage
service = service_json
"""Creates a new service"""
args = (service_name, uuid.uuid1())
res = self._session.execute(CQL_CREATE_SERVICE, args)
print "stored new record in cassandra"
# create at providers
providers = super(ServicesController, self).create(service_name, service)
return providers
def update(self, service_name, service_json):
# update configuration in storage
# update at providers
return super(ServicesController, self).update(service_name, service_json)
def delete(self, service_name):
# delete local configuration from storage
# delete from providers
return super(ServicesController, self).delete(service_name)

View File

@@ -24,4 +24,4 @@ Field Mappings:
from cdn.storage.mongodb import hosts
HostController = hosts.HostController
ServicesController = servicess.ServicesController

View File

@@ -79,21 +79,23 @@ class StorageDriver(storage.StorageDriverBase):
except pymongo.errors.PyMongoError:
return False
@decorators.lazy_property(write=False)
def host_database(self):
"""Database dedicated to the "host" collection.
The host collection is separated out into its own database.
"""
name = self.mongodb_conf.database + '_host'
return self.connection[name]
@decorators.lazy_property(write=False)
def connection(self):
"""MongoDB client connection instance."""
return _connection(self.mongodb_conf)
@decorators.lazy_property(write=False)
def host_controller(self):
return controllers.HostController(self.providers)
def service_controller(self):
return controllers.ServicesController(self.providers)
@decorators.lazy_property(write=False)
def service_database(self):
"""Database dedicated to the "services" collection.
The services collection is separated out into its own database.
"""
name = self.mongodb_conf.database + '_services'
return self.connection[name]

View File

@@ -1,60 +0,0 @@
# 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 Mongo'
},
{
'hostname': 'www.myotherwebsite.com',
'description': 'My Other Website'
}
]
return hostnames
def get(self):
# get the requested hostname from storage
print "get hostname"
def create(self, service_name, service_json):
# create the hostname in storage
service = service_json
# create at providers
return super(HostController, self).create(service_name, service)
def update(self, service_name, service_json):
# update configuration in storage
# update at providers
return super(HostController, self).update(service_name, service_json)
def delete(self, service_name):
# delete local configuration from storage
# delete from providers
return super(HostController, self).delete(service_name)

View File

@@ -0,0 +1,103 @@
# 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 ServicesController(base.ServicesBase):
def list(self):
services = {
"links": [
{
"rel": "next",
"href": "/v1.0/services?marker=www.myothersite.com&limit=20"
}
],
"services" : [
{
"domains": [
{
"domain": "www.mywebsite.com"
}
],
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
}
],
"caching": [
{ "name" : "default", "ttl" : 3600 },
{
"name" : "home",
"ttl" : 17200,
"rules" : [
{ "name" : "index", "request_url" : "/index.htm" }
]
},
{
"name" : "images",
"ttl" : 12800,
"rules" : [
{ "name" : "images", "request_url" : "*.png" }
]
}
],
"restrictions" : [
{
"name" : "website only",
"rules" : [ { "name" : "mywebsite.com", "http_host" : "www.mywebsite.com" } ]
}
],
"links" : [
{
"href": "/v1.0/services/mywebsite",
"rel" : "self"
}
]
}
]
}
return services
def get(self):
# get the requested service from storage
print "get service"
def create(self, service_name, service_json):
# create the service in storage
service = service_json
# create at providers
return super(ServicesController, self).create(service_name, service)
def update(self, service_name, service_json):
# update configuration in storage
# update at providers
return super(ServicesController, self).update(service_name, service_json)
def delete(self, service_name):
# delete local configuration from storage
# delete from providers
return super(ServicesController, self).delete(service_name)