diff options
Diffstat (limited to 'glance/contrib/plugins')
20 files changed, 326 insertions, 0 deletions
diff --git a/glance/contrib/plugins/__init__.py b/glance/contrib/plugins/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/__init__.py diff --git a/glance/contrib/plugins/artifacts_sample/__init__.py b/glance/contrib/plugins/artifacts_sample/__init__.py new file mode 100644 index 000000000..f730c4393 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/__init__.py @@ -0,0 +1,5 @@ +from v1 import artifact as art1 +from v2 import artifact as art2 + + +MY_ARTIFACT = [art1.MyArtifact, art2.MyArtifact] diff --git a/glance/contrib/plugins/artifacts_sample/base.py b/glance/contrib/plugins/artifacts_sample/base.py new file mode 100644 index 000000000..2763ec534 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/base.py @@ -0,0 +1,29 @@ +# Copyright 2011-2012 OpenStack Foundation +# 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 glance.common.artifacts import definitions + + +class BaseArtifact(definitions.ArtifactType): + __type_version__ = "1.0" + prop1 = definitions.String() + prop2 = definitions.Integer() + int_list = definitions.Array(item_type=definitions.Integer(max_value=10, + min_value=1)) + depends_on = definitions.ArtifactReference(type_name='MyArtifact') + references = definitions.ArtifactReferenceList() + + image_file = definitions.BinaryObject() + screenshots = definitions.BinaryObjectList() diff --git a/glance/contrib/plugins/artifacts_sample/setup.cfg b/glance/contrib/plugins/artifacts_sample/setup.cfg new file mode 100644 index 000000000..7d5234ae7 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/setup.cfg @@ -0,0 +1,25 @@ +[metadata] +name = artifact +version = 0.0.1 +description = A sample plugin for artifact loading +author = Inessa Vasilevskaya +author-email = ivasilevskaya@mirantis.com +classifier = + Development Status :: 3 - Alpha + License :: OSI Approved :: Apache Software License + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.2 + Programming Language :: Python :: 3.3 + Intended Audience :: Developers + Environment :: Console + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[entry_points] +glance.artifacts.types = + MyArtifact = glance.contrib.plugins.artifacts_sample:MY_ARTIFACT diff --git a/glance/contrib/plugins/artifacts_sample/setup.py b/glance/contrib/plugins/artifacts_sample/setup.py new file mode 100644 index 000000000..2a3ea51e7 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/setup.py @@ -0,0 +1,20 @@ +# Copyright 2011-2012 OpenStack Foundation +# 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. + +import setuptools + +# all other params will be taken from setup.cfg +setuptools.setup(packages=setuptools.find_packages(), + setup_requires=['pbr'], pbr=True) diff --git a/glance/contrib/plugins/artifacts_sample/v1/__init__.py b/glance/contrib/plugins/artifacts_sample/v1/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/v1/__init__.py diff --git a/glance/contrib/plugins/artifacts_sample/v1/artifact.py b/glance/contrib/plugins/artifacts_sample/v1/artifact.py new file mode 100644 index 000000000..f224edd30 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/v1/artifact.py @@ -0,0 +1,21 @@ +# Copyright 2011-2012 OpenStack Foundation +# 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 glance.contrib.plugins.artifacts_sample import base + + +class MyArtifact(base.BaseArtifact): + __type_version__ = "1.0.1" diff --git a/glance/contrib/plugins/artifacts_sample/v2/__init__.py b/glance/contrib/plugins/artifacts_sample/v2/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/v2/__init__.py diff --git a/glance/contrib/plugins/artifacts_sample/v2/artifact.py b/glance/contrib/plugins/artifacts_sample/v2/artifact.py new file mode 100644 index 000000000..b331f80d5 --- /dev/null +++ b/glance/contrib/plugins/artifacts_sample/v2/artifact.py @@ -0,0 +1,23 @@ +# Copyright 2011-2012 OpenStack Foundation +# 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 glance.common.artifacts import definitions +from glance.contrib.plugins.artifacts_sample import base + + +class MyArtifact(base.BaseArtifact): + __type_version__ = "2.0" + depends_on = definitions.ArtifactReference(type_name="MyArtifact") diff --git a/glance/contrib/plugins/image_artifact/__init__.py b/glance/contrib/plugins/image_artifact/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/image_artifact/__init__.py diff --git a/glance/contrib/plugins/image_artifact/requirements.txt b/glance/contrib/plugins/image_artifact/requirements.txt new file mode 100644 index 000000000..5cee777d4 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/requirements.txt @@ -0,0 +1 @@ +python-glanceclient diff --git a/glance/contrib/plugins/image_artifact/setup.cfg b/glance/contrib/plugins/image_artifact/setup.cfg new file mode 100644 index 000000000..38253c792 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/setup.cfg @@ -0,0 +1,25 @@ +[metadata] +name = image_artifact_plugin +version = 2.0 +description = An artifact plugin for Imaging functionality +author = Alexander Tivelkov +author-email = ativelkov@mirantis.com +classifier = + Development Status :: 3 - Alpha + License :: OSI Approved :: Apache Software License + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.2 + Programming Language :: Python :: 3.3 + Intended Audience :: Developers + Environment :: Console + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[entry_points] +glance.artifacts.types = + Image = glance.contrib.plugins.image_artifact.version_selector:versions diff --git a/glance/contrib/plugins/image_artifact/setup.py b/glance/contrib/plugins/image_artifact/setup.py new file mode 100644 index 000000000..2a3ea51e7 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/setup.py @@ -0,0 +1,20 @@ +# Copyright 2011-2012 OpenStack Foundation +# 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. + +import setuptools + +# all other params will be taken from setup.cfg +setuptools.setup(packages=setuptools.find_packages(), + setup_requires=['pbr'], pbr=True) diff --git a/glance/contrib/plugins/image_artifact/v1/__init__.py b/glance/contrib/plugins/image_artifact/v1/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v1/__init__.py diff --git a/glance/contrib/plugins/image_artifact/v1/image.py b/glance/contrib/plugins/image_artifact/v1/image.py new file mode 100644 index 000000000..176c4b9a6 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v1/image.py @@ -0,0 +1,36 @@ +# Copyright (c) 2014 Mirantis, 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. + +from glance.common.artifacts import definitions + + +class ImageAsAnArtifact(definitions.ArtifactType): + __type_name__ = 'Image' + __endpoint__ = 'images' + + file = definitions.BinaryObject(required=True) + disk_format = definitions.String(allowed_values=['ami', 'ari', 'aki', + 'vhd', 'vmdk', 'raw', + 'qcow2', 'vdi', 'iso'], + required=True, + mutable=False) + container_format = definitions.String(allowed_values=['ami', 'ari', + 'aki', 'bare', + 'ovf', 'ova'], + required=True, + mutable=False) + min_disk = definitions.Integer(min_value=0, default=0) + min_ram = definitions.Integer(min_value=0, default=0) + + virtual_size = definitions.Integer(min_value=0) diff --git a/glance/contrib/plugins/image_artifact/v1_1/__init__.py b/glance/contrib/plugins/image_artifact/v1_1/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v1_1/__init__.py diff --git a/glance/contrib/plugins/image_artifact/v1_1/image.py b/glance/contrib/plugins/image_artifact/v1_1/image.py new file mode 100644 index 000000000..fc41dae7a --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v1_1/image.py @@ -0,0 +1,27 @@ +# Copyright (c) 2014 Mirantis, 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. + + +from glance.common.artifacts import definitions +import glance.contrib.plugins.image_artifact.v1.image as v1 + + +class ImageAsAnArtifact(v1.ImageAsAnArtifact): + __type_version__ = '1.1' + + icons = definitions.BinaryObjectList() + + similar_images = (definitions. + ArtifactReferenceList(references=definitions. + ArtifactReference('Image'))) diff --git a/glance/contrib/plugins/image_artifact/v2/__init__.py b/glance/contrib/plugins/image_artifact/v2/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v2/__init__.py diff --git a/glance/contrib/plugins/image_artifact/v2/image.py b/glance/contrib/plugins/image_artifact/v2/image.py new file mode 100644 index 000000000..cf6002153 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/v2/image.py @@ -0,0 +1,75 @@ +# Copyright (c) 2014 Mirantis, 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. + +from glance.common.artifacts import definitions +from glance.common import exception +import glance.contrib.plugins.image_artifact.v1_1.image as v1_1 + +import glanceclient + + +from glance import i18n + + +_ = i18n._ + + +class ImageAsAnArtifact(v1_1.ImageAsAnArtifact): + __type_version__ = '2.0' + + file = definitions.BinaryObject(required=False) + legacy_image_id = definitions.String(required=False, mutable=False, + pattern=R'[0-9a-f]{8}-[0-9a-f]{4}' + R'-4[0-9a-f]{3}-[89ab]' + R'[0-9a-f]{3}-[0-9a-f]{12}') + + def __pre_publish__(self, context, *args, **kwargs): + super(ImageAsAnArtifact, self).__pre_publish__(*args, **kwargs) + if self.file is None and self.legacy_image_id is None: + raise exception.InvalidArtifactPropertyValue( + message=_("Either a file or a legacy_image_id has to be " + "specified") + ) + if self.file is not None and self.legacy_image_id is not None: + raise exception.InvalidArtifactPropertyValue( + message=_("Both file and legacy_image_id may not be " + "specified at the same time")) + + if self.legacy_image_id: + glance_endpoint = next(service['endpoints'][0]['publicURL'] + for service in context.service_catalog + if service['name'] == 'glance') + try: + client = glanceclient.Client(version=2, + endpoint=glance_endpoint, + token=context.auth_token) + legacy_image = client.images.get(self.legacy_image_id) + except Exception: + raise exception.InvalidArtifactPropertyValue( + message=_('Unable to get legacy image') + ) + if legacy_image is not None: + self.file = definitions.Blob(size=legacy_image.size, + locations=[ + { + "status": "active", + "value": + legacy_image.direct_url + }], + checksum=legacy_image.checksum, + item_key=legacy_image.id) + else: + raise exception.InvalidArtifactPropertyValue( + message=_("Legacy image was not found") + ) diff --git a/glance/contrib/plugins/image_artifact/version_selector.py b/glance/contrib/plugins/image_artifact/version_selector.py new file mode 100644 index 000000000..afbe30345 --- /dev/null +++ b/glance/contrib/plugins/image_artifact/version_selector.py @@ -0,0 +1,19 @@ +# Copyright (c) 2014 Mirantis, 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. + +from v1 import image as v1 +from v1_1 import image as v1_1 +from v2 import image as v2 + +versions = [v1.ImageAsAnArtifact, v1_1.ImageAsAnArtifact, v2.ImageAsAnArtifact] |