Add OpenStack Resource Template
This commit is contained in:
parent
3db3cb91a3
commit
5753438add
@ -1,7 +1,7 @@
|
|||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = ooi
|
source = ooi
|
||||||
omit = ooi/tests/*,ooi/openstack/*
|
omit = ooi/tests/*
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
ignore-errors = True
|
ignore-errors = True
|
@ -14,6 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from ooi.occi.core import attribute
|
||||||
from ooi.occi.core import mixin
|
from ooi.occi.core import mixin
|
||||||
from ooi.occi.infrastructure import templates
|
from ooi.occi.infrastructure import templates
|
||||||
from ooi.openstack import helpers
|
from ooi.openstack import helpers
|
||||||
@ -26,3 +27,44 @@ class OpenStackOSTemplate(mixin.Mixin):
|
|||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
related=[templates.os_tpl])
|
related=[templates.os_tpl])
|
||||||
|
|
||||||
|
|
||||||
|
class OpenStackResourceTemplate(mixin.Mixin):
|
||||||
|
|
||||||
|
def __init__(self, name, cores, memory, disk, ephemeral=0, swap=0):
|
||||||
|
attrs = [
|
||||||
|
attribute.InmutableAttribute("occi.compute.cores", cores),
|
||||||
|
attribute.InmutableAttribute("occi.compute.memory", memory),
|
||||||
|
attribute.InmutableAttribute("occi.compute.disk", disk),
|
||||||
|
attribute.InmutableAttribute("occi.compute.ephemeral", ephemeral),
|
||||||
|
attribute.InmutableAttribute("occi.compute.swap", swap)
|
||||||
|
]
|
||||||
|
|
||||||
|
attrs = attribute.AttributeCollection({a.name: a for a in attrs})
|
||||||
|
|
||||||
|
super(OpenStackResourceTemplate, self).__init__(
|
||||||
|
helpers.build_scheme("template/resource"),
|
||||||
|
name,
|
||||||
|
"Flavor: %s" % name,
|
||||||
|
related=[templates.resource_tpl],
|
||||||
|
attributes=attrs)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cores(self):
|
||||||
|
return self.attributes["occi.compute.cores"].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def memory(self):
|
||||||
|
return self.attributes["occi.compute.memory"].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def disk(self):
|
||||||
|
return self.attributes["occi.compute.disk"].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ephemeral(self):
|
||||||
|
return self.attributes["occi.compute.ephemeral"].value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def swap(self):
|
||||||
|
return self.attributes["occi.compute.swap"].value
|
||||||
|
@ -33,3 +33,30 @@ class TestOpenStackOSTemplate(base.TestCase):
|
|||||||
self.assertEqual(title, tpl.title)
|
self.assertEqual(title, tpl.title)
|
||||||
self.assertTrue(tpl.scheme.startswith(helpers._PREFIX))
|
self.assertTrue(tpl.scheme.startswith(helpers._PREFIX))
|
||||||
self.assertIn(occi_templates.os_tpl, tpl.related)
|
self.assertIn(occi_templates.os_tpl, tpl.related)
|
||||||
|
|
||||||
|
|
||||||
|
class TestOpenStackResourceTemplate(base.TestCase):
|
||||||
|
def test_resource_template(self):
|
||||||
|
name = "m1.humongous"
|
||||||
|
cores = 10
|
||||||
|
memory = 30
|
||||||
|
disk = 40
|
||||||
|
swap = 20
|
||||||
|
ephemeral = 50
|
||||||
|
|
||||||
|
tpl = templates.OpenStackResourceTemplate(name,
|
||||||
|
cores,
|
||||||
|
memory,
|
||||||
|
disk,
|
||||||
|
swap=swap,
|
||||||
|
ephemeral=ephemeral)
|
||||||
|
|
||||||
|
self.assertEqual(name, tpl.term)
|
||||||
|
self.assertEqual("Flavor: %s" % name, tpl.title)
|
||||||
|
self.assertTrue(tpl.scheme.startswith(helpers._PREFIX))
|
||||||
|
self.assertIn(occi_templates.resource_tpl, tpl.related)
|
||||||
|
self.assertEqual(cores, tpl.cores)
|
||||||
|
self.assertEqual(memory, tpl.memory)
|
||||||
|
self.assertEqual(disk, tpl.disk)
|
||||||
|
self.assertEqual(swap, tpl.swap)
|
||||||
|
self.assertEqual(ephemeral, tpl.ephemeral)
|
||||||
|
Loading…
Reference in New Issue
Block a user