python-openstackclient 7.3.1__py3-none-any.whl → 8.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. openstackclient/common/availability_zone.py +3 -6
  2. openstackclient/common/clientmanager.py +2 -1
  3. openstackclient/common/envvars.py +57 -0
  4. openstackclient/common/extension.py +3 -11
  5. openstackclient/common/limits.py +1 -1
  6. openstackclient/common/project_cleanup.py +3 -2
  7. openstackclient/common/quota.py +54 -28
  8. openstackclient/compute/client.py +2 -5
  9. openstackclient/compute/v2/agent.py +5 -5
  10. openstackclient/compute/v2/aggregate.py +17 -15
  11. openstackclient/compute/v2/console.py +3 -4
  12. openstackclient/compute/v2/flavor.py +14 -18
  13. openstackclient/compute/v2/host.py +3 -3
  14. openstackclient/compute/v2/hypervisor.py +10 -4
  15. openstackclient/compute/v2/hypervisor_stats.py +1 -1
  16. openstackclient/compute/v2/keypair.py +8 -10
  17. openstackclient/compute/v2/server.py +70 -112
  18. openstackclient/compute/v2/server_backup.py +1 -1
  19. openstackclient/compute/v2/server_event.py +7 -16
  20. openstackclient/compute/v2/server_group.py +6 -6
  21. openstackclient/compute/v2/server_image.py +1 -1
  22. openstackclient/compute/v2/server_migration.py +6 -6
  23. openstackclient/compute/v2/server_volume.py +4 -4
  24. openstackclient/compute/v2/service.py +9 -13
  25. openstackclient/compute/v2/usage.py +4 -6
  26. openstackclient/identity/client.py +2 -4
  27. openstackclient/identity/common.py +16 -17
  28. openstackclient/identity/v2_0/ec2creds.py +4 -3
  29. openstackclient/identity/v2_0/endpoint.py +12 -10
  30. openstackclient/identity/v2_0/project.py +6 -6
  31. openstackclient/identity/v2_0/role.py +1 -1
  32. openstackclient/identity/v2_0/service.py +7 -7
  33. openstackclient/identity/v2_0/user.py +6 -21
  34. openstackclient/identity/v3/access_rule.py +2 -5
  35. openstackclient/identity/v3/consumer.py +4 -3
  36. openstackclient/identity/v3/credential.py +8 -9
  37. openstackclient/identity/v3/domain.py +1 -1
  38. openstackclient/identity/v3/ec2creds.py +4 -3
  39. openstackclient/identity/v3/endpoint.py +104 -88
  40. openstackclient/identity/v3/endpoint_group.py +1 -1
  41. openstackclient/identity/v3/group.py +3 -4
  42. openstackclient/identity/v3/identity_provider.py +1 -2
  43. openstackclient/identity/v3/limit.py +4 -9
  44. openstackclient/identity/v3/mapping.py +4 -3
  45. openstackclient/identity/v3/policy.py +5 -8
  46. openstackclient/identity/v3/project.py +6 -6
  47. openstackclient/identity/v3/region.py +2 -5
  48. openstackclient/identity/v3/registered_limit.py +4 -8
  49. openstackclient/identity/v3/role.py +15 -16
  50. openstackclient/identity/v3/service.py +8 -8
  51. openstackclient/identity/v3/service_provider.py +3 -6
  52. openstackclient/identity/v3/tag.py +2 -2
  53. openstackclient/identity/v3/token.py +1 -2
  54. openstackclient/identity/v3/trust.py +74 -25
  55. openstackclient/identity/v3/user.py +9 -6
  56. openstackclient/image/client.py +2 -5
  57. openstackclient/image/v1/image.py +11 -15
  58. openstackclient/image/v2/cache.py +2 -4
  59. openstackclient/image/v2/image.py +30 -37
  60. openstackclient/image/v2/metadef_namespaces.py +4 -3
  61. openstackclient/image/v2/metadef_resource_type_association.py +1 -2
  62. openstackclient/image/v2/metadef_resource_types.py +1 -2
  63. openstackclient/locale/tr_TR/LC_MESSAGES/openstackclient.po +9 -1370
  64. openstackclient/network/client.py +4 -10
  65. openstackclient/network/common.py +16 -12
  66. openstackclient/network/utils.py +3 -3
  67. openstackclient/network/v2/address_group.py +5 -9
  68. openstackclient/network/v2/address_scope.py +2 -3
  69. openstackclient/network/v2/default_security_group_rule.py +1 -2
  70. openstackclient/network/v2/floating_ip.py +14 -21
  71. openstackclient/network/v2/floating_ip_port_forwarding.py +7 -7
  72. openstackclient/network/v2/ip_availability.py +1 -2
  73. openstackclient/network/v2/l3_conntrack_helper.py +8 -12
  74. openstackclient/network/v2/local_ip.py +24 -26
  75. openstackclient/network/v2/local_ip_association.py +4 -5
  76. openstackclient/network/v2/ndp_proxy.py +9 -10
  77. openstackclient/network/v2/network.py +12 -16
  78. openstackclient/network/v2/network_agent.py +29 -37
  79. openstackclient/network/v2/network_auto_allocated_topology.py +4 -5
  80. openstackclient/network/v2/network_flavor.py +1 -1
  81. openstackclient/network/v2/network_flavor_profile.py +5 -5
  82. openstackclient/network/v2/network_meter.py +3 -3
  83. openstackclient/network/v2/network_meter_rule.py +5 -8
  84. openstackclient/network/v2/network_qos_policy.py +4 -4
  85. openstackclient/network/v2/network_qos_rule.py +4 -5
  86. openstackclient/network/v2/network_rbac.py +4 -4
  87. openstackclient/network/v2/network_segment.py +6 -7
  88. openstackclient/network/v2/network_segment_range.py +16 -20
  89. openstackclient/network/v2/network_trunk.py +24 -16
  90. openstackclient/network/v2/port.py +42 -31
  91. openstackclient/network/v2/router.py +55 -41
  92. openstackclient/network/v2/security_group.py +8 -15
  93. openstackclient/network/v2/security_group_rule.py +9 -10
  94. openstackclient/network/v2/subnet.py +31 -30
  95. openstackclient/network/v2/subnet_pool.py +4 -4
  96. openstackclient/object/client.py +2 -3
  97. openstackclient/object/v1/container.py +2 -3
  98. openstackclient/object/v1/object.py +2 -9
  99. openstackclient/shell.py +22 -5
  100. openstackclient/tests/functional/base.py +2 -2
  101. openstackclient/tests/functional/common/test_quota.py +3 -1
  102. openstackclient/tests/functional/compute/v2/common.py +12 -6
  103. openstackclient/tests/functional/compute/v2/test_server.py +2 -3
  104. openstackclient/tests/functional/compute/v2/test_server_event.py +1 -1
  105. openstackclient/tests/functional/identity/v2/test_user.py +1 -1
  106. openstackclient/tests/functional/identity/v3/common.py +3 -8
  107. openstackclient/tests/functional/identity/v3/test_application_credential.py +10 -10
  108. openstackclient/tests/functional/identity/v3/test_endpoint.py +3 -3
  109. openstackclient/tests/functional/identity/v3/test_group.py +3 -3
  110. openstackclient/tests/functional/identity/v3/test_idp.py +3 -7
  111. openstackclient/tests/functional/identity/v3/test_limit.py +4 -4
  112. openstackclient/tests/functional/identity/v3/test_project.py +5 -14
  113. openstackclient/tests/functional/identity/v3/test_region.py +1 -3
  114. openstackclient/tests/functional/identity/v3/test_registered_limit.py +3 -3
  115. openstackclient/tests/functional/identity/v3/test_role.py +1 -1
  116. openstackclient/tests/functional/identity/v3/test_role_assignment.py +13 -31
  117. openstackclient/tests/functional/identity/v3/test_service_provider.py +3 -7
  118. openstackclient/tests/functional/identity/v3/test_user.py +8 -8
  119. openstackclient/tests/functional/network/v2/common.py +7 -3
  120. openstackclient/tests/functional/network/v2/test_address_group.py +4 -0
  121. openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py +15 -11
  122. openstackclient/tests/functional/network/v2/test_local_ip.py +4 -0
  123. openstackclient/tests/functional/network/v2/test_network_meter_rule.py +2 -2
  124. openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py +2 -3
  125. openstackclient/tests/functional/network/v2/test_network_rbac.py +2 -2
  126. openstackclient/tests/functional/network/v2/test_network_trunk.py +1 -1
  127. openstackclient/tests/functional/network/v2/test_port.py +17 -7
  128. openstackclient/tests/functional/network/v2/test_router.py +42 -0
  129. openstackclient/tests/functional/network/v2/test_subnet_pool.py +4 -0
  130. openstackclient/tests/unit/api/test_compute_v2.py +67 -87
  131. openstackclient/tests/unit/common/test_availability_zone.py +6 -14
  132. openstackclient/tests/unit/common/test_command.py +1 -1
  133. openstackclient/tests/unit/common/test_extension.py +5 -7
  134. openstackclient/tests/unit/common/test_limits.py +1 -1
  135. openstackclient/tests/unit/common/test_project_cleanup.py +5 -6
  136. openstackclient/tests/unit/common/test_quota.py +51 -28
  137. openstackclient/tests/unit/compute/v2/fakes.py +4 -10
  138. openstackclient/tests/unit/compute/v2/test_agent.py +16 -16
  139. openstackclient/tests/unit/compute/v2/test_aggregate.py +56 -60
  140. openstackclient/tests/unit/compute/v2/test_console.py +16 -16
  141. openstackclient/tests/unit/compute/v2/test_flavor.py +71 -71
  142. openstackclient/tests/unit/compute/v2/test_host.py +8 -8
  143. openstackclient/tests/unit/compute/v2/test_hypervisor.py +22 -30
  144. openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -2
  145. openstackclient/tests/unit/compute/v2/test_keypair.py +24 -24
  146. openstackclient/tests/unit/compute/v2/test_server.py +524 -560
  147. openstackclient/tests/unit/compute/v2/test_server_backup.py +5 -7
  148. openstackclient/tests/unit/compute/v2/test_server_event.py +16 -18
  149. openstackclient/tests/unit/compute/v2/test_server_group.py +25 -31
  150. openstackclient/tests/unit/compute/v2/test_server_image.py +6 -8
  151. openstackclient/tests/unit/compute/v2/test_server_migration.py +37 -37
  152. openstackclient/tests/unit/compute/v2/test_server_volume.py +12 -12
  153. openstackclient/tests/unit/compute/v2/test_service.py +39 -45
  154. openstackclient/tests/unit/compute/v2/test_usage.py +5 -5
  155. openstackclient/tests/unit/identity/v2_0/fakes.py +1 -1
  156. openstackclient/tests/unit/identity/v3/test_access_rule.py +1 -3
  157. openstackclient/tests/unit/identity/v3/test_application_credential.py +1 -1
  158. openstackclient/tests/unit/identity/v3/test_credential.py +4 -4
  159. openstackclient/tests/unit/identity/v3/test_endpoint.py +167 -172
  160. openstackclient/tests/unit/identity/v3/test_mappings.py +2 -2
  161. openstackclient/tests/unit/identity/v3/test_trust.py +5 -2
  162. openstackclient/tests/unit/identity/v3/test_user.py +16 -0
  163. openstackclient/tests/unit/image/v1/fakes.py +2 -2
  164. openstackclient/tests/unit/image/v2/test_image.py +39 -1
  165. openstackclient/tests/unit/integ/cli/test_shell.py +1 -2
  166. openstackclient/tests/unit/network/test_common.py +2 -2
  167. openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +8 -14
  168. openstackclient/tests/unit/network/v2/test_floating_ip_network.py +49 -35
  169. openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +1 -1
  170. openstackclient/tests/unit/network/v2/test_network_compute.py +11 -11
  171. openstackclient/tests/unit/network/v2/test_network_trunk.py +2 -2
  172. openstackclient/tests/unit/network/v2/test_port.py +33 -5
  173. openstackclient/tests/unit/network/v2/test_router.py +120 -7
  174. openstackclient/tests/unit/network/v2/test_security_group_compute.py +11 -19
  175. openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +14 -14
  176. openstackclient/tests/unit/object/v1/test_object_all.py +4 -3
  177. openstackclient/tests/unit/test_shell.py +16 -13
  178. openstackclient/tests/unit/volume/v2/test_volume.py +1 -1
  179. openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +1 -1
  180. openstackclient/tests/unit/volume/v3/fakes.py +2 -8
  181. openstackclient/tests/unit/volume/v3/test_volume.py +1 -1
  182. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +3 -3
  183. openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +1 -2
  184. openstackclient/tests/unit/volume/v3/test_volume_transfer_request.py +1 -1
  185. openstackclient/volume/client.py +1 -3
  186. openstackclient/volume/v2/consistency_group.py +4 -8
  187. openstackclient/volume/v2/consistency_group_snapshot.py +1 -2
  188. openstackclient/volume/v2/qos_specs.py +1 -2
  189. openstackclient/volume/v2/volume.py +8 -16
  190. openstackclient/volume/v2/volume_backup.py +6 -7
  191. openstackclient/volume/v2/volume_snapshot.py +8 -9
  192. openstackclient/volume/v2/volume_transfer_request.py +0 -3
  193. openstackclient/volume/v2/volume_type.py +10 -21
  194. openstackclient/volume/v3/block_storage_cluster.py +3 -3
  195. openstackclient/volume/v3/block_storage_manage.py +1 -3
  196. openstackclient/volume/v3/volume.py +18 -19
  197. openstackclient/volume/v3/volume_attachment.py +3 -2
  198. openstackclient/volume/v3/volume_backup.py +7 -8
  199. openstackclient/volume/v3/volume_group.py +2 -1
  200. openstackclient/volume/v3/volume_group_snapshot.py +2 -1
  201. openstackclient/volume/v3/volume_snapshot.py +4 -3
  202. openstackclient/volume/v3/volume_type.py +10 -21
  203. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/AUTHORS +4 -0
  204. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/METADATA +7 -13
  205. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/RECORD +210 -233
  206. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/WHEEL +1 -1
  207. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/entry_points.txt +0 -41
  208. python_openstackclient-8.0.0.dist-info/pbr.json +1 -0
  209. openstackclient/tests/functional/volume/v1/__init__.py +0 -0
  210. openstackclient/tests/functional/volume/v1/common.py +0 -35
  211. openstackclient/tests/functional/volume/v1/test_qos.py +0 -100
  212. openstackclient/tests/functional/volume/v1/test_service.py +0 -76
  213. openstackclient/tests/functional/volume/v1/test_snapshot.py +0 -232
  214. openstackclient/tests/functional/volume/v1/test_transfer_request.py +0 -111
  215. openstackclient/tests/functional/volume/v1/test_volume.py +0 -228
  216. openstackclient/tests/functional/volume/v1/test_volume_type.py +0 -213
  217. openstackclient/tests/unit/volume/v1/__init__.py +0 -0
  218. openstackclient/tests/unit/volume/v1/fakes.py +0 -615
  219. openstackclient/tests/unit/volume/v1/test_qos_specs.py +0 -471
  220. openstackclient/tests/unit/volume/v1/test_service.py +0 -295
  221. openstackclient/tests/unit/volume/v1/test_transfer_request.py +0 -380
  222. openstackclient/tests/unit/volume/v1/test_type.py +0 -633
  223. openstackclient/tests/unit/volume/v1/test_volume.py +0 -1447
  224. openstackclient/tests/unit/volume/v1/test_volume_backup.py +0 -435
  225. openstackclient/volume/v1/__init__.py +0 -0
  226. openstackclient/volume/v1/qos_specs.py +0 -377
  227. openstackclient/volume/v1/service.py +0 -136
  228. openstackclient/volume/v1/volume.py +0 -734
  229. openstackclient/volume/v1/volume_backup.py +0 -302
  230. openstackclient/volume/v1/volume_snapshot.py +0 -433
  231. openstackclient/volume/v1/volume_transfer_request.py +0 -200
  232. openstackclient/volume/v1/volume_type.py +0 -520
  233. python_openstackclient-7.3.1.dist-info/pbr.json +0 -1
  234. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/LICENSE +0 -0
  235. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/top_level.txt +0 -0
