From 283846b006205e7bb30ebee94b02475240bb3b01 Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Mon, 30 Mar 2015 15:38:45 +0000 Subject: [PATCH] New OpenStack mixins. --- ooi/openstack/mixins.py | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ooi/openstack/mixins.py diff --git a/ooi/openstack/mixins.py b/ooi/openstack/mixins.py new file mode 100644 index 0000000..403dd8d --- /dev/null +++ b/ooi/openstack/mixins.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +# Copyright 2015 Spanish National Research Council +# +# 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 ooi.occi.core import attribute +from ooi.occi.core import mixin +from ooi.openstack import helpers + + +class OpenStackUserData(mixin.Mixin): + def __init__(self, user_data=None): + attrs = [ + attribute.InmutableAttribute("org.openstack.compute.user_data", + user_data), + ] + + attrs = attribute.AttributeCollection({a.name: a for a in attrs}) + + super(OpenStackUserData, self).__init__( + helpers.build_scheme("compute/instance"), + "user_data", "Contextualization extension - user_data", + attributes=attrs) + + @property + def user_data(self): + return self.attributes["org.openstack.compute.user_data"].value + + +class OpenStackPublicKey(mixin.Mixin): + def __init__(self, name=None, data=None): + attrs = [ + attribute.InmutableAttribute( + "org.openstack.credentials.publickey.name", name), + attribute.InmutableAttribute( + "org.openstack.credentials.publickey.data", data), + ] + + attrs = attribute.AttributeCollection({a.name: a for a in attrs}) + + super(OpenStackPublicKey, self).__init__( + helpers.build_scheme("instance/credentials"), + "public_key", "Contextualization extension - public_key", + attributes=attrs) + + @property + def name(self): + attr = "org.openstack.credentials.publickey.name" + return self.attributes[attr].value + + @property + def data(self): + attr = "org.openstack.credentials.publickey.data" + return self.attributes[attr].value + + +user_data = OpenStackUserData() +public_key = OpenStackPublicKey()