Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/openstack/user_preference.py b/openstack/user_preference.py
index bb97800..199b885 100644
--- a/openstack/user_preference.py
+++ b/openstack/user_preference.py
@@ -63,6 +63,7 @@ from openstack.network import network_service
from openstack.object_store import object_store_service
from openstack.orchestration import orchestration_service
from openstack.telemetry import telemetry_service
+from openstack.volume import volume_service
class UserPreference(object):
@@ -112,6 +113,9 @@ class UserPreference(object):
serv = telemetry_service.TelemetryService()
serv.set_visibility(None)
self._services[serv.service_type] = serv
+ serv = volume_service.VolumeService()
+ serv.set_visibility(None)
+ self._services[serv.service_type] = serv
self.service_names = sorted(self._services.keys())
def __repr__(self):
diff --git a/openstack/volume/__init__.py b/openstack/volume/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/openstack/volume/v2/__init__.py b/openstack/volume/v2/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/openstack/volume/v2/_proxy.py b/openstack/volume/v2/_proxy.py
new file mode 100644
index 0000000..52fcc1f
--- /dev/null
+++ b/openstack/volume/v2/_proxy.py
@@ -0,0 +1,22 @@
+# 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 openstack.volume.v2 import volumes
+
+
+class Proxy(object):
+
+ def __init__(self, session):
+ self.session = session
+
+ def list_volumes(self):
+ return volumes.Volume.list(self.session)
diff --git a/openstack/volume/v2/volumes.py b/openstack/volume/v2/volumes.py
new file mode 100644
index 0000000..a0d65bf
--- /dev/null
+++ b/openstack/volume/v2/volumes.py
@@ -0,0 +1,104 @@
+# 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 time
+
+from openstack.volume import volume_service
+from openstack import exceptions
+from openstack import resource
+
+
+class Volume(resource.Resource):
+ resource_key = 'volume'
+ resources_key = 'volumes'
+ base_path = '/volumes'
+
+ # capablities
+ allow_list = True
+ allow_create = False
+ allow_retrieve = True
+ allow_update = False
+ allow_delete = False
+
+ service = volume_service.VolumeService()
+
+ # Properties
+ ec2_id = resource.prop('ec2_id')
+ user_id = resource.prop('user_id')
+ project_id = resource.prop('project_id')
+ host = resource.prop('host')
+ size = resource.prop('size')
+ status = resource.prop('status')
+ attach_status = resource.prop('attach_status')
+ display_name = resource.prop('display_name')
+ display_description = resource.prop('display_description')
+ provider_location = resource.prop('provider_location')
+ provider_auth = resource.prop('provider_auth')
+ snapshot_id = resource.prop('snapshot_id')
+ volume_type_id = resource.prop('volume_type_id')
+ source_volid = resource.prop('source_volid')
+ bootable = resource.prop('bootable')
+ provider_geometry = resource.prop('provider_geometry')
+ encryption_key_id = resource.prop('encryption_key_id')
+ migration_status = resource.prop('migration_status')
+ replication_status = resource.prop('replication_status')
+ replication_extended_status = resource.prop('replication_extended_status')
+ replication_driver_data = resource.prop('replication_driver_data')
+ consistencygroup_id = resource.prop('consistencygroup_id')
+ provider_id = resource.prop('provider_id')
+ multiattach = resource.prop('multiattach')
+
+
+ def action(self, session, body):
+ """Perform volume actions given the message body."""
+ url = utils.urljoin(self.base_path, self.id, 'action')
+ resp = session.put(url, service=self.service, json=body).body
+ return resp
+
+ def wait_for_status(self, session, status='ACTIVE', failures=None,
+ interval=5, wait=120):
+ """Wait for the server to be in some status.
+
+ :param session: The session to use for making this request.
+ :type session: :class:`~openstack.session.Session`
+ :param status: Desired status of the server.
+ :param list failures: Statuses that would indicate the transition
+ failed such as 'ERROR'.
+ :param interval: Number of seconds to wait between checks.
+ :param wait: Maximum number of seconds to wait for transition.
+
+ :return: Method returns self on success.
+ :raises: :class:`~openstack.exceptions.ResourceTimeout` transition
+ to status failed to occur in wait seconds.
+ :raises: :class:`~openstack.exceptions.ResourceFailure` resource
+ transitioned to one of the failure states.
+ """
+ try:
+ if self.status == status:
+ return self
+ except AttributeError:
+ pass
+ total_sleep = 0
+ if failures is None:
+ failures = []
+ while total_sleep < wait:
+ self.get(session)
+ if self.status == status:
+ return self
+ if self.status in failures:
+ msg = ("Resource %s transitioned to failure state %s" %
+ (self.id, self.status))
+ raise exceptions.ResourceFailure(msg)
+ time.sleep(interval)
+ total_sleep += interval
+ msg = "Timeout waiting for %s to transition to %s" % (self.id, status)
+ raise exceptions.ResourceTimeout(msg)
diff --git a/openstack/volume/version.py b/openstack/volume/version.py
new file mode 100644
index 0000000..1bcaaf6
--- /dev/null
+++ b/openstack/volume/version.py
@@ -0,0 +1,30 @@
+# 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 openstack.volume import volume_service
+from openstack import resource
+
+
+class Version(resource.Resource):
+ resource_key = 'volume'
+ resources_key = 'volumes'
+ base_path = '/volumes'
+ service = volume_service.VolumeService(
+ version=volume_service.VolumeService.UNVERSIONED
+ )
+
+ # capabilities
+ allow_list = True
+
+ # Properties
+ links = resource.prop('links')
+ status = resource.prop('status')
diff --git a/openstack/volume/volume_service.py b/openstack/volume/volume_service.py
new file mode 100644
index 0000000..19f5084
--- /dev/null
+++ b/openstack/volume/volume_service.py
@@ -0,0 +1,24 @@
+# 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 openstack.auth import service_filter
+
+
+class VolumeService(service_filter.ServiceFilter):
+ """The volume service."""
+
+ valid_versions = [service_filter.ValidVersion('v2')]
+
+ def __init__(self, version=None):
+ """Create an volume service."""
+ super(VolumeService, self).__init__(service_type='volume',
+ version=version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment