Porting Tenant API models and configuration

Change-Id: I657ab4c77a279f9f825777d39baad3688c37e396
This commit is contained in:
John Vrbanac
2013-04-23 16:05:43 -05:00
parent bdd4a02fc2
commit 87fa3f6d5a
18 changed files with 1071 additions and 0 deletions

1
.gitignore vendored
View File

@@ -28,3 +28,4 @@ pip-log.txt
# IDE Project Files
*.project
*.pydev*
*.idea

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,141 @@
"""
Copyright 2013 Rackspace
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 json import dumps as json_to_str
from cafe.engine.models.base import AutoMarshallingModel
class SystemInfo(AutoMarshallingModel):
def __init__(self, disk_usage=None, os_type=None, memory_mb=None,
architecture=None, cpu_cores=None, load_average=None):
super(SystemInfo, self).__init__()
self.os_type = os_type
self.memory_mb = memory_mb
self.architecture = architecture
self.cpu_cores = cpu_cores
self.load_average = load_average
self.disk_usage = disk_usage
def _obj_to_dict(self):
body = {
'os_type': self.os_type,
'memory_mb': self.memory_mb,
'architecture': self.architecture,
'cpu_cores': self.cpu_cores,
'load_average': self.load_average,
'disk_usage': self.disk_usage._obj_to_dict()
}
return body
def _obj_to_json(self):
return json_to_str(self._obj_to_dict())
@classmethod
def _dict_to_obj(cls, dic):
disk_usage = DiskUsage._dict_to_obj(dic.get('disk_usage'))
load_average = LoadAverage._dict_to_obj(dic.get('load_average'))
kwargs = {
'os_type': dic.get('os_type'),
'memory_mb': dic.get('memory_mb'),
'architecture': dic.get('architecture'),
'cpu_cores': dic.get('cpu_cores'),
'disk_usage': disk_usage,
'load_average': load_average
}
return SystemInfo(**kwargs)
class LoadAverage(AutoMarshallingModel):
def __init__(self, one_average=None, five_average=None,
fifteen_average=None):
super(LoadAverage, self).__init__()
self.one_average = one_average
self.five_average = five_average
self.fifteen_average = fifteen_average
def _obj_to_json(self):
body = {
'load_average': {
'1': self.one_average,
'5': self.five_average,
'15': self.fifteen_average
}
}
return json_to_str(body)
@classmethod
def _dict_to_obj(cls, dic):
kwargs = {
'one_average': dic.get('1'),
'five_average': dic.get('5'),
'fifteen_average': dic.get('5')
}
return LoadAverage(**kwargs)
class DiskUsage(AutoMarshallingModel):
def __init__(self):
super(DiskUsage, self).__init__()
self.disks = []
def add_disk(self, partition):
if partition is not None:
self.disks.append(partition)
def _obj_to_dict(self):
body = {}
for disk in self.disks:
key = disk.keys()[0]
body[key] = disk[key]
return body
def _obj_to_json(self):
return json_to_str(self._obj_to_dict())
@classmethod
def _dict_to_obj(cls, json_dict):
usage = DiskUsage()
for disk in json_dict:
part = Partition(name=disk,
used=json_dict[disk]['used'],
total=json_dict[disk]['total'])
usage.add_disk(part)
return usage
class Partition(AutoMarshallingModel):
def __init__(self, name=None, total=None, used=None):
super(Partition, self).__init__()
self.name = name
self.total = total
self.used = used
def _obj_to_dict(self):
body = {self.name: {
'total': self.total,
'used': self.used
}}
return body
def _obj_to_json(self):
return json_to_str(self._obj_to_dict())

View File

@@ -0,0 +1,77 @@
"""
Copyright 2013 Rackspace
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 cloudcafe.common.models.configuration import ConfigSectionInterface
class MarshallingConfig(ConfigSectionInterface):
SECTION_NAME = 'marshalling'
@property
def serializer(self):
return self.get("serializer")
@property
def deserializer(self):
return self.get("deserializer")
class MeniscusConfig(ConfigSectionInterface):
SECTION_NAME = 'meniscus'
@property
def base_url(self):
return self.get("base_url")
@property
def api_version(self):
return self.get("api_version")
class TenantConfig(ConfigSectionInterface):
SECTION_NAME = 'meniscus-tenant'
@property
def hostname(self):
return self.get("hostname")
@property
def ip_address_v4(self):
return self.get("ip_address_v4")
@property
def ip_address_v6(self):
return self.get("ip_address_v6")
@property
def producer_name(self):
return self.get("producer_name")
@property
def producer_pattern(self):
return self.get("producer_pattern")
@property
def producer_durable(self):
return self.get_boolean("producer_durable")
@property
def producer_encrypted(self):
return self.get_boolean("producer_encrypted")
@property
def profile_name(self):
return self.get("profile_name")

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,312 @@
"""
Copyright 2013 Rackspace
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 cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.meniscus.tenant_api.models.tenant import Tenant, CreateTenant
from cloudcafe.meniscus.tenant_api.models.producer import \
CreateProducer, UpdateProducer, AllProducers, Producer
from cloudcafe.meniscus.tenant_api.models.profile import \
CreateProfile, UpdateProfile, AllProfiles, Profile
from cloudcafe.meniscus.tenant_api.models.host import \
CreateHost, UpdateHost, AllHosts, Host
class TenantClient(AutoMarshallingRestClient):
def __init__(self, url, api_version, serialize_format=None,
deserialize_format=None):
"""
@param url: Base URL of meniscus api
@type url: String
"""
super(TenantClient, self).__init__(serialize_format,
deserialize_format)
self.url = url
self.api_version = api_version
def create_tenant(self, tenant_id):
"""
@summary: Creates a tenant with the given id
@param tenant_id:
"""
url = '{base}/{version}'.format(base=self.url,
version=self.api_version)
resp = self.request('POST', url,
request_entity=CreateTenant(tenant_id))
return resp
def get_tenant(self, tenant_id):
"""
@summary: Retrieves the version information from the API
"""
url = '{base}/{version}/{tenant_id}'.format(
base=self.url,
version=self.api_version,
tenant_id=tenant_id)
resp = self.request('GET', url, response_entity_type=Tenant)
return resp
class ProducerClient(AutoMarshallingRestClient):
def __init__(self, url, api_version, tenant_id, serialize_format=None,
deserialize_format=None):
super(ProducerClient, self).__init__(serialize_format,
deserialize_format)
self.url = url
self.api_version = api_version
self.tenant_id = tenant_id
def _generate_producer_url(self, producer_id):
remote_url = '{base}/{version}/{tenant_id}/producers/{producer_id}'\
.format(base=self.url,
version=self.api_version,
tenant_id=self.tenant_id,
producer_id=producer_id)
return remote_url
def create_producer(self, name=None, pattern=None,
durable=None, encrypted=None):
"""
POST /{api_version}/{tenant_id}/producers
@summary: Creates a new producer on a tenant
"""
request_producer = CreateProducer(
producer_name=name,
producer_pattern=pattern,
producer_durable=durable,
producer_encrypted=encrypted)
url = '{base}/{version}/{tenant_id}/producers'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
producer_request = self.request('POST', url,
request_entity=request_producer)
return producer_request
def delete_producer(self, producer_id):
"""
DELETE /{app_version}/{tenant_id}/producers/{producer_id}
@summary: Removes a producer from a tenant
"""
remote_url = self._generate_producer_url(producer_id)
response = self.request('DELETE', remote_url)
return response
def update_producer(self, producer_id, name=None, pattern=None,
durable=None, encrypted=None):
"""
PUT /{app_version}/{tenant_id}/producers/{producer_id}
@summary: Updates a producer
"""
producer_obj = UpdateProducer(producer_name=name,
producer_pattern=pattern,
producer_durable=durable,
producer_encrypted=encrypted)
remote_url = self._generate_producer_url(producer_id)
response = self.request('PUT', remote_url, request_entity=producer_obj)
return response
def get_producer(self, producer_id):
"""
GET /{app_version}/{tenant_id}/producers/{producer_id}
@summary: Retrieves a Producer on a tenant
"""
remote_url = self._generate_producer_url(producer_id)
response = self.request('GET', remote_url,
response_entity_type=Producer)
return response
def get_all_producers(self):
"""
GET /{app_version}/{tenant_id}/producers
@summary: Retrieves all producers on a given tenants
"""
remote_url = '{base}/{version}/{tenant_id}/producers'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
response = self.request('GET', remote_url,
response_entity_type=AllProducers)
return response
class ProfileClient(AutoMarshallingRestClient):
def __init__(self, url, api_version, tenant_id, producer_id,
serialize_format=None, deserialize_format=None):
super(ProfileClient, self).__init__(serialize_format,
deserialize_format)
self.url = url
self.api_version = api_version
self.tenant_id = tenant_id
self.producer_id = producer_id
def _generate_profile_url(self, profile_id):
remote_url = '{base}/{version}/{tenant_id}/profiles/{profile_id}'\
.format(base=self.url,
version=self.api_version,
tenant_id=self.tenant_id,
profile_id=profile_id)
return remote_url
def create_profile(self, name=None, producer_ids=None):
"""
POST /{app_version}/{tenant_id}/profiles
@summary: Creates a profile on a tenant
"""
request_profile = CreateProfile(name=name,
producer_ids=producer_ids)
url = '{base}/{version}/{tenant_id}/profiles'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
profile_request = self.post(url, request_entity=request_profile)
return profile_request
def get_profile(self, profile_id):
"""
GET /{app_version}/{tenant_id}/profiles/{profile_id}
@summary: Retrieves a profile from a tenant
"""
remote_url = self._generate_profile_url(profile_id)
response = self.request('GET', remote_url,
response_entity_type=Profile)
return response
def get_all_profiles(self):
"""
GET /{app_version}/{tenant_id}/profiles
@summary: Retrieves all profiles from a tenant
"""
remote_url = '{base}/{version}/{tenant_id}/profiles'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
response = self.request('GET', remote_url,
response_entity_type=AllProfiles)
return response
def delete_profile(self, profile_id):
"""
DELETE /{app_version}/{tenant_id}/profiles/{profile_id}
@summary: Removes a profile from a tenant
"""
remote_url = self._generate_profile_url(profile_id)
response = self.request('DELETE', remote_url)
return response
def update_profile(self, id, name=None, producer_ids=None):
"""
PUT /{app_version}/{tenant_id}/profiles/{profile_id}
@summary: Updates a profile on a tenant
"""
profile_obj = UpdateProfile(name=name, producer_ids=producer_ids)
remote_url = self._generate_profile_url(id)
response = self.request('PUT', remote_url, request_entity=profile_obj)
return response
class HostClient(AutoMarshallingRestClient):
def __init__(self, url, api_version, tenant_id, profile_id,
serialize_format=None, deserialize_format=None):
super(HostClient, self).__init__(serialize_format,
deserialize_format)
self.url = url
self.api_version = api_version
self.tenant_id = tenant_id
self.profile_id = profile_id
def _generate_host_url(self, host_id):
remote_url = '{base}/{version}/{tenant_id}/hosts/{host_id}'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id,
host_id=host_id)
return remote_url
def create_host(self, hostname, ip_v4, ip_v6, profile_id):
"""
POST /{app_version}/{tenant_id}/hosts
@summary: Creates a new host on a tenant
"""
remote_url = '{base}/{version}/{tenant_id}/hosts'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
host = CreateHost(hostname, profile_id, ip_v4, ip_v6)
response = self.request('POST', remote_url, request_entity=host)
return response
def get_host(self, host_id):
"""
GET /{app_version}/{tenant_id}/hosts/{host_id}
@summary: Retrieves a host from a tenant
"""
remote_url = self._generate_host_url(host_id)
response = self.request('GET', remote_url,
response_entity_type=Host)
return response
def get_all_hosts(self):
"""
GET /{app_version}/{tenant_id}/hosts
@summary: Retrieves all hosts from a tenant
"""
remote_url = '{base}/{version}/{tenant_id}/hosts'.format(
base=self.url,
version=self.api_version,
tenant_id=self.tenant_id)
response = self.request('GET', remote_url,
response_entity_type=AllHosts)
return response
def update_host(self, host_id, hostname=None, ip_v4=None, ip_v6=None,
profile_id=None):
"""
PUT /{app_version}/{tenant_id}/hosts/{host_id}
@summary: Update a single host on a tenant
"""
remote_url = self._generate_host_url(host_id)
host = UpdateHost(hostname, profile_id, ip_v4, ip_v6)
response = self.request('PUT', remote_url, request_entity=host)
return response
def delete_host(self, host_id):
"""
DELETE /{app_version}/{tenant_id}/hosts/{host_id}
@summary: Removes a host from a tenant
"""
remote_url = self._generate_host_url(host_id)
response = self.request('DELETE', remote_url)
return response

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,83 @@
"""
Copyright 2013 Rackspace
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 json import dumps as json_to_str, loads as str_to_json
from cafe.engine.models.base import AutoMarshallingModel
class UpdateHost(AutoMarshallingModel):
def __init__(self, hostname=None, profile_id=None, ip_address_v4=None,
ip_address_v6=None):
super(UpdateHost, self).__init__()
self.hostname = hostname
self.ip_address_v4 = ip_address_v4
self.ip_address_v6 = ip_address_v6
self.profile_id = profile_id
def _obj_to_json(self):
body = self._auto_to_dict()
return json_to_str(body)
# Create requires all parameters, whereas update they are optional
class CreateHost(UpdateHost):
def __init__(self, hostname, profile_id, ip_address_v4,
ip_address_v6):
super(CreateHost, self).__init__(hostname, profile_id, ip_address_v4,
ip_address_v6)
class Host(AutoMarshallingModel):
ROOT_TAG = 'host'
def __init__(self, ip_address_v6=None, profile=None, ip_address_v4=None,
hostname=None, id=None):
super(Host, self).__init__()
self.ip_address_v6 = ip_address_v6
self.ip_address_v4 = ip_address_v4
self.profile = profile
self.hostname = hostname
self.id = id
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
return cls._dict_to_obj(json_dict.get(cls.ROOT_TAG))
@classmethod
def _dict_to_obj(cls, json_dict):
return Host(**json_dict)
class AllHosts(AutoMarshallingModel):
ROOT_TAG = 'hosts'
def __init__(self):
super(AllHosts, self).__init__()
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
converted = []
json_producer_list = json_dict.get(cls.ROOT_TAG)
for json_producer in json_producer_list:
producer = Host._dict_to_obj(json_producer)
converted.append(producer)
return converted

View File

@@ -0,0 +1,86 @@
"""
Copyright 2013 Rackspace
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 json import dumps as json_to_str, loads as str_to_json
from cafe.engine.models.base import AutoMarshallingModel
class UpdateProducer(AutoMarshallingModel):
def __init__(self, producer_name=None, producer_pattern=None,
producer_durable=None, producer_encrypted=None):
super(UpdateProducer, self).__init__()
# Making all of these conditional for _auto_to_dict()
if producer_name is not None:
self.name = producer_name
if producer_pattern is not None:
self.pattern = producer_pattern
if producer_durable is not None:
self.durable = producer_durable
if producer_encrypted is not None:
self.encrypted = producer_encrypted
def _obj_to_json(self):
body = self._auto_to_dict()
return json_to_str(body)
# Create requires all parameters, whereas update they are optional
class CreateProducer(UpdateProducer):
def __init__(self, producer_name, producer_pattern,
producer_durable, producer_encrypted):
super(CreateProducer, self).__init__(producer_name, producer_pattern,
producer_durable,
producer_encrypted)
class Producer(AutoMarshallingModel):
ROOT_TAG = 'event_producer'
def __init__(self, pattern=None, durable=None, encrypted=None, id=None,
name=None):
super(Producer, self).__init__()
self.pattern = pattern
self.durable = durable
self.encrypted = encrypted
self.id = id
self.name = name
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
return cls._dict_to_obj(json_dict.get(cls.ROOT_TAG))
@classmethod
def _dict_to_obj(cls, json_dict):
return Producer(**json_dict)
class AllProducers(AutoMarshallingModel):
ROOT_TAG = 'event_producers'
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
converted = []
json_producer_list = json_dict.get(cls.ROOT_TAG)
for json_producer in json_producer_list:
producer = Producer._dict_to_obj(json_producer)
converted.append(producer)
return converted

View File

@@ -0,0 +1,78 @@
"""
Copyright 2013 Rackspace
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 json import dumps as json_to_str, loads as str_to_json
from cafe.engine.models.base import AutoMarshallingModel
class UpdateProfile(AutoMarshallingModel):
def __init__(self, name=None, producer_ids=None):
super(UpdateProfile, self).__init__()
if name is not None:
self.name = name
if producer_ids is not None:
self.producer_ids = producer_ids
def _obj_to_json(self):
body = self._auto_to_dict()
return json_to_str(body)
# Create requires all parameters, whereas update they are optional
class CreateProfile(UpdateProfile):
def __init__(self, name, producer_ids):
super(CreateProfile, self).__init__(name, producer_ids)
class Profile(AutoMarshallingModel):
ROOT_TAG = 'profile'
def __init__(self, name=None, id=None, event_producers=None):
super(Profile, self).__init__()
self.event_producers = event_producers
self.id = id
self.name = name
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
return cls._dict_to_obj(json_dict.get(cls.ROOT_TAG))
@classmethod
def _dict_to_obj(cls, json_dict):
return Profile(**json_dict)
class AllProfiles(AutoMarshallingModel):
ROOT_TAG = 'profiles'
def __init__(self):
super(AllProfiles, self).__init__()
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = str_to_json(serialized_str)
converted = []
json_profile_list = json_dict.get(cls.ROOT_TAG)
for json_profile in json_profile_list:
profile = Profile._dict_to_obj(json_profile)
converted.append(profile)
return converted

