python-openstackclient 7.4.0__py3-none-any.whl → 8.1.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 (264) 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 +7 -5
  9. openstackclient/compute/v2/agent.py +5 -5
  10. openstackclient/compute/v2/aggregate.py +17 -15
  11. openstackclient/compute/v2/console.py +10 -4
  12. openstackclient/compute/v2/console_connection.py +48 -0
  13. openstackclient/compute/v2/flavor.py +14 -18
  14. openstackclient/compute/v2/host.py +3 -3
  15. openstackclient/compute/v2/hypervisor.py +10 -4
  16. openstackclient/compute/v2/hypervisor_stats.py +1 -1
  17. openstackclient/compute/v2/keypair.py +18 -13
  18. openstackclient/compute/v2/server.py +144 -121
  19. openstackclient/compute/v2/server_backup.py +1 -1
  20. openstackclient/compute/v2/server_event.py +8 -17
  21. openstackclient/compute/v2/server_group.py +6 -6
  22. openstackclient/compute/v2/server_image.py +1 -1
  23. openstackclient/compute/v2/server_migration.py +6 -6
  24. openstackclient/compute/v2/server_volume.py +4 -4
  25. openstackclient/compute/v2/service.py +9 -13
  26. openstackclient/compute/v2/usage.py +4 -6
  27. openstackclient/identity/client.py +2 -4
  28. openstackclient/identity/common.py +95 -17
  29. openstackclient/identity/v2_0/ec2creds.py +4 -3
  30. openstackclient/identity/v2_0/endpoint.py +12 -10
  31. openstackclient/identity/v2_0/project.py +6 -6
  32. openstackclient/identity/v2_0/role.py +1 -1
  33. openstackclient/identity/v2_0/service.py +7 -7
  34. openstackclient/identity/v2_0/user.py +6 -21
  35. openstackclient/identity/v3/access_rule.py +2 -5
  36. openstackclient/identity/v3/application_credential.py +2 -2
  37. openstackclient/identity/v3/consumer.py +4 -3
  38. openstackclient/identity/v3/credential.py +6 -7
  39. openstackclient/identity/v3/domain.py +63 -44
  40. openstackclient/identity/v3/ec2creds.py +4 -3
  41. openstackclient/identity/v3/endpoint.py +104 -88
  42. openstackclient/identity/v3/endpoint_group.py +1 -1
  43. openstackclient/identity/v3/group.py +116 -72
  44. openstackclient/identity/v3/identity_provider.py +1 -2
  45. openstackclient/identity/v3/limit.py +4 -9
  46. openstackclient/identity/v3/mapping.py +4 -3
  47. openstackclient/identity/v3/policy.py +5 -8
  48. openstackclient/identity/v3/project.py +23 -6
  49. openstackclient/identity/v3/region.py +2 -5
  50. openstackclient/identity/v3/registered_limit.py +4 -8
  51. openstackclient/identity/v3/role.py +15 -16
  52. openstackclient/identity/v3/service.py +8 -8
  53. openstackclient/identity/v3/service_provider.py +3 -6
  54. openstackclient/identity/v3/tag.py +2 -2
  55. openstackclient/identity/v3/token.py +1 -2
  56. openstackclient/identity/v3/trust.py +74 -25
  57. openstackclient/identity/v3/user.py +47 -11
  58. openstackclient/image/client.py +7 -5
  59. openstackclient/image/v1/image.py +11 -15
  60. openstackclient/image/v2/cache.py +2 -4
  61. openstackclient/image/v2/image.py +41 -48
  62. openstackclient/image/v2/metadef_namespaces.py +4 -3
  63. openstackclient/image/v2/metadef_resource_type_association.py +1 -2
  64. openstackclient/image/v2/metadef_resource_types.py +1 -2
  65. openstackclient/locale/tr_TR/LC_MESSAGES/openstackclient.po +9 -1370
  66. openstackclient/network/client.py +4 -16
  67. openstackclient/network/common.py +16 -12
  68. openstackclient/network/utils.py +3 -3
  69. openstackclient/network/v2/address_group.py +5 -9
  70. openstackclient/network/v2/address_scope.py +2 -3
  71. openstackclient/network/v2/default_security_group_rule.py +1 -2
  72. openstackclient/network/v2/floating_ip.py +69 -47
  73. openstackclient/network/v2/floating_ip_port_forwarding.py +7 -7
  74. openstackclient/network/v2/ip_availability.py +1 -2
  75. openstackclient/network/v2/l3_conntrack_helper.py +8 -12
  76. openstackclient/network/v2/local_ip.py +24 -26
  77. openstackclient/network/v2/local_ip_association.py +4 -5
  78. openstackclient/network/v2/ndp_proxy.py +9 -10
  79. openstackclient/network/v2/network.py +12 -16
  80. openstackclient/network/v2/network_agent.py +29 -37
  81. openstackclient/network/v2/network_auto_allocated_topology.py +4 -5
  82. openstackclient/network/v2/network_flavor.py +1 -1
  83. openstackclient/network/v2/network_flavor_profile.py +5 -5
  84. openstackclient/network/v2/network_meter.py +3 -3
  85. openstackclient/network/v2/network_meter_rule.py +5 -8
  86. openstackclient/network/v2/network_qos_policy.py +4 -4
  87. openstackclient/network/v2/network_qos_rule.py +7 -16
  88. openstackclient/network/v2/network_rbac.py +4 -4
  89. openstackclient/network/v2/network_segment.py +6 -7
  90. openstackclient/network/v2/network_segment_range.py +16 -20
  91. openstackclient/network/v2/network_trunk.py +24 -16
  92. openstackclient/network/v2/port.py +28 -29
  93. openstackclient/network/v2/router.py +53 -42
  94. openstackclient/network/v2/security_group.py +13 -19
  95. openstackclient/network/v2/security_group_rule.py +10 -11
  96. openstackclient/network/v2/subnet.py +31 -30
  97. openstackclient/network/v2/subnet_pool.py +4 -4
  98. openstackclient/object/client.py +2 -3
  99. openstackclient/object/v1/container.py +2 -3
  100. openstackclient/object/v1/object.py +2 -9
  101. openstackclient/shell.py +22 -5
  102. openstackclient/tests/functional/base.py +7 -3
  103. openstackclient/tests/functional/common/test_quota.py +3 -1
  104. openstackclient/tests/functional/compute/v2/common.py +12 -6
  105. openstackclient/tests/functional/compute/v2/test_keypair.py +41 -5
  106. openstackclient/tests/functional/compute/v2/test_server.py +2 -3
  107. openstackclient/tests/functional/compute/v2/test_server_event.py +1 -1
  108. openstackclient/tests/functional/identity/v2/test_user.py +1 -1
  109. openstackclient/tests/functional/identity/v3/common.py +3 -8
  110. openstackclient/tests/functional/identity/v3/test_application_credential.py +10 -10
  111. openstackclient/tests/functional/identity/v3/test_endpoint.py +3 -3
  112. openstackclient/tests/functional/identity/v3/test_group.py +3 -3
  113. openstackclient/tests/functional/identity/v3/test_idp.py +3 -7
  114. openstackclient/tests/functional/identity/v3/test_limit.py +4 -4
  115. openstackclient/tests/functional/identity/v3/test_project.py +5 -14
  116. openstackclient/tests/functional/identity/v3/test_region.py +1 -3
  117. openstackclient/tests/functional/identity/v3/test_registered_limit.py +3 -3
  118. openstackclient/tests/functional/identity/v3/test_role.py +1 -1
  119. openstackclient/tests/functional/identity/v3/test_role_assignment.py +13 -31
  120. openstackclient/tests/functional/identity/v3/test_service_provider.py +3 -7
  121. openstackclient/tests/functional/identity/v3/test_user.py +8 -8
  122. openstackclient/tests/functional/network/v2/common.py +7 -3
  123. openstackclient/tests/functional/network/v2/test_address_group.py +4 -0
  124. openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py +15 -11
  125. openstackclient/tests/functional/network/v2/test_local_ip.py +4 -0
  126. openstackclient/tests/functional/network/v2/test_network_meter_rule.py +2 -2
  127. openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py +2 -3
  128. openstackclient/tests/functional/network/v2/test_network_rbac.py +2 -2
  129. openstackclient/tests/functional/network/v2/test_network_trunk.py +1 -1
  130. openstackclient/tests/functional/network/v2/test_port.py +17 -7
  131. openstackclient/tests/functional/network/v2/test_router.py +42 -0
  132. openstackclient/tests/functional/network/v2/test_subnet_pool.py +4 -0
  133. openstackclient/tests/unit/api/test_compute_v2.py +67 -87
  134. openstackclient/tests/unit/common/test_availability_zone.py +6 -14
  135. openstackclient/tests/unit/common/test_command.py +1 -1
  136. openstackclient/tests/unit/common/test_extension.py +5 -7
  137. openstackclient/tests/unit/common/test_limits.py +1 -1
  138. openstackclient/tests/unit/common/test_project_cleanup.py +5 -6
  139. openstackclient/tests/unit/common/test_quota.py +51 -28
  140. openstackclient/tests/unit/compute/v2/fakes.py +85 -315
  141. openstackclient/tests/unit/compute/v2/test_agent.py +16 -16
  142. openstackclient/tests/unit/compute/v2/test_aggregate.py +56 -60
  143. openstackclient/tests/unit/compute/v2/test_console.py +34 -17
  144. openstackclient/tests/unit/compute/v2/test_console_connection.py +72 -0
  145. openstackclient/tests/unit/compute/v2/test_flavor.py +72 -72
  146. openstackclient/tests/unit/compute/v2/test_host.py +8 -8
  147. openstackclient/tests/unit/compute/v2/test_hypervisor.py +22 -30
  148. openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -2
  149. openstackclient/tests/unit/compute/v2/test_keypair.py +36 -29
  150. openstackclient/tests/unit/compute/v2/test_server.py +693 -606
  151. openstackclient/tests/unit/compute/v2/test_server_backup.py +36 -77
  152. openstackclient/tests/unit/compute/v2/test_server_event.py +18 -20
  153. openstackclient/tests/unit/compute/v2/test_server_group.py +25 -31
  154. openstackclient/tests/unit/compute/v2/test_server_image.py +37 -78
  155. openstackclient/tests/unit/compute/v2/test_server_migration.py +41 -41
  156. openstackclient/tests/unit/compute/v2/test_server_volume.py +12 -12
  157. openstackclient/tests/unit/compute/v2/test_service.py +39 -45
  158. openstackclient/tests/unit/compute/v2/test_usage.py +5 -5
  159. openstackclient/tests/unit/identity/v2_0/fakes.py +1 -1
  160. openstackclient/tests/unit/identity/v3/test_access_rule.py +1 -3
  161. openstackclient/tests/unit/identity/v3/test_application_credential.py +48 -26
  162. openstackclient/tests/unit/identity/v3/test_domain.py +115 -105
  163. openstackclient/tests/unit/identity/v3/test_endpoint.py +167 -172
  164. openstackclient/tests/unit/identity/v3/test_group.py +353 -202
  165. openstackclient/tests/unit/identity/v3/test_mappings.py +2 -2
  166. openstackclient/tests/unit/identity/v3/test_project.py +16 -0
  167. openstackclient/tests/unit/identity/v3/test_trust.py +5 -2
  168. openstackclient/tests/unit/identity/v3/test_user.py +102 -6
  169. openstackclient/tests/unit/image/v1/fakes.py +2 -2
  170. openstackclient/tests/unit/image/v1/test_image.py +8 -9
  171. openstackclient/tests/unit/image/v2/test_image.py +84 -46
  172. openstackclient/tests/unit/integ/cli/test_shell.py +1 -2
  173. openstackclient/tests/unit/network/test_common.py +2 -2
  174. openstackclient/tests/unit/network/v2/fakes.py +405 -485
  175. openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +8 -14
  176. openstackclient/tests/unit/network/v2/test_floating_ip_network.py +62 -54
  177. openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +1 -1
  178. openstackclient/tests/unit/network/v2/test_l3_conntrack_helper.py +2 -2
  179. openstackclient/tests/unit/network/v2/test_ndp_proxy.py +1 -3
  180. openstackclient/tests/unit/network/v2/test_network.py +4 -4
  181. openstackclient/tests/unit/network/v2/test_network_agent.py +15 -29
  182. openstackclient/tests/unit/network/v2/test_network_compute.py +11 -11
  183. openstackclient/tests/unit/network/v2/test_network_qos_policy.py +16 -19
  184. openstackclient/tests/unit/network/v2/test_network_qos_rule.py +79 -152
  185. openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +4 -6
  186. openstackclient/tests/unit/network/v2/test_network_rbac.py +2 -2
  187. openstackclient/tests/unit/network/v2/test_network_trunk.py +2 -2
  188. openstackclient/tests/unit/network/v2/test_port.py +21 -22
  189. openstackclient/tests/unit/network/v2/test_router.py +130 -51
  190. openstackclient/tests/unit/network/v2/test_security_group_compute.py +11 -19
  191. openstackclient/tests/unit/network/v2/test_security_group_network.py +25 -27
  192. openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +15 -17
  193. openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +33 -39
  194. openstackclient/tests/unit/object/v1/test_object_all.py +4 -3
  195. openstackclient/tests/unit/test_shell.py +16 -13
  196. openstackclient/tests/unit/volume/v2/fakes.py +1 -2
  197. openstackclient/tests/unit/volume/v2/test_service.py +57 -91
  198. openstackclient/tests/unit/volume/v2/test_volume.py +109 -106
  199. openstackclient/tests/unit/volume/v2/test_volume_backup.py +141 -148
  200. openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +293 -283
  201. openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +1 -1
  202. openstackclient/tests/unit/volume/v3/fakes.py +2 -8
  203. openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +61 -71
  204. openstackclient/tests/unit/volume/v3/test_service.py +221 -141
  205. openstackclient/tests/unit/volume/v3/test_volume.py +131 -120
  206. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +4 -4
  207. openstackclient/tests/unit/volume/v3/test_volume_backup.py +198 -203
  208. openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +683 -49
  209. openstackclient/tests/unit/volume/v3/test_volume_transfer_request.py +1 -1
  210. openstackclient/volume/client.py +1 -3
  211. openstackclient/volume/v2/consistency_group.py +4 -8
  212. openstackclient/volume/v2/consistency_group_snapshot.py +1 -2
  213. openstackclient/volume/v2/qos_specs.py +1 -2
  214. openstackclient/volume/v2/service.py +41 -38
  215. openstackclient/volume/v2/volume.py +71 -53
  216. openstackclient/volume/v2/volume_backup.py +15 -10
  217. openstackclient/volume/v2/volume_snapshot.py +129 -93
  218. openstackclient/volume/v2/volume_transfer_request.py +0 -3
  219. openstackclient/volume/v2/volume_type.py +10 -21
  220. openstackclient/volume/v3/block_storage_cluster.py +3 -3
  221. openstackclient/volume/v3/block_storage_log_level.py +22 -28
  222. openstackclient/volume/v3/block_storage_manage.py +1 -3
  223. openstackclient/volume/v3/service.py +105 -14
  224. openstackclient/volume/v3/volume.py +218 -58
  225. openstackclient/volume/v3/volume_attachment.py +3 -2
  226. openstackclient/volume/v3/volume_backup.py +31 -27
  227. openstackclient/volume/v3/volume_group.py +2 -1
  228. openstackclient/volume/v3/volume_group_snapshot.py +2 -1
  229. openstackclient/volume/v3/volume_snapshot.py +489 -13
  230. openstackclient/volume/v3/volume_type.py +10 -21
  231. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/AUTHORS +11 -0
  232. python_openstackclient-8.1.0.dist-info/METADATA +264 -0
  233. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/RECORD +238 -259
  234. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/WHEEL +1 -1
  235. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/entry_points.txt +7 -47
  236. python_openstackclient-8.1.0.dist-info/pbr.json +1 -0
  237. openstackclient/tests/functional/volume/v1/__init__.py +0 -0
  238. openstackclient/tests/functional/volume/v1/common.py +0 -35
  239. openstackclient/tests/functional/volume/v1/test_qos.py +0 -100
  240. openstackclient/tests/functional/volume/v1/test_service.py +0 -76
  241. openstackclient/tests/functional/volume/v1/test_snapshot.py +0 -232
  242. openstackclient/tests/functional/volume/v1/test_transfer_request.py +0 -111
  243. openstackclient/tests/functional/volume/v1/test_volume.py +0 -228
  244. openstackclient/tests/functional/volume/v1/test_volume_type.py +0 -213
  245. openstackclient/tests/unit/volume/v1/__init__.py +0 -0
  246. openstackclient/tests/unit/volume/v1/fakes.py +0 -615
  247. openstackclient/tests/unit/volume/v1/test_qos_specs.py +0 -471
  248. openstackclient/tests/unit/volume/v1/test_service.py +0 -295
  249. openstackclient/tests/unit/volume/v1/test_transfer_request.py +0 -380
  250. openstackclient/tests/unit/volume/v1/test_type.py +0 -633
  251. openstackclient/tests/unit/volume/v1/test_volume.py +0 -1447
  252. openstackclient/tests/unit/volume/v1/test_volume_backup.py +0 -435
  253. openstackclient/volume/v1/__init__.py +0 -0
  254. openstackclient/volume/v1/qos_specs.py +0 -377
  255. openstackclient/volume/v1/service.py +0 -136
  256. openstackclient/volume/v1/volume.py +0 -734
  257. openstackclient/volume/v1/volume_backup.py +0 -302
  258. openstackclient/volume/v1/volume_snapshot.py +0 -433
  259. openstackclient/volume/v1/volume_transfer_request.py +0 -200
  260. openstackclient/volume/v1/volume_type.py +0 -520
  261. python_openstackclient-7.4.0.dist-info/METADATA +0 -172
  262. python_openstackclient-7.4.0.dist-info/pbr.json +0 -1
  263. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/LICENSE +0 -0
  264. {python_openstackclient-7.4.0.dist-info → python_openstackclient-8.1.0.dist-info}/top_level.txt +0 -0