@@ -1,734 +0,0 @@
1
- # Copyright 2012-2013 OpenStack Foundation
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
- # not use this file except in compliance with the License. You may obtain
5
- # a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
- # License for the specific language governing permissions and limitations
13
- # under the License.
14
- #
15
-
16
- """Volume v1 Volume action implementations"""
17
-
18
- import argparse
19
- import functools
20
- import logging
21
-
22
- from cliff import columns as cliff_columns
23
- from osc_lib.cli import format_columns
24
- from osc_lib.cli import parseractions
25
- from osc_lib.command import command
26
- from osc_lib import exceptions
27
- from osc_lib import utils
28
-
29
- from openstackclient.common import pagination
30
- from openstackclient.i18n import _
31
-
32
-
33
- LOG = logging.getLogger(__name__)
34
-
35
-
36
- class AttachmentsColumn(cliff_columns.FormattableColumn):
37
- """Formattable column for attachments column.
38
-
39
- Unlike the parent FormattableColumn class, the initializer of the
40
- class takes server_cache as the second argument.
41
- osc_lib.utils.get_item_properties instantiate cliff FormattableColumn
42
- object with a single parameter "column value", so you need to pass
43
- a partially initialized class like
44
- ``functools.partial(AttachmentsColumn, server_cache)``.
45
- """
46
-
47
- def __init__(self, value, server_cache=None):
48
- super().__init__(value)
49
- self._server_cache = server_cache or {}
50
-
51
- def human_readable(self):
52
- """Return a formatted string of a volume's attached instances
53
-
54
- :rtype: a string of formatted instances
55
- """
56
-
57
- msg = ''
58
- for attachment in self._value:
59
- server = attachment['server_id']
60
- if server in self._server_cache.keys():
61
- server = self._server_cache[server].name
62
- device = attachment['device']
63
- msg += f'Attached to {server} on {device} '
64
- return msg
65
-
66
-
67
- def _check_size_arg(args):
68
- """Check whether --size option is required or not.
69
-
70
- Require size parameter only in case when snapshot or source
71
- volume is not specified.
72
- """
73
-
74
- if (args.snapshot or args.source) is None and args.size is None:
75
- msg = _(
76
- "--size is a required option if snapshot "
77
- "or source volume is not specified."
78
- )
79
- raise exceptions.CommandError(msg)
80
-
81
-
82
- class CreateVolume(command.ShowOne):
83
- _description = _("Create new volume")
84
-
85
- def get_parser(self, prog_name):
86
- parser = super().get_parser(prog_name)
87
- parser.add_argument(
88
- 'name',
89
- metavar='<name>',
90
- help=_('Volume name'),
91
- )
92
- parser.add_argument(
93
- '--size',
94
- metavar='<size>',
95
- type=int,
96
- help=_(
97
- "Volume size in GB (Required unless --snapshot or "
98
- "--source is specified)"
99
- ),
100
- )
101
- parser.add_argument(
102
- '--type',
103
- metavar='<volume-type>',
104
- help=_("Set the type of volume"),
105
- )
106
- source_group = parser.add_mutually_exclusive_group()
107
- source_group.add_argument(
108
- '--image',
109
- metavar='<image>',
110
- help=_('Use <image> as source of volume (name or ID)'),
111
- )
112
- source_group.add_argument(
113
- '--snapshot',
114
- metavar='<snapshot>',
115
- help=_('Use <snapshot> as source of volume (name or ID)'),
116
- )
117
- source_group.add_argument(
118
- '--snapshot-id',
119
- metavar='<snapshot-id>',
120
- help=argparse.SUPPRESS,
121
- )
122
- source_group.add_argument(
123
- '--source',
124
- metavar='<volume>',
125
- help=_('Volume to clone (name or ID)'),
126
- )
127
- parser.add_argument(
128
- '--description',
129
- metavar='<description>',
130
- help=_('Volume description'),
131
- )
132
- parser.add_argument(
133
- '--user',
134
- metavar='<user>',
135
- help=_('Specify an alternate user (name or ID)'),
136
- )
137
- parser.add_argument(
138
- '--project',
139
- metavar='<project>',
140
- help=_('Specify an alternate project (name or ID)'),
141
- )
142
- parser.add_argument(
143
- '--availability-zone',
144
- metavar='<availability-zone>',
145
- help=_('Create volume in <availability-zone>'),
146
- )
147
- parser.add_argument(
148
- '--property',
149
- metavar='<key=value>',
150
- action=parseractions.KeyValueAction,
151
- help=_(
152
- 'Set a property on this volume '
153
- '(repeat option to set multiple properties)'
154
- ),
155
- )
156
- bootable_group = parser.add_mutually_exclusive_group()
157
- bootable_group.add_argument(
158
- "--bootable",
159
- action="store_true",
160
- help=_("Mark volume as bootable"),
161
- )
162
- bootable_group.add_argument(
163
- "--non-bootable",
164
- action="store_true",
165
- help=_("Mark volume as non-bootable (default)"),
166
- )
167
- readonly_group = parser.add_mutually_exclusive_group()
168
- readonly_group.add_argument(
169
- "--read-only",
170
- action="store_true",
171
- help=_("Set volume to read-only access mode"),
172
- )
173
- readonly_group.add_argument(
174
- "--read-write",
175
- action="store_true",
176
- help=_("Set volume to read-write access mode (default)"),
177
- )
178
-
179
- return parser
180
-
181
- def take_action(self, parsed_args):
182
- _check_size_arg(parsed_args)
183
- identity_client = self.app.client_manager.identity
184
- image_client = self.app.client_manager.image
185
- volume_client = self.app.client_manager.volume
186
-
187
- source_volume = None
188
- if parsed_args.source:
189
- source_volume = utils.find_resource(
190
- volume_client.volumes,
191
- parsed_args.source,
192
- ).id
193
-
194
- project = None
195
- if parsed_args.project:
196
- project = utils.find_resource(
197
- identity_client.tenants,
198
- parsed_args.project,
199
- ).id
200
-
201
- user = None
202
- if parsed_args.user:
203
- user = utils.find_resource(
204
- identity_client.users,
205
- parsed_args.user,
206
- ).id
207
-
208
- image = None
209
- if parsed_args.image:
210
- image = image_client.find_image(
211
- parsed_args.image,
212
- ignore_missing=False,
213
- ).id
214
-
215
- snapshot = parsed_args.snapshot or parsed_args.snapshot_id
216
-
217
- volume = volume_client.volumes.create(
218
- parsed_args.size,
219
- snapshot,
220
- source_volume,
221
- parsed_args.name,
222
- parsed_args.description,
223
- parsed_args.type,
224
- user,
225
- project,
226
- parsed_args.availability_zone,
227
- parsed_args.property,
228
- image,
229
- )
230
-
231
- if parsed_args.bootable or parsed_args.non_bootable:
232
- try:
233
- if utils.wait_for_status(
234
- volume_client.volumes.get,
235
- volume.id,
236
- success_status=['available'],
237
- error_status=['error'],
238
- sleep_time=1,
239
- ):
240
- volume_client.volumes.set_bootable(
241
- volume.id, parsed_args.bootable
242
- )
243
- else:
244
- msg = _(
245
- "Volume status is not available for setting boot "
246
- "state"
247
- )
248
- raise exceptions.CommandError(msg)
249
- except Exception as e:
250
- LOG.error(_("Failed to set volume bootable property: %s"), e)
251
- if parsed_args.read_only or parsed_args.read_write:
252
- try:
253
- if utils.wait_for_status(
254
- volume_client.volumes.get,
255
- volume.id,
256
- success_status=['available'],
257
- error_status=['error'],
258
- sleep_time=1,
259
- ):
260
- volume_client.volumes.update_readonly_flag(
261
- volume.id, parsed_args.read_only
262
- )
263
- else:
264
- msg = _(
265
- "Volume status is not available for setting it"
266
- "read only."
267
- )
268
- raise exceptions.CommandError(msg)
269
- except Exception as e:
270
- LOG.error(
271
- _(
272
- "Failed to set volume read-only access "
273
- "mode flag: %s"
274
- ),
275
- e,
276
- )
277
-
278
- # Map 'metadata' column to 'properties'
279
- volume._info.update(
280
- {
281
- 'properties': format_columns.DictColumn(
282
- volume._info.pop('metadata')
283
- ),
284
- 'type': volume._info.pop('volume_type'),
285
- },
286
- )
287
- # Replace "display_name" by "name", keep consistent in v1 and v2
288
- if 'display_name' in volume._info:
289
- volume._info.update({'name': volume._info.pop('display_name')})
290
- volume_info = utils.backward_compat_col_showone(
291
- volume._info, parsed_args.columns, {'display_name': 'name'}
292
- )
293
-
294
- return zip(*sorted(volume_info.items()))
295
-
296
-
297
- class DeleteVolume(command.Command):
298
- _description = _("Delete volume(s)")
299
-
300
- def get_parser(self, prog_name):
301
- parser = super().get_parser(prog_name)
302
- parser.add_argument(
303
- 'volumes',
304
- metavar='<volume>',
305
- nargs="+",
306
- help=_('Volume(s) to delete (name or ID)'),
307
- )
308
- parser.add_argument(
309
- '--force',
310
- action='store_true',
311
- default=False,
312
- help=_(
313
- 'Attempt forced removal of volume(s), regardless of state '
314
- '(defaults to False)'
315
- ),
316
- )
317
- return parser
318
-
319
- def take_action(self, parsed_args):
320
- volume_client = self.app.client_manager.volume
321
- result = 0
322
-
323
- for i in parsed_args.volumes:
324
- try:
325
- volume_obj = utils.find_resource(volume_client.volumes, i)
326
- if parsed_args.force:
327
- volume_client.volumes.force_delete(volume_obj.id)
328
- else:
329
- volume_client.volumes.delete(volume_obj.id)
330
- except Exception as e:
331
- result += 1
332
- LOG.error(
333
- _(
334
- "Failed to delete volume with "
335
- "name or ID '%(volume)s': %(e)s"
336
- ),
337
- {'volume': i, 'e': e},
338
- )
339
-
340
- if result > 0:
341
- total = len(parsed_args.volumes)
342
- msg = _("%(result)s of %(total)s volumes failed " "to delete.") % {
343
- 'result': result,
344
- 'total': total,
345
- }
346
- raise exceptions.CommandError(msg)
347
-
348
-
349
- class ListVolume(command.Lister):
350
- _description = _("List volumes")
351
-
352
- def get_parser(self, prog_name):
353
- parser = super().get_parser(prog_name)
354
- parser.add_argument(
355
- '--name',
356
- metavar='<name>',
357
- help=_('Filter results by volume name'),
358
- )
359
- parser.add_argument(
360
- '--status',
361
- metavar='<status>',
362
- help=_('Filter results by status'),
363
- )
364
- parser.add_argument(
365
- '--all-projects',
366
- action='store_true',
367
- default=False,
368
- help=_('Include all projects (admin only)'),
369
- )
370
- parser.add_argument(
371
- '--long',
372
- action='store_true',
373
- default=False,
374
- help=_('List additional fields in output'),
375
- )
376
- pagination.add_offset_pagination_option_to_parser(parser)
377
- return parser
378
-
379
- def take_action(self, parsed_args):
380
- volume_client = self.app.client_manager.volume
381
-
382
- if parsed_args.long:
383
- columns = (
384
- 'ID',
385
- 'Display Name',
386
- 'Status',
387
- 'Size',
388
- 'Volume Type',
389
- 'Bootable',
390
- 'Attachments',
391
- 'Metadata',
392
- )
393
- column_headers = (
394
- 'ID',
395
- 'Name',
396
- 'Status',
397
- 'Size',
398
- 'Type',
399
- 'Bootable',
400
- 'Attached to',
401
- 'Properties',
402
- )
403
- else:
404
- columns = (
405
- 'ID',
406
- 'Display Name',
407
- 'Status',
408
- 'Size',
409
- 'Attachments',
410
- )
411
- column_headers = (
412
- 'ID',
413
- 'Name',
414
- 'Status',
415
- 'Size',
416
- 'Attached to',
417
- )
418
-
419
- # Cache the server list
420
- server_cache = {}
421
- try:
422
- compute_client = self.app.client_manager.sdk_connection.compute
423
- for s in compute_client.servers():
424
- server_cache[s.id] = s
425
- except Exception: # noqa: S110
426
- # Just forget it if there's any trouble
427
- pass
428
- AttachmentsColumnWithCache = functools.partial(
429
- AttachmentsColumn, server_cache=server_cache
430
- )
431
-
432
- search_opts = {
433
- 'all_tenants': parsed_args.all_projects,
434
- 'display_name': parsed_args.name,
435
- 'status': parsed_args.status,
436
- }
437
-
438
- if parsed_args.offset:
439
- search_opts['offset'] = parsed_args.offset
440
-
441
- data = volume_client.volumes.list(
442
- search_opts=search_opts,
443
- limit=parsed_args.limit,
444
- )
445
- column_headers = utils.backward_compat_col_lister(
446
- column_headers, parsed_args.columns, {'Display Name': 'Name'}
447
- )
448
-
449
- return (
450
- column_headers,
451
- (
452
- utils.get_item_properties(
453
- s,
454
- columns,
455
- formatters={
456
- 'Metadata': format_columns.DictColumn,
457
- 'Attachments': AttachmentsColumnWithCache,
458
- },
459
- )
460
- for s in data
461
- ),
462
- )
463
-
464
-
465
- class MigrateVolume(command.Command):
466
- _description = _("Migrate volume to a new host")
467
-
468
- def get_parser(self, prog_name):
469
- parser = super().get_parser(prog_name)
470
- parser.add_argument(
471
- 'volume',
472
- metavar="<volume>",
473
- help=_("Volume to migrate (name or ID)"),
474
- )
475
- parser.add_argument(
476
- '--host',
477
- metavar="<host>",
478
- required=True,
479
- help=_(
480
- "Destination host (takes the form: host@backend-name#pool)"
481
- ),
482
- )
483
- parser.add_argument(
484
- '--force-host-copy',
485
- action="store_true",
486
- help=_(
487
- "Enable generic host-based force-migration, "
488
- "which bypasses driver optimizations"
489
- ),
490
- )
491
- return parser
492
-
493
- def take_action(self, parsed_args):
494
- volume_client = self.app.client_manager.volume
495
- volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
496
- volume_client.volumes.migrate_volume(
497
- volume.id,
498
- parsed_args.host,
499
- parsed_args.force_host_copy,
500
- )
501
-
502
-
503
- class SetVolume(command.Command):
504
- _description = _("Set volume properties")
505
-
506
- def get_parser(self, prog_name):
507
- parser = super().get_parser(prog_name)
508
- parser.add_argument(
509
- 'volume',
510
- metavar='<volume>',
511
- help=_('Volume to modify (name or ID)'),
512
- )
513
- parser.add_argument(
514
- '--name',
515
- metavar='<name>',
516
- help=_('New volume name'),
517
- )
518
- parser.add_argument(
519
- '--description',
520
- metavar='<description>',
521
- help=_('New volume description'),
522
- )
523
- parser.add_argument(
524
- '--size',
525
- metavar='<size>',
526
- type=int,
527
- help=_('Extend volume size in GB'),
528
- )
529
- parser.add_argument(
530
- "--no-property",
531
- dest="no_property",
532
- action="store_true",
533
- help=_(
534
- "Remove all properties from <volume> "
535
- "(specify both --no-property and --property to "
536
- "remove the current properties before setting "
537
- "new properties.)"
538
- ),
539
- )
540
- parser.add_argument(
541
- '--property',
542
- metavar='<key=value>',
543
- action=parseractions.KeyValueAction,
544
- help=_(
545
- 'Set a property on this volume '
546
- '(repeat option to set multiple properties)'
547
- ),
548
- )
549
- bootable_group = parser.add_mutually_exclusive_group()
550
- bootable_group.add_argument(
551
- "--bootable",
552
- action="store_true",
553
- help=_("Mark volume as bootable"),
554
- )
555
- bootable_group.add_argument(
556
- "--non-bootable",
557
- action="store_true",
558
- help=_("Mark volume as non-bootable"),
559
- )
560
- readonly_group = parser.add_mutually_exclusive_group()
561
- readonly_group.add_argument(
562
- "--read-only",
563
- action="store_true",
564
- help=_("Set volume to read-only access mode"),
565
- )
566
- readonly_group.add_argument(
567
- "--read-write",
568
- action="store_true",
569
- help=_("Set volume to read-write access mode"),
570
- )
571
- return parser
572
-
573
- def take_action(self, parsed_args):
574
- volume_client = self.app.client_manager.volume
575
- volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
576
-
577
- result = 0
578
- if parsed_args.size:
579
- try:
580
- if volume.status != 'available':
581
- msg = (
582
- _(
583
- "Volume is in %s state, it must be available "
584
- "before size can be extended"
585
- )
586
- % volume.status
587
- )
588
- raise exceptions.CommandError(msg)
589
- if parsed_args.size <= volume.size:
590
- msg = (
591
- _("New size must be greater than %s GB") % volume.size
592
- )
593
- raise exceptions.CommandError(msg)
594
- volume_client.volumes.extend(volume.id, parsed_args.size)
595
- except Exception as e:
596
- LOG.error(_("Failed to set volume size: %s"), e)
597
- result += 1
598
-
599
- if parsed_args.no_property:
600
- try:
601
- volume_client.volumes.delete_metadata(
602
- volume.id, volume.metadata.keys()
603
- )
604
- except Exception as e:
605
- LOG.error(_("Failed to clean volume properties: %s"), e)
606
- result += 1
607
-
608
- if parsed_args.property:
609
- try:
610
- volume_client.volumes.set_metadata(
611
- volume.id, parsed_args.property
612
- )
613
- except Exception as e:
614
- LOG.error(_("Failed to set volume property: %s"), e)
615
- result += 1
616
- if parsed_args.bootable or parsed_args.non_bootable:
617
- try:
618
- volume_client.volumes.set_bootable(
619
- volume.id, parsed_args.bootable
620
- )
621
- except Exception as e:
622
- LOG.error(_("Failed to set volume bootable property: %s"), e)
623
- result += 1
624
- if parsed_args.read_only or parsed_args.read_write:
625
- try:
626
- volume_client.volumes.update_readonly_flag(
627
- volume.id, parsed_args.read_only
628
- )
629
- except Exception as e:
630
- LOG.error(
631
- _(
632
- "Failed to set volume read-only access "
633
- "mode flag: %s"
634
- ),
635
- e,
636
- )
637
- result += 1
638
- kwargs = {}
639
- if parsed_args.name:
640
- kwargs['display_name'] = parsed_args.name
641
- if parsed_args.description:
642
- kwargs['display_description'] = parsed_args.description
643
- if kwargs:
644
- try:
645
- volume_client.volumes.update(volume.id, **kwargs)
646
- except Exception as e:
647
- LOG.error(
648
- _(
649
- "Failed to update volume display name "
650
- "or display description: %s"
651
- ),
652
- e,
653
- )
654
- result += 1
655
-
656
- if result > 0:
657
- raise exceptions.CommandError(
658
- _("One or more of the " "set operations failed")
659
- )
660
-
661
-
662
- class ShowVolume(command.ShowOne):
663
- _description = _("Show volume details")
664
-
665
- def get_parser(self, prog_name):
666
- parser = super().get_parser(prog_name)
667
- parser.add_argument(
668
- 'volume',
669
- metavar='<volume>',
670
- help=_('Volume to display (name or ID)'),
671
- )
672
- return parser
673
-
674
- def take_action(self, parsed_args):
675
- volume_client = self.app.client_manager.volume
676
- volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
677
- # Map 'metadata' column to 'properties'
678
- volume._info.update(
679
- {
680
- 'properties': format_columns.DictColumn(
681
- volume._info.pop('metadata')
682
- ),
683
- 'type': volume._info.pop('volume_type'),
684
- },
685
- )
686
- if 'os-vol-tenant-attr:tenant_id' in volume._info:
687
- volume._info.update(
688
- {
689
- 'project_id': volume._info.pop(
690
- 'os-vol-tenant-attr:tenant_id'
691
- )
692
- }
693
- )
694
- # Replace "display_name" by "name", keep consistent in v1 and v2
695
- if 'display_name' in volume._info:
696
- volume._info.update({'name': volume._info.pop('display_name')})
697
-
698
- volume_info = utils.backward_compat_col_showone(
699
- volume._info, parsed_args.columns, {'display_name': 'name'}
700
- )
701
-
702
- return zip(*sorted(volume_info.items()))
703
-
704
-
705
- class UnsetVolume(command.Command):
706
- _description = _("Unset volume properties")
707
-
708
- def get_parser(self, prog_name):
709
- parser = super().get_parser(prog_name)
710
- parser.add_argument(
711
- 'volume',
712
- metavar='<volume>',
713
- help=_('Volume to modify (name or ID)'),
714
- )
715
- parser.add_argument(
716
- '--property',
717
- metavar='<key>',
718
- action='append',
719
- help=_(
720
- 'Remove a property from volume '
721
- '(repeat option to remove multiple properties)'
722
- ),
723
- )
724
- return parser
725
-
726
- def take_action(self, parsed_args):
727
- volume_client = self.app.client_manager.volume
728
- volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
729
-
730
- if parsed_args.property:
731
- volume_client.volumes.delete_metadata(
732
- volume.id,
733
- parsed_args.property,
734
- )