View File

@@ -0,0 +1,79 @@
"""
Copyright 2013 Rackspace
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 json import dumps as json_to_str, loads as str_to_json
from cafe.engine.models.base import AutoMarshallingModel
from cloudcafe.meniscus.tenant_api.models.producer import Producer
from cloudcafe.meniscus.tenant_api.models.profile import Profile
from cloudcafe.meniscus.tenant_api.models.host import Host
class CreateTenant(AutoMarshallingModel):
def __init__(self, tenant_id):
super(CreateTenant, self).__init__()
self.tenant_id = tenant_id
def _obj_to_json(self):
body = self._auto_to_dict()
return json_to_str(body)
class Tenant(AutoMarshallingModel):
ROOT_TAG = 'tenant'
def __init__(self, tenant_id=None, event_producers=None, hosts=None,
profiles=None):
"""An object that represents an tenant's response object."""
super(Tenant, self).__init__()
self.tenant_id = tenant_id
self.event_producers = event_producers
self.hosts = hosts
self.profiles = profiles
@classmethod
def _json_to_obj(cls, serialized_str):
"""
@param serialized_str:
@return:
"""
result = None
json_dict = str_to_json(serialized_str)
if json_dict is not None:
result = [cls._dict_to_obj(json_dict.get(cls.ROOT_TAG))]
return result
@classmethod
def _dict_to_obj(cls, dic):
event_producers = cls._convert_dict_of_types(
Producer, dic.get('event_producers'))
hosts = cls._convert_dict_of_types(Host, dic.get('hosts'))
profiles = cls._convert_dict_of_types(Profile, dic.get('profiles'))
kwargs = {
'tenant_id': str(dic.get('tenant_id')),
'event_producers': event_producers,
'hosts': hosts,
'profiles': profiles
}
return Tenant(**kwargs)
@classmethod
def _convert_dict_of_types(cls, c_type, dict):
result = None
if len(dict) > 0:
result = []
for item in dict:
result.append(c_type._dict_to_obj(item))
return result

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,36 @@
"""
Copyright 2013 Rackspace
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 cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.meniscus.version_api.models.version import Version
class VersionClient(AutoMarshallingRestClient):
def __init__(self, url, serialize_format=None, deserialize_format=None):
"""
@param url: Base URL of meniscus api
@type url: String
"""
super(VersionClient, self).__init__(serialize_format,
deserialize_format)
self.url = url
def get_version(self):
"""
@summary: Retrieves the version information from the API
"""
resp = self.request('GET', self.url, response_entity_type=Version)
return resp

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
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.
"""

