Skip to content

Commit 95e82f9

Browse files
committed
Add databases to instances
Add support for list, create, and delete operations only to dbs within a dbms instance. Change-Id: I16eb5314fe1edfb56f9f38a74cccc39e548cd0b3
1 parent 8f4dfec commit 95e82f9

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

openstack/database/v1/database.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.database import database_service
14+
from openstack import resource
15+
16+
17+
class Database(resource.Resource):
18+
id_attribute = 'name'
19+
resource_key = 'database'
20+
resources_key = 'databases'
21+
base_path = '/instances/%(instance_id)s/databases'
22+
service = database_service.DatabaseService()
23+
24+
# capabilities
25+
allow_create = True
26+
allow_delete = True
27+
allow_list = True
28+
29+
# Properties
30+
character_set = resource.prop('character_set')
31+
collate = resource.prop('collate')
32+
instance_id = resource.prop('instance_id')
33+
name = resource.prop('name')
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import testtools
14+
15+
from openstack.database.v1 import database
16+
17+
18+
IDENTIFIER = 'NAME'
19+
INSTANCE_ID = 'INSTANCE_ID'
20+
EXAMPLE = {
21+
'character_set': '1',
22+
'collate': '2',
23+
'instance_id': INSTANCE_ID,
24+
'name': IDENTIFIER,
25+
}
26+
27+
28+
class TestDatabase(testtools.TestCase):
29+
30+
def test_basic(self):
31+
sot = database.Database()
32+
self.assertEqual('database', sot.resource_key)
33+
self.assertEqual('databases', sot.resources_key)
34+
path = '/instances/%(instance_id)s/databases'
35+
self.assertEqual(path, sot.base_path)
36+
self.assertEqual('database', sot.service.service_type)
37+
self.assertTrue(sot.allow_list)
38+
self.assertTrue(sot.allow_create)
39+
self.assertFalse(sot.allow_retrieve)
40+
self.assertFalse(sot.allow_update)
41+
self.assertTrue(sot.allow_delete)
42+
43+
def test_make_it(self):
44+
sot = database.Database(EXAMPLE)
45+
self.assertEqual(IDENTIFIER, sot.id)
46+
self.assertEqual(EXAMPLE['character_set'], sot.character_set)
47+
self.assertEqual(EXAMPLE['collate'], sot.collate)
48+
self.assertEqual(EXAMPLE['instance_id'], sot.instance_id)
49+
self.assertEqual(IDENTIFIER, sot.name)

0 commit comments

Comments
 (0)