@@ -14,17 +14,180 @@
14
14
 
15
15
  """Volume v3 snapshot action implementations"""
16
16
 
17
+ import functools
17
18
  import logging
19
+ import typing as ty
18
20
 
21
+ from cliff import columns as cliff_columns
22
+ from openstack.block_storage.v3 import snapshot as _snapshot
23
+ from osc_lib.cli import format_columns
24
+ from osc_lib.cli import parseractions
19
25
  from osc_lib.command import command
20
26
  from osc_lib import exceptions
21
27
  from osc_lib import utils
22
28
 
29
+ from openstackclient.common import pagination
23
30
  from openstackclient.i18n import _
31
+ from openstackclient.identity import common as identity_common
24
32
 
25
33
  LOG = logging.getLogger(__name__)
26
34
 
27
35
 
36
+ class VolumeIdColumn(cliff_columns.FormattableColumn):
37
+ """Formattable column for volume ID column.
38
+
39
+ Unlike the parent FormattableColumn class, the initializer of the
40
+ class takes volume_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(VolumeIdColumn, volume_cache)``.
45
+ """
46
+
47
+ def __init__(self, value, volume_cache=None):
48
+ super().__init__(value)
49
+ self._volume_cache = volume_cache or {}
50
+
51
+ def human_readable(self):
52
+ """Return a volume name if available
53
+
54
+ :rtype: either the volume ID or name
55
+ """
56
+ volume_id = self._value
57
+ volume = volume_id
58
+ if volume_id in self._volume_cache.keys():
59
+ volume = self._volume_cache[volume_id].name
60
+ return volume
61
+
62
+
63
+ def _format_snapshot(snapshot: _snapshot.Snapshot) -> dict[str, ty.Any]:
64
+ # Some columns returned by openstacksdk should not be shown because they're
65
+ # either irrelevant or duplicates
66
+ ignored_columns = {
67
+ # computed columns
68
+ 'location',
69
+ # create-only columns
70
+ 'consumes_quota',
71
+ 'force',
72
+ 'group_snapshot_id',
73
+ # ignored columns
74
+ 'os-extended-snapshot-attributes:progress',
75
+ 'os-extended-snapshot-attributes:project_id',
76
+ 'updated_at',
77
+ 'user_id',
78
+ # unnecessary columns
79
+ 'links',
80
+ }
81
+
82
+ info = snapshot.to_dict(original_names=True)
83
+ data = {}
84
+ for key, value in info.items():
85
+ if key in ignored_columns:
86
+ continue
87
+
88
+ data[key] = value
89
+
90
+ data.update(
91
+ {
92
+ 'properties': format_columns.DictColumn(data.pop('metadata')),
93
+ }
94
+ )
95
+
96
+ return data
97
+
98
+
99
+ class CreateVolumeSnapshot(command.ShowOne):
100
+ _description = _("Create new volume snapshot")
101
+
102
+ def get_parser(self, prog_name):
103
+ parser = super().get_parser(prog_name)
104
+ parser.add_argument(
105
+ "snapshot_name",
106
+ metavar="<snapshot-name>",
107
+ help=_("Name of the new snapshot"),
108
+ )
109
+ parser.add_argument(
110
+ "--volume",
111
+ metavar="<volume>",
112
+ help=_(
113
+ "Volume to snapshot (name or ID) (default is <snapshot-name>)"
114
+ ),
115
+ )
116
+ parser.add_argument(
117
+ "--description",
118
+ metavar="<description>",
119
+ help=_("Description of the snapshot"),
120
+ )
121
+ parser.add_argument(
122
+ "--force",
123
+ action="store_true",
124
+ default=False,
125
+ help=_(
126
+ "Create a snapshot attached to an instance. Default is False"
127
+ ),
128
+ )
129
+ parser.add_argument(
130
+ "--property",
131
+ metavar="<key=value>",
132
+ dest='properties',
133
+ action=parseractions.KeyValueAction,
134
+ help=_(
135
+ "Set a property to this snapshot "
136
+ "(repeat option to set multiple properties)"
137
+ ),
138
+ )
139
+ parser.add_argument(
140
+ "--remote-source",
141
+ metavar="<key=value>",
142
+ action=parseractions.KeyValueAction,
143
+ help=_(
144
+ "The attribute(s) of the existing remote volume snapshot "
145
+ "(admin required) (repeat option to specify multiple "
146
+ "attributes) e.g.: '--remote-source source-name=test_name "
147
+ "--remote-source source-id=test_id'"
148
+ ),
149
+ )
150
+ return parser
151
+
152
+ def take_action(self, parsed_args):
153
+ volume_client = self.app.client_manager.sdk_connection.volume
154
+
155
+ volume = parsed_args.volume
156
+ if not parsed_args.volume:
157
+ volume = parsed_args.snapshot_name
158
+ volume_id = volume_client.find_volume(volume, ignore_missing=False).id
159
+
160
+ if parsed_args.remote_source:
161
+ # Create a new snapshot from an existing remote snapshot source
162
+ if parsed_args.force:
163
+ msg = _(
164
+ "'--force' option will not work when you create "
165
+ "new volume snapshot from an existing remote "
166
+ "volume snapshot"
167
+ )
168
+ LOG.warning(msg)
169
+
170
+ snapshot = volume_client.manage_snapshot(
171
+ volume_id=volume_id,
172
+ ref=parsed_args.remote_source,
173
+ name=parsed_args.snapshot_name,
174
+ description=parsed_args.description,
175
+ metadata=parsed_args.properties,
176
+ )
177
+ else:
178
+ # Create a new snapshot from scratch
179
+ snapshot = volume_client.create_snapshot(
180
+ volume_id=volume_id,
181
+ force=parsed_args.force,
182
+ name=parsed_args.snapshot_name,
183
+ description=parsed_args.description,
184
+ metadata=parsed_args.properties,
185
+ )
186
+
187
+ data = _format_snapshot(snapshot)
188
+ return zip(*sorted(data.items()))
189
+
190
+
28
191
  class DeleteVolumeSnapshot(command.Command):