View File

@@ -0,0 +1,41 @@
"""
Copyright 2013 Rackspace
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 json
from cafe.engine.models.base import AutoMarshallingModel
class Version(AutoMarshallingModel):
def __init__(self, version):
super(Version, self).__init__()
self.v1 = version
@classmethod
def _json_to_obj(cls, serialized_str):
"""Returns an instance of a Version based on the json serialized_str
passed in."""
result = None
json_obj = json.loads(serialized_str)
if json_obj is not None:
result = []
for _ in json_obj:
result.append(cls._dict_to_obj(json_obj))
return result
@classmethod
def _dict_to_obj(cls, dic):
kwargs = {'version': dic.get('v1')}
return Version(**kwargs)

View File

@@ -0,0 +1,32 @@
[marshalling]
serializer=json
deserializer=json
[meniscus]
base_url=http://localhost:8080
api_version=v1
[meniscus-tenant]
hostname=testhost
ip_address_v4=127.0.0.1
ip_address_v6=::1
producer_name=testapp
producer_pattern=syslog
producer_durable=true
producer_encrypted=false
profile_name=appservers-1
[meniscus-pairing]
coordinator_base_url=http://192.168.1.2:8080
callback=192.168.1.2:8080/v1/configuration
os_type=Linux
memory_mb=1024
arch=x86_64
worker_base_url=http://192.168.1.3:8080
api_secret=87188ab51cdhg6efeeee
personality=correlation
disk_path=/dev/sda1
disk_total=313764528
disk_used=112512436
cpu_cores=4
load_average=0.234353456