Merge "Added behaviour and model for first config drive openstack metadata"
This commit is contained in:
15
cloudcafe/compute/extensions/config_drive/__init__.py
Normal file
15
cloudcafe/compute/extensions/config_drive/__init__.py
Normal 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.
|
||||
"""
|
||||
74
cloudcafe/compute/extensions/config_drive/behaviors.py
Normal file
74
cloudcafe/compute/extensions/config_drive/behaviors.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
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.behaviors import BaseBehavior
|
||||
from cloudcafe.compute.extensions.config_drive.models.\
|
||||
config_drive_openstack_meta import OpenStackMeta
|
||||
from cloudcafe.compute.extensions.config_drive.models.\
|
||||
config_drive_ec_meta import EcMeta
|
||||
|
||||
|
||||
class ConfigDriveBehaviors(BaseBehavior):
|
||||
|
||||
def __init__(self, servers_client, servers_config,
|
||||
server_behaviors):
|
||||
|
||||
self.config = servers_config
|
||||
self.servers_client = servers_client
|
||||
self.server_behaviors = server_behaviors
|
||||
|
||||
def get_openstack_metadata(self, server, servers_config, key,
|
||||
filepath):
|
||||
"""
|
||||
@summary:Returns openstack metadata on config drive
|
||||
@return: Response Object containing openstack meta domain object
|
||||
@rtype: Request Response Object
|
||||
"""
|
||||
|
||||
remote_client = self.server_behaviors.get_remote_instance_client(
|
||||
server, servers_config, key=key)
|
||||
openstack_meta_str = remote_client.get_file_details(
|
||||
filepath=filepath)
|
||||
return OpenStackMeta.deserialize(openstack_meta_str.content, 'json')
|
||||
|
||||
def get_ec_metadata(self, server, servers_config, key,
|
||||
filepath):
|
||||
"""
|
||||
@summary:Returns ec2 metadata on config drive
|
||||
@return: Response Object containing ec2 meta domain object
|
||||
@rtype: Request Response Object
|
||||
"""
|
||||
|
||||
remote_client = self.server_behaviors.get_remote_instance_client(
|
||||
server, servers_config, key=key)
|
||||
ec_meta_str = remote_client.get_file_details(
|
||||
filepath=filepath)
|
||||
return EcMeta.deserialize(ec_meta_str.content, 'json')
|
||||
|
||||
def mount_config_drive(self, server, servers_config, key,
|
||||
source_path, destination_path):
|
||||
"""
|
||||
@summary: Mounts config drive
|
||||
@return: Silent
|
||||
@rtype: None
|
||||
"""
|
||||
remote_client = self.server_behaviors.get_remote_instance_client(
|
||||
server, servers_config, key=key)
|
||||
remote_client.create_directory(
|
||||
path=destination_path)
|
||||
remote_client.mount_file_to_destination_directory(
|
||||
source_path=source_path,
|
||||
destination_path=destination_path)
|
||||
15
cloudcafe/compute/extensions/config_drive/models/__init__.py
Normal file
15
cloudcafe/compute/extensions/config_drive/models/__init__.py
Normal 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.
|
||||
"""
|
||||
@@ -0,0 +1,102 @@
|
||||
"""
|
||||
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 OpenStackMeta(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, availability_zone=None, hostname=None,
|
||||
launch_index=None, name=None,
|
||||
uuid=None, files=None, public_keys=None, meta=None):
|
||||
self.availability_zone = availability_zone
|
||||
self.hostname = hostname
|
||||
self.launch_index = launch_index
|
||||
self.name = name
|
||||
self.uuid = uuid
|
||||
self.files = files
|
||||
self.public_keys = public_keys
|
||||
self.meta = meta
|
||||
|
||||
@classmethod
|
||||
def _json_to_obj(cls, serialized_str):
|
||||
json_dict = json.loads(serialized_str)
|
||||
open_meta = cls._dict_to_obj(json_dict)
|
||||
return open_meta
|
||||
|
||||
@classmethod
|
||||
def _dict_to_obj(cls, json_dict):
|
||||
openstack_meta = OpenStackMeta(
|
||||
availability_zone=json_dict.get('availability_zone'),
|
||||
hostname=json_dict.get('hostname'),
|
||||
launch_index=json_dict.get('launch_index'),
|
||||
name=json_dict.get('name'), meta=json_dict.get('meta'),
|
||||
public_keys=json_dict.get('public_keys'),
|
||||
uuid=json_dict.get('uuid'))
|
||||
if 'files' in json_dict:
|
||||
openstack_meta.files = Files._dict_to_obj(json_dict)
|
||||
return openstack_meta
|
||||
|
||||
|
||||
class File(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, content_path, path):
|
||||
|
||||
super(File, self).__init__()
|
||||
self.content_path = content_path
|
||||
self.path = content_path
|
||||
|
||||
@classmethod
|
||||
def _json_to_obj(cls, serialized_str):
|
||||
"""
|
||||
Returns an instance of a File based on the json serialized_str
|
||||
passed in.
|
||||
"""
|
||||
|
||||
json_dict = json.loads(serialized_str)
|
||||
file = cls._dict_to_obj(json_dict)
|
||||
return file
|
||||
|
||||
@classmethod
|
||||
def _dict_to_obj(cls, file_dict):
|
||||
"""Helper method to turn dictionary into File instance."""
|
||||
file = File(content_path=file_dict.get('content_path'),
|
||||
path=file_dict.get('path'))
|
||||
return file
|
||||
|
||||
|
||||
class Files(AutoMarshallingModel):
|
||||
|
||||
@classmethod
|
||||
def _json_to_obj(cls, serialized_str):
|
||||
"""
|
||||
Returns an instance of a Files based on the json serialized_str
|
||||
passed in.
|
||||
"""
|
||||
json_dict = json.loads(serialized_str)
|
||||
files = cls._dict_to_obj(json_dict)
|
||||
return files
|
||||
|
||||
@classmethod
|
||||
def _dict_to_obj(cls, file_dict):
|
||||
"""Helper method to turn dictionary into Files instance."""
|
||||
files = []
|
||||
for file_dict in file_dict['files']:
|
||||
file = File._dict_to_obj(file_dict)
|
||||
files.append(file)
|
||||
return files
|
||||
Reference in New Issue
Block a user