29
192
  _description = _("Delete volume snapshot(s)")
30
193
 
@@ -55,9 +218,7 @@ class DeleteVolumeSnapshot(command.Command):
55
218
  return parser
56
219
 
57
220
  def take_action(self, parsed_args):
58
- volume_client = self.app.client_manager.volume
59
- volume_client_sdk = self.app.client_manager.sdk_connection.volume
60
-
221
+ volume_client = self.app.client_manager.sdk_connection.volume
61
222
  result = 0
62
223
 
63
224
  if parsed_args.remote:
@@ -68,16 +229,16 @@ class DeleteVolumeSnapshot(command.Command):
68
229
  )
69
230
  raise exceptions.CommandError(msg)
70
231
 
71
- for i in parsed_args.snapshots:
232
+ for snapshot in parsed_args.snapshots:
72
233
  try:
73
- snapshot_id = utils.find_resource(
74
- volume_client.volume_snapshots, i
234
+ snapshot_id = volume_client.find_snapshot(
235
+ snapshot, ignore_missing=False
75
236
  ).id
76
237
  if parsed_args.remote:
77
- volume_client_sdk.unmanage_snapshot(snapshot_id)
238
+ volume_client.unmanage_snapshot(snapshot_id)
78
239
  else:
79
- volume_client.volume_snapshots.delete(
80
- snapshot_id, parsed_args.force
240
+ volume_client.delete_snapshot(
241
+ snapshot_id, force=parsed_args.force
81
242
  )
82
243
  except Exception as e:
83
244
  result += 1
@@ -86,12 +247,327 @@ class DeleteVolumeSnapshot(command.Command):
86
247
  "Failed to delete snapshot with "
87
248
  "name or ID '%(snapshot)s': %(e)s"
88
249
  )
89
- % {'snapshot': i, 'e': e}
250
+ % {'snapshot': snapshot, 'e': e}
90
251
  )
