Include OCCI Security Group infrastructure
This change add the OCCI Security Group infrastructure following the features provided by CESNET. Change-Id: Ic573210399bbcd30e699d0d4f6446b932230d4ae
This commit is contained in:
parent
a8cfcb58e8
commit
647740eb9c
56
ooi/occi/infrastructure/securitygroup.py
Normal file
56
ooi/occi/infrastructure/securitygroup.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2015 LIP - INDIGO-DataCloud
|
||||
#
|
||||
# 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 as attr
|
||||
from ooi.occi.core import kind
|
||||
from ooi.occi.core import resource
|
||||
from ooi.occi import helpers
|
||||
|
||||
|
||||
class SecurityGroupResource(resource.Resource):
|
||||
attributes = attr.AttributeCollection({
|
||||
"occi.securitygroup.rules": attr.MutableAttribute(
|
||||
"occi.securitygroup.rules", description="Security Rules",
|
||||
attr_type=attr.AttributeType.list_type),
|
||||
"occi.securitygroup.state": attr.InmutableAttribute(
|
||||
"occi.securitygroup.state",
|
||||
description="Current state of the instance",
|
||||
attr_type=attr.AttributeType.string_type)
|
||||
})
|
||||
kind = kind.Kind(helpers.build_scheme('infrastructure'), 'securitygroup',
|
||||
'securitygroup resource', attributes, 'securitygroup/',
|
||||
parent=resource.Resource.kind
|
||||
)
|
||||
|
||||
def __init__(self, title, id=None, rules=None, summary=None,
|
||||
state=None, mixins=[]):
|
||||
super(SecurityGroupResource, self).__init__(title, mixins,
|
||||
summary=summary,
|
||||
id=id)
|
||||
self.rules = rules
|
||||
self.attributes["occi.securitygroup.state"] = (
|
||||
attr.InmutableAttribute.from_attr(
|
||||
self.attributes["occi.securitygroup.state"], state))
|
||||
|
||||
@property
|
||||
def rules(self):
|
||||
return self.attributes["occi.securitygroup.rules"].value
|
||||
|
||||
@rules.setter
|
||||
def rules(self, value):
|
||||
self.attributes["occi.securitygroup.rules"].value = value
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.attributes["occi.securitygroup.state"].value
|
44
ooi/occi/infrastructure/securitygroup_link.py
Normal file
44
ooi/occi/infrastructure/securitygroup_link.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright 2015 LIP - INDIGO-DataCloud
|
||||
#
|
||||
# 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 as attr
|
||||
from ooi.occi.core import kind
|
||||
from ooi.occi.core import link
|
||||
from ooi.occi import helpers
|
||||
|
||||
|
||||
class SecurityGroupLink(link.Link):
|
||||
attributes = attr.AttributeCollection({
|
||||
"occi.securitygrouplink.state": attr.InmutableAttribute(
|
||||
"occi.securitygrouplink.state",
|
||||
description="Current state of the instance",
|
||||
attr_type=attr.AttributeType.string_type)
|
||||
})
|
||||
kind = kind.Kind(helpers.build_scheme('infrastructure'),
|
||||
'securitygrouplink', 'security group link resource',
|
||||
attributes, 'securitygrouplink/',
|
||||
parent=link.Link.kind)
|
||||
|
||||
def __init__(self, source, target, state=None):
|
||||
link_id = '_'.join([source.id, target.id])
|
||||
super(SecurityGroupLink, self).__init__(None, [], source,
|
||||
target, link_id)
|
||||
|
||||
self.attributes["occi.securitygrouplink.state"] = (
|
||||
attr.InmutableAttribute.from_attr(
|
||||
self.attributes["occi.securitygrouplink.state"], state))
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.attributes["occi.securitygrouplink.state"].value
|
@ -21,6 +21,8 @@ from ooi.occi.infrastructure import compute
|
||||
from ooi.occi.infrastructure import contextualization
|
||||
from ooi.occi.infrastructure import network
|
||||
from ooi.occi.infrastructure import network_link
|
||||
from ooi.occi.infrastructure import securitygroup
|
||||
from ooi.occi.infrastructure import securitygroup_link
|
||||
from ooi.occi.infrastructure import storage
|
||||
from ooi.occi.infrastructure import storage_link
|
||||
from ooi.occi.infrastructure import templates
|
||||
@ -359,3 +361,81 @@ class TestOCCISSHKey(base.TestCase):
|
||||
self.assertEqual("ssh_key", mxn.term)
|
||||
self.assertEqual(key_data, mxn.ssh_key)
|
||||
self.assertEqual([compute.ComputeResource.kind], mxn.applies)
|
||||
|
||||
|
||||
class TestOCCISecurityGRoup(base.TestCase):
|
||||
def test_storage_class(self):
|
||||
s = securitygroup.SecurityGroupResource
|
||||
self.assertIsNone(s.actions)
|
||||
self.assertIn("occi.core.id", s.attributes)
|
||||
self.assertIn("occi.core.summary", s.attributes)
|
||||
self.assertIn("occi.core.title", s.attributes)
|
||||
self.assertIn("occi.securitygroup.rules", s.attributes)
|
||||
self.assertIn("occi.securitygroup.state", s.attributes)
|
||||
self.assertEqual(resource.Resource.kind, s.kind.parent)
|
||||
self.assertEqual(s.kind.location, "securitygroup/")
|
||||
|
||||
def test_securitygroup(self):
|
||||
id = uuid.uuid4().hex
|
||||
rules = [{"port": 1}]
|
||||
s = securitygroup.SecurityGroupResource(
|
||||
"foo",
|
||||
summary="This is a summary",
|
||||
id=id, rules=rules
|
||||
)
|
||||
self.assertEqual("foo", s.title)
|
||||
self.assertEqual(id, s.id)
|
||||
self.assertEqual("This is a summary", s.summary)
|
||||
self.assertEqual(rules, s.rules)
|
||||
self.assertIsNone(s.state)
|
||||
|
||||
def test_setters(self):
|
||||
rules = [{"port": 1}]
|
||||
s = securitygroup.SecurityGroupResource("foo")
|
||||
s.rules = rules
|
||||
self.assertEqual(rules, s.attributes["occi.securitygroup.rules"].value)
|
||||
|
||||
def test_getters(self):
|
||||
rules = [{"port": 1}]
|
||||
s = securitygroup.SecurityGroupResource(
|
||||
"foobar",
|
||||
state="foostate", rules=rules
|
||||
)
|
||||
self.assertEqual("foostate", s.state)
|
||||
self.assertEqual(rules, s.rules)
|
||||
|
||||
|
||||
class TestOCCISecurityGroupLink(base.TestCase):
|
||||
def test_securitygrouplink_class(self):
|
||||
s = securitygroup_link.SecurityGroupLink
|
||||
self.assertIn("occi.core.id", s.attributes)
|
||||
self.assertIn("occi.core.title", s.attributes)
|
||||
self.assertIn("occi.core.source", s.attributes)
|
||||
self.assertIn("occi.core.target", s.attributes)
|
||||
self.assertIn("occi.securitygrouplink.state", s.attributes)
|
||||
self.assertEqual(link.Link.kind, s.kind.parent)
|
||||
self.assertEqual(s.kind.location, "securitygrouplink/")
|
||||
|
||||
def test_securitygrouplink(self):
|
||||
server_id = uuid.uuid4().hex
|
||||
c = compute.ComputeResource("foo",
|
||||
summary="This is a summary",
|
||||
id=server_id)
|
||||
vol_id = uuid.uuid4().hex
|
||||
s = securitygroup.SecurityGroupResource("bar",
|
||||
summary="This is a summary",
|
||||
id=vol_id)
|
||||
l = securitygroup_link.SecurityGroupLink(c, s)
|
||||
link_id = '%s_%s' % (server_id, vol_id)
|
||||
self.assertEqual(link_id, l.id)
|
||||
self.assertIsNone(l.state)
|
||||
|
||||
def test_getters(self):
|
||||
c = compute.ComputeResource("foo",
|
||||
summary="This is a summary",
|
||||
id=uuid.uuid4().hex)
|
||||
s = securitygroup.SecurityGroupResource("bar",
|
||||
summary="This is a summary",
|
||||
id=uuid.uuid4().hex)
|
||||
l = securitygroup_link.SecurityGroupLink(c, s, state="foobar")
|
||||
self.assertEqual("foobar", l.state)
|
||||
|
Loading…
Reference in New Issue
Block a user