-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit a77f2df.
- Loading branch information
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ecl.network import network_service | ||
from ecl import resource2 | ||
|
||
|
||
class SecurityGroup(resource2.Resource): | ||
"""SecurityGroup Resource""" | ||
resource_key = 'security_group' | ||
resources_key = 'security_groups' | ||
service = network_service.NetworkService("v2.0") | ||
base_path = '/' + service.version + '/security-groups' | ||
|
||
# capabilities | ||
allow_list = True | ||
allow_create = True | ||
allow_get = True | ||
allow_update = True | ||
allow_delete = True | ||
|
||
# Properties | ||
# Security group description. | ||
description = resource2.Body('description') | ||
# Security group unique id. | ||
id = resource2.Body('id') | ||
# Security group name. | ||
name = resource2.Body('name') | ||
# Security group status. | ||
status = resource2.Body('status') | ||
# Security Group tags. | ||
tags = resource2.Body('tags') | ||
# The owner name of security group. | ||
tenant_id = resource2.Body('tenant_id') | ||
# Security group rules | ||
security_group_rules = resource2.Body('security_group_rules', type=list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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 testtools | ||
|
||
from ecl.network.v2.security_group import SecurityGroup | ||
|
||
IDENTIFIER = 'IDENTIFIER' | ||
EXAMPLE = { | ||
"description": '1', | ||
"id": IDENTIFIER, | ||
"name": '2', | ||
"status": '3', | ||
"tags": { | ||
'tag1': '4', | ||
'tag2': '5' | ||
}, | ||
"tenant_id": IDENTIFIER, | ||
"security_group_rules": [ | ||
{ | ||
'rule1': '6', | ||
'rule2': '7' | ||
} | ||
] | ||
} | ||
|
||
|
||
class TestSecurityGroup(testtools.TestCase): | ||
|
||
def test_basic(self): | ||
sot = SecurityGroup() | ||
self.assertEqual('security_group', sot.resource_key) | ||
self.assertEqual('security_groups', sot.resources_key) | ||
self.assertEqual('/v2.0/security-groups', sot.base_path) | ||
self.assertEqual('network', sot.service.service_type) | ||
self.assertTrue(sot.allow_list) | ||
self.assertTrue(sot.allow_create) | ||
self.assertTrue(sot.allow_get) | ||
self.assertTrue(sot.allow_update) | ||
self.assertTrue(sot.allow_delete) | ||
|
||
def test_make_it(self): | ||
sot = SecurityGroup(**EXAMPLE) | ||
self.assertEqual(EXAMPLE['description'], sot.description) | ||
self.assertEqual(EXAMPLE['id'], sot.id) | ||
self.assertEqual(EXAMPLE['name'], sot.name) | ||
self.assertEqual(EXAMPLE['status'], sot.status) | ||
self.assertEqual(EXAMPLE['tags'], sot.tags) | ||
self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) | ||
self.assertEqual(EXAMPLE['security_group_rules'], sot.security_group_rules) |