91
252
 
92
253
  if result > 0:
93
254
  total = len(parsed_args.snapshots)
94
- msg = _(
95
- "%(result)s of %(total)s snapshots failed " "to delete."
96
- ) % {'result': result, 'total': total}
255
+ msg = _("%(result)s of %(total)s snapshots failed to delete.") % {
256
+ 'result': result,
257
+ 'total': total,
258
+ }
97
259
  raise exceptions.CommandError(msg)
260
+
261
+
262
+ class ListVolumeSnapshot(command.Lister):
263
+ _description = _("List volume snapshots")
264
+
265
+ def get_parser(self, prog_name):
266
+ parser = super().get_parser(prog_name)
267
+ parser.add_argument(
268
+ '--all-projects',
269
+ action='store_true',
270
+ default=False,
271
+ help=_('Include all projects (admin only)'),
272
+ )
273
+ parser.add_argument(
274
+ '--project',
275
+ metavar='<project>',
276
+ help=_('Filter results by project (name or ID) (admin only)'),
277
+ )
278
+ identity_common.add_project_domain_option_to_parser(parser)
279
+ parser.add_argument(
280
+ '--long',
281
+ action='store_true',
282
+ default=False,
283
+ help=_('List additional fields in output'),
284
+ )
285
+ parser.add_argument(
286
+ '--name',
287
+ metavar='<name>',
288
+ default=None,
289
+ help=_('Filters results by a name.'),
290
+ )
291
+ parser.add_argument(
292
+ '--status',
293
+ metavar='<status>',
294
+ choices=[
295
+ 'available',
296
+ 'error',
297
+ 'creating',
298
+ 'deleting',
299
+ 'error_deleting',
300
+ ],
301
+ help=_(
302
+ "Filters results by a status. "
303
+ "('available', 'error', 'creating', 'deleting'"
304
+ " or 'error_deleting')"
305
+ ),
306
+ )
307
+ parser.add_argument(
308
+ '--volume',
309
+ metavar='<volume>',
310
+ default=None,
311
+ help=_('Filters results by a volume (name or ID).'),
312
+ )
313
+ pagination.add_marker_pagination_option_to_parser(parser)
314
+ return parser
315
+
316
+ def take_action(self, parsed_args):
317
+ volume_client = self.app.client_manager.sdk_connection.volume
318
+ identity_client = self.app.client_manager.identity
319
+
320
+ columns: tuple[str, ...] = (
321
+ 'id',
322
+ 'name',
323
+ 'description',
324
+ 'status',
325
+ 'size',
326
+ )
327
+ column_headers: tuple[str, ...] = (
328
+ 'ID',
329
+ 'Name',
330
+ 'Description',
331
+ 'Status',
332
+ 'Size',
333
+ )
334
+ if parsed_args.long:
335
+ columns += (
336
+ 'created_at',
337
+ 'volume_id',
338
+ 'metadata',
339
+ )
340
+ column_headers += (
341
+ 'Created At',
342
+ 'Volume',
343
+ 'Properties',
344
+ )
345
+
346
+ # Cache the volume list
347
+ volume_cache = {}
348
+ try:
349
+ for s in volume_client.volumes():
350
+ volume_cache[s.id] = s
351
+ except Exception: # noqa: S110
352
+ # Just forget it if there's any trouble
353
+ pass
354
+ _VolumeIdColumn = functools.partial(
355
+ VolumeIdColumn, volume_cache=volume_cache
356
+ )
357
+
358
+ volume_id = None
359
+ if parsed_args.volume:
360
+ volume_id = volume_client.find_volume(
361
+ parsed_args.volume, ignore_missing=False
362
+ ).id
363
+
364
+ project_id = None
365
+ if parsed_args.project:
366
+ project_id = identity_common.find_project(
367
+ identity_client,
368
+ parsed_args.project,
369
+ parsed_args.project_domain,
370
+ ).id
371
+
372
+ # set value of 'all_tenants' when using project option
373
+ all_projects = (
374
+ True if parsed_args.project else parsed_args.all_projects
375
+ )
376
+
377
+ data = volume_client.snapshots(
378
+ marker=parsed_args.marker,
379
+ limit=parsed_args.limit,
380
+ all_projects=all_projects,
381
+ project_id=project_id,
382
+ name=parsed_args.name,
383
+ status=parsed_args.status,
384
+ volume_id=volume_id,
385
+ )
386
+ return (
387
+ column_headers,
388
+ (
389
+ utils.get_item_properties(
390
+ s,
391
+ columns,
392
+ formatters={
393
+ 'metadata': format_columns.DictColumn,
394
+ 'volume_id': _VolumeIdColumn,
395
+ },
396
+ )
397
+ for s in data
398
+ ),
399
+ )
400
+
401
+
402
+ class SetVolumeSnapshot(command.Command):
403
+ _description = _("Set volume snapshot properties")
404
+
405
+ def get_parser(self, prog_name):
406
+ parser = super().get_parser(prog_name)
407
+ parser.add_argument(
408
+ 'snapshot',
409
+ metavar='<snapshot>',
410
+ help=_('Snapshot to modify (name or ID)'),
411
+ )
412
+ parser.add_argument(
413
+ '--name', metavar='<name>', help=_('New snapshot name')
414
+ )
415
+ parser.add_argument(
416
+ '--description',
417
+ metavar='<description>',
418
+ help=_('New snapshot description'),
419
+ )
420
+ parser.add_argument(
421
+ "--no-property",
422
+ dest="no_property",
423
+ action="store_true",
424
+ help=_(
425
+ "Remove all properties from <snapshot> "
426
+ "(specify both --no-property and --property to "
427
+ "remove the current properties before setting "
428
+ "new properties.)"
429
+ ),
430
+ )
431
+ parser.add_argument(
432
+ '--property',
433
+ metavar='<key=value>',
434
+ action=parseractions.KeyValueAction,
435
+ dest='properties',
436
+ help=_(
437
+ 'Property to add/change for this snapshot '
438
+ '(repeat option to set multiple properties)'
439
+ ),
440
+ )
441
+ parser.add_argument(
442
+ '--state',
443
+ metavar='<state>',
444
+ choices=[
445
+ 'available',
446
+ 'error',
447
+ 'creating',
448
+ 'deleting',
449
+ 'error_deleting',
450
+ ],
451
+ help=_(
452
+ 'New snapshot state. ("available", "error", "creating", '
453
+ '"deleting", or "error_deleting") (admin only) '
454
+ '(This option simply changes the state of the snapshot '
455
+ 'in the database with no regard to actual status, '
456
+ 'exercise caution when using)'
457
+ ),
458
+ )
459
+ return parser
460
+
461
+ def take_action(self, parsed_args):
462
+ volume_client = self.app.client_manager.sdk_connection.volume
463
+
464
+ snapshot = volume_client.find_snapshot(
465
+ parsed_args.snapshot, ignore_missing=False
466
+ )
467
+
468
+ result = 0
469
+ if parsed_args.no_property:
470
+ try:
471
+ volume_client.delete_snapshot_metadata(
472
+ snapshot.id, keys=list(snapshot.metadata)
473
+ )
474
+ except Exception as e:
475
+ LOG.error(_("Failed to clean snapshot properties: %s"), e)
476
+ result += 1
477
+
478
+ if parsed_args.properties:
479
+ try:
480
+ volume_client.set_snapshot_metadata(
481
+ snapshot.id, **parsed_args.properties
482
+ )
483
+ except Exception as e:
484
+ LOG.error(_("Failed to set snapshot property: %s"), e)
485
+ result += 1
486
+
487
+ if parsed_args.state:
488
+ try:
489
+ volume_client.reset_snapshot_status(
490
+ snapshot.id, parsed_args.state
491
+ )
492
+ except Exception as e:
493
+ LOG.error(_("Failed to set snapshot state: %s"), e)
494
+ result += 1
495
+
496
+ kwargs = {}
497
+ if parsed_args.name:
498
+ kwargs['name'] = parsed_args.name
499
+ if parsed_args.description:
500
+ kwargs['description'] = parsed_args.description
501
+ if kwargs:
502
+ try:
503
+ volume_client.update_snapshot(snapshot.id, **kwargs)
504
+ except Exception as e:
505
+ LOG.error(
506
+ _("Failed to update snapshot name or description: %s"),
507
+ e,
508
+ )
509
+ result += 1
510
+
511
+ if result > 0:
512
+ raise exceptions.CommandError(
513
+ _("One or more of the set operations failed")
514
+ )
515
+
516
+
517
+ class ShowVolumeSnapshot(command.ShowOne):
518
+ _description = _("Display volume snapshot details")
519
+
520
+ def get_parser(self, prog_name):
521
+ parser = super().get_parser(prog_name)
522
+ parser.add_argument(
523
+ "snapshot",
524
+ metavar="<snapshot>",
525
+ help=_("Snapshot to display (name or ID)"),
526
+ )
527
+ return parser
528
+
529
+ def take_action(self, parsed_args):
530
+ volume_client = self.app.client_manager.sdk_connection.volume
531
+
532
+ snapshot = volume_client.find_snapshot(
533
+ parsed_args.snapshot, ignore_missing=False
534
+ )
535
+
536
+ data = _format_snapshot(snapshot)
537
+ return zip(*sorted(data.items()))
538
+
539
+
540
+ class UnsetVolumeSnapshot(command.Command):
541
+ _description = _("Unset volume snapshot properties")
542
+
543
+ def get_parser(self, prog_name):
544
+ parser = super().get_parser(prog_name)
545
+ parser.add_argument(
546
+ 'snapshot',
547
+ metavar='<snapshot>',
548
+ help=_('Snapshot to modify (name or ID)'),
549
+ )
550
+ parser.add_argument(
551
+ '--property',
552
+ metavar='<key>',
553
+ dest='properties',
554
+ action='append',
555
+ default=[],
556
+ help=_(
557
+ 'Property to remove from snapshot '
558
+ '(repeat option to remove multiple properties)'
559
+ ),
560
+ )
561
+ return parser
562
+
563
+ def take_action(self, parsed_args):
564
+ volume_client = self.app.client_manager.sdk_connection.volume
565
+
566
+ snapshot = volume_client.find_snapshot(
567
+ parsed_args.snapshot, ignore_missing=False
568
+ )
569
+
570
+ if parsed_args.properties:
571
+ volume_client.delete_snapshot_metadata(
572
+ snapshot.id, keys=parsed_args.properties
573
+ )
@@ -273,8 +273,7 @@ class CreateVolumeType(command.ShowOne):
273
273
  )
