Add simple objects interface and registry

Objects are
- objects/bay
- objects/pod
- objects/service
- objects/container

These code is based on Solum.

Change-Id: Id1f64417a86807964ebb4226547517587d8565eb
Implements: blueprint db-object-definitions
changes/33/137533/1
Motohiro OTSUKA 2014-11-27 15:52:05 +09:00
parent 359ce6c12b
commit 370b577e8c
7 changed files with 178 additions and 0 deletions

View File

53
magnum/objects/base.py Normal file
View File

@ -0,0 +1,53 @@
# 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.
class CrudMixin(object):
@classmethod
def get_by_id(cls, context, id):
"""Return a specific object by its unique identifier."""
@classmethod
def get_by_uuid(cls, context, item_uuid):
"""Return a specific object by its uuid."""
def create(self, context):
"""Create the model."""
def save(self, context):
"""Change the model."""
def destroy(self, context):
"""Destroy the model."""
def add_forward_schema_changes(self):
"""Update the attributes of self to include new schema elements.
This method is invoked during save/create operations to guarantee
that objects being created during a schema transition support both
new and old schemas. This ensures that background jobs can run
to migrate existing objects on a live system while writes are
occurring.
The changes made by this method must match the schema defined
for "transitioning" and "new" (see solum.objects.__init__).
"""
class CrudListMixin(object):
@classmethod
def get_all(cls, context):
"""Retrieve all applications for the active context.
Context may be global or tenant scoped.
"""

24
magnum/objects/bay.py Normal file
View File

@ -0,0 +1,24 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# 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 magnum.objects import base
class Bay(base.CrudMixin):
# Version 1.0: Initial version
VERSION = '1.0'
class BayList(list, base.CrudListMixin):
"""List of Bays."""

View File

@ -0,0 +1,24 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# 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 magnum.objects import base
class Container(base.CrudMixin):
# Version 1.0: Initial version
VERSION = '1.0'
class ContainerList(list, base.CrudListMixin):
"""List of Containers."""

24
magnum/objects/pod.py Normal file
View File

@ -0,0 +1,24 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# 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 magnum.objects import base
class Pod(base.CrudMixin):
# Version 1.0: Initial version
VERSION = '1.0'
class PodList(list, base.CrudListMixin):
"""List of Pods."""

View File

@ -0,0 +1,29 @@
# Copyright 2013 Red Hat, Inc.
#
# 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.
class Registry(object):
impls = dict()
"""Allow domain objects to be loaded by name."""
def __getattr__(self, name):
return self.impls[name]
def add(self, interface, cls):
"""Register an implementation for a class."""
self.impls[interface.__name__] = cls
def clear(self):
"""Deregister all implementations."""
self.impls.clear()

24
magnum/objects/service.py Normal file
View File

@ -0,0 +1,24 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# 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 magnum.objects import base
class Service(base.CrudMixin):
# Version 1.0: Initial version
VERSION = '1.0'
class ServiceList(list, base.CrudListMixin):
"""List of Services."""