274
274
  except Exception as e:
275
275
  msg = _(
276
- "Failed to add project %(project)s access to "
277
- "type: %(e)s"
276
+ "Failed to add project %(project)s access to type: %(e)s"
278
277
  )
279
278
  LOG.error(msg % {'project': parsed_args.project, 'e': e})
280
279
 
@@ -364,7 +363,7 @@ class DeleteVolumeType(command.Command):
364
363
  if result > 0:
365
364
  total = len(parsed_args.volume_types)
366
365
  msg = _(
367
- "%(result)s of %(total)s volume types failed " "to delete."
366
+ "%(result)s of %(total)s volume types failed to delete."
368
367
  ) % {'result': result, 'total': total}
369
368
  raise exceptions.CommandError(msg)
370
369
 
@@ -635,8 +634,7 @@ class SetVolumeType(command.Command):
635
634
  '--project',
636
635
  metavar='<project>',
637
636
  help=_(
638
- 'Set volume type access to project (name or ID) '
639
- '(admin only)'
637
+ 'Set volume type access to project (name or ID) (admin only)'
640
638
  ),
641
639
  )
642
640
  public_group = parser.add_mutually_exclusive_group()
@@ -728,17 +726,12 @@ class SetVolumeType(command.Command):
728
726
  volume_client.volume_types.update(volume_type.id, **kwargs)
729
727
  except Exception as e:
730
728
  LOG.error(
731
- _(
732
- "Failed to update volume type name or"
733
- " description: %s"
734
- ),
729
+ _("Failed to update volume type name or description: %s"),
735
730
  e,
736
731
  )
737
732
  result += 1
738
733
 
739
- properties = {}
740
-
741
- properties = {}
734
+ properties: dict[str, str] = {}
742
735
  if parsed_args.properties:
743
736
  properties.update(parsed_args.properties)
744
737
  if parsed_args.multiattach:
@@ -772,7 +765,7 @@ class SetVolumeType(command.Command):
772
765
  )
773
766
  except Exception as e:
774
767
  LOG.error(
775
- _("Failed to set volume type access to " "project: %s"), e
768
+ _("Failed to set volume type access to project: %s"), e
776
769
  )
777
770
  result += 1
778
771
 
@@ -796,7 +789,7 @@ class SetVolumeType(command.Command):
796
789
 
797
790
  if result > 0:
798
791
  raise exceptions.CommandError(
799
- _("Command Failed: One or more of" " the operations failed")
792
+ _("Command Failed: One or more of the operations failed")
800
793
  )
801
794
 
802
795
 
@@ -904,8 +897,7 @@ class UnsetVolumeType(command.Command):
904
897
  "--encryption-type",
905
898
  action="store_true",
906
899
  help=_(
907
- "Remove the encryption type for this volume type "
908
- "(admin only)"
900
+ "Remove the encryption type for this volume type (admin only)"
909
901
  ),
910
902
  )
911
903
  return parser
@@ -941,10 +933,7 @@ class UnsetVolumeType(command.Command):
941
933
  )
942
934
  except Exception as e:
943
935
  LOG.error(
944
- _(
945
- "Failed to remove volume type access from "
946
- "project: %s"
947
- ),
936
+ _("Failed to remove volume type access from project: %s"),
948
937
  e,
949
938
  )
950
939
  result += 1
@@ -963,5 +952,5 @@ class UnsetVolumeType(command.Command):
963
952
 
964
953
  if result > 0:
965
954
  raise exceptions.CommandError(
966
- _("Command Failed: One or more of" " the operations failed")
955
+ _("Command Failed: One or more of the operations failed")
967
956
  )