python-manilaclient 5.5.0__py3-none-any.whl → 5.7.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. manilaclient/__init__.py +2 -1
  2. manilaclient/api_versions.py +137 -80
  3. manilaclient/base.py +69 -52
  4. manilaclient/client.py +7 -5
  5. manilaclient/common/apiclient/exceptions.py +65 -16
  6. manilaclient/common/apiclient/utils.py +14 -9
  7. manilaclient/common/cliutils.py +25 -11
  8. manilaclient/common/constants.py +32 -15
  9. manilaclient/common/httpclient.py +46 -30
  10. manilaclient/config.py +250 -165
  11. manilaclient/exceptions.py +4 -0
  12. manilaclient/extension.py +1 -1
  13. manilaclient/osc/plugin.py +56 -32
  14. manilaclient/osc/utils.py +24 -19
  15. manilaclient/osc/v2/availability_zones.py +8 -4
  16. manilaclient/osc/v2/messages.py +71 -41
  17. manilaclient/osc/v2/quotas.py +191 -109
  18. manilaclient/osc/v2/resource_locks.py +118 -82
  19. manilaclient/osc/v2/security_services.py +192 -124
  20. manilaclient/osc/v2/services.py +50 -33
  21. manilaclient/osc/v2/share.py +590 -404
  22. manilaclient/osc/v2/share_access_rules.py +181 -124
  23. manilaclient/osc/v2/share_backups.py +185 -102
  24. manilaclient/osc/v2/share_group_snapshots.py +114 -86
  25. manilaclient/osc/v2/share_group_type_access.py +65 -41
  26. manilaclient/osc/v2/share_group_types.py +113 -77
  27. manilaclient/osc/v2/share_groups.py +155 -119
  28. manilaclient/osc/v2/share_instance_export_locations.py +16 -17
  29. manilaclient/osc/v2/share_instances.py +62 -42
  30. manilaclient/osc/v2/share_limits.py +7 -5
  31. manilaclient/osc/v2/share_network_subnets.py +166 -93
  32. manilaclient/osc/v2/share_networks.py +304 -186
  33. manilaclient/osc/v2/share_pools.py +42 -22
  34. manilaclient/osc/v2/share_replica_export_locations.py +17 -19
  35. manilaclient/osc/v2/share_replicas.py +157 -110
  36. manilaclient/osc/v2/share_servers.py +244 -166
  37. manilaclient/osc/v2/share_snapshot_instance_export_locations.py +22 -15
  38. manilaclient/osc/v2/share_snapshot_instances.py +60 -33
  39. manilaclient/osc/v2/share_snapshots.py +303 -241
  40. manilaclient/osc/v2/share_transfers.py +107 -66
  41. manilaclient/osc/v2/share_type_access.py +27 -18
  42. manilaclient/osc/v2/share_types.py +163 -105
  43. manilaclient/shell.py +408 -333
  44. manilaclient/tests/functional/base.py +210 -99
  45. manilaclient/tests/functional/client.py +848 -584
  46. manilaclient/tests/functional/exceptions.py +8 -5
  47. manilaclient/tests/functional/osc/base.py +211 -122
  48. manilaclient/tests/functional/osc/test_availability_zones.py +1 -7
  49. manilaclient/tests/functional/osc/test_messages.py +66 -36
  50. manilaclient/tests/functional/osc/test_resource_locks.py +95 -71
  51. manilaclient/tests/functional/osc/test_share_access_rules.py +87 -69
  52. manilaclient/tests/functional/osc/test_share_backups.py +71 -49
  53. manilaclient/tests/functional/osc/test_share_group_type_access.py +30 -16
  54. manilaclient/tests/functional/osc/test_share_limits.py +17 -19
  55. manilaclient/tests/functional/osc/test_share_network_subnets.py +3 -4
  56. manilaclient/tests/functional/osc/test_share_networks.py +46 -33
  57. manilaclient/tests/functional/osc/test_share_pools.py +9 -17
  58. manilaclient/tests/functional/osc/test_share_replica_export_locations.py +26 -19
  59. manilaclient/tests/functional/osc/test_share_replicas.py +23 -18
  60. manilaclient/tests/functional/osc/test_share_services.py +25 -23
  61. manilaclient/tests/functional/osc/test_share_snapshot_instances.py +47 -34
  62. manilaclient/tests/functional/osc/test_share_snapshots.py +80 -78
  63. manilaclient/tests/functional/osc/test_share_transfers.py +45 -25
  64. manilaclient/tests/functional/osc/test_share_types.py +48 -51
  65. manilaclient/tests/functional/osc/test_shares.py +61 -45
  66. manilaclient/tests/functional/osc/test_shares_group_type.py +62 -51
  67. manilaclient/tests/functional/test_availability_zones.py +2 -2
  68. manilaclient/tests/functional/test_common.py +16 -6
  69. manilaclient/tests/functional/test_export_locations.py +34 -23
  70. manilaclient/tests/functional/test_limits.py +0 -1
  71. manilaclient/tests/functional/test_messages.py +17 -7
  72. manilaclient/tests/functional/test_quotas.py +141 -76
  73. manilaclient/tests/functional/test_scheduler_stats.py +8 -8
  74. manilaclient/tests/functional/test_security_services.py +1 -2
  75. manilaclient/tests/functional/test_services.py +0 -1
  76. manilaclient/tests/functional/test_share_access.py +138 -77
  77. manilaclient/tests/functional/test_share_network_subnets.py +27 -17
  78. manilaclient/tests/functional/test_share_networks.py +231 -123
  79. manilaclient/tests/functional/test_share_replica_export_locations.py +39 -19
  80. manilaclient/tests/functional/test_share_replicas.py +6 -4
  81. manilaclient/tests/functional/test_share_servers.py +102 -61
  82. manilaclient/tests/functional/test_share_transfers.py +13 -8
  83. manilaclient/tests/functional/test_share_types.py +243 -130
  84. manilaclient/tests/functional/test_shares.py +90 -57
  85. manilaclient/tests/functional/test_shares_listing.py +105 -61
  86. manilaclient/tests/functional/test_shares_metadata.py +17 -17
  87. manilaclient/tests/functional/test_snapshot_access.py +103 -66
  88. manilaclient/tests/functional/test_snapshot_instances.py +50 -29
  89. manilaclient/tests/functional/test_snapshot_instances_export_locations.py +39 -25
  90. manilaclient/tests/functional/test_snapshots_export_locations.py +23 -17
  91. manilaclient/tests/functional/utils.py +50 -25
  92. manilaclient/tests/unit/common/test_httpclient.py +75 -51
  93. manilaclient/tests/unit/fakes.py +18 -14
  94. manilaclient/tests/unit/osc/osc_fakes.py +20 -24
  95. manilaclient/tests/unit/osc/osc_utils.py +10 -7
  96. manilaclient/tests/unit/osc/v2/fakes.py +185 -190
  97. manilaclient/tests/unit/osc/v2/test_availability_zones.py +9 -9
  98. manilaclient/tests/unit/osc/v2/test_messages.py +52 -64
  99. manilaclient/tests/unit/osc/v2/test_quotas.py +130 -147
  100. manilaclient/tests/unit/osc/v2/test_resource_locks.py +80 -82
  101. manilaclient/tests/unit/osc/v2/test_security_services.py +205 -132
  102. manilaclient/tests/unit/osc/v2/test_services.py +77 -69
  103. manilaclient/tests/unit/osc/v2/test_share.py +586 -582
  104. manilaclient/tests/unit/osc/v2/test_share_access_rules.py +104 -155
  105. manilaclient/tests/unit/osc/v2/test_share_backups.py +140 -153
  106. manilaclient/tests/unit/osc/v2/test_share_group_snapshots.py +167 -214
  107. manilaclient/tests/unit/osc/v2/test_share_group_type.py +144 -131
  108. manilaclient/tests/unit/osc/v2/test_share_group_type_access.py +33 -46
  109. manilaclient/tests/unit/osc/v2/test_share_groups.py +172 -253
  110. manilaclient/tests/unit/osc/v2/test_share_instance_export_locations.py +37 -45
  111. manilaclient/tests/unit/osc/v2/test_share_instances.py +88 -117
  112. manilaclient/tests/unit/osc/v2/test_share_limits.py +14 -22
  113. manilaclient/tests/unit/osc/v2/test_share_network_subnets.py +265 -100
  114. manilaclient/tests/unit/osc/v2/test_share_networks.py +374 -218
  115. manilaclient/tests/unit/osc/v2/test_share_pools.py +37 -37
  116. manilaclient/tests/unit/osc/v2/test_share_replica_export_locations.py +30 -43
  117. manilaclient/tests/unit/osc/v2/test_share_replicas.py +171 -254
  118. manilaclient/tests/unit/osc/v2/test_share_servers.py +258 -253
  119. manilaclient/tests/unit/osc/v2/test_share_snapshot_instance_export_locations.py +66 -56
  120. manilaclient/tests/unit/osc/v2/test_share_snapshot_instances.py +90 -77
  121. manilaclient/tests/unit/osc/v2/test_share_snapshots.py +330 -432
  122. manilaclient/tests/unit/osc/v2/test_share_transfers.py +77 -93
  123. manilaclient/tests/unit/osc/v2/test_share_type.py +146 -176
  124. manilaclient/tests/unit/osc/v2/test_share_type_access.py +35 -51
  125. manilaclient/tests/unit/test_api_versions.py +91 -70
  126. manilaclient/tests/unit/test_base.py +5 -5
  127. manilaclient/tests/unit/test_client.py +25 -19
  128. manilaclient/tests/unit/test_functional_utils.py +105 -72
  129. manilaclient/tests/unit/test_shell.py +187 -100
  130. manilaclient/tests/unit/utils.py +14 -8
  131. manilaclient/tests/unit/v1/test_limits.py +5 -4
  132. manilaclient/tests/unit/v1/test_quota_classes.py +5 -4
  133. manilaclient/tests/unit/v1/test_quotas.py +5 -4
  134. manilaclient/tests/unit/v1/test_scheduler_stats.py +5 -4
  135. manilaclient/tests/unit/v1/test_security_services.py +5 -4
  136. manilaclient/tests/unit/v1/test_services.py +5 -4
  137. manilaclient/tests/unit/v1/test_share_networks.py +5 -4
  138. manilaclient/tests/unit/v1/test_share_servers.py +5 -4
  139. manilaclient/tests/unit/v1/test_share_snapshots.py +5 -4
  140. manilaclient/tests/unit/v1/test_share_type_access.py +5 -4
  141. manilaclient/tests/unit/v1/test_share_types.py +5 -4
  142. manilaclient/tests/unit/v1/test_shares.py +5 -4
  143. manilaclient/tests/unit/v2/fake_clients.py +34 -26
  144. manilaclient/tests/unit/v2/fakes.py +358 -228
  145. manilaclient/tests/unit/v2/test_availability_zones.py +7 -5
  146. manilaclient/tests/unit/v2/test_client.py +137 -54
  147. manilaclient/tests/unit/v2/test_limits.py +62 -38
  148. manilaclient/tests/unit/v2/test_messages.py +43 -27
  149. manilaclient/tests/unit/v2/test_quota_classes.py +22 -13
  150. manilaclient/tests/unit/v2/test_quotas.py +113 -75
  151. manilaclient/tests/unit/v2/test_scheduler_stats.py +13 -12
  152. manilaclient/tests/unit/v2/test_security_services.py +70 -48
  153. manilaclient/tests/unit/v2/test_services.py +12 -12
  154. manilaclient/tests/unit/v2/test_share_backups.py +31 -14
  155. manilaclient/tests/unit/v2/test_share_export_locations.py +5 -10
  156. manilaclient/tests/unit/v2/test_share_group_snapshots.py +94 -52
  157. manilaclient/tests/unit/v2/test_share_group_type_access.py +32 -19
  158. manilaclient/tests/unit/v2/test_share_group_types.py +68 -37
  159. manilaclient/tests/unit/v2/test_share_groups.py +73 -41
  160. manilaclient/tests/unit/v2/test_share_instance_export_locations.py +14 -9
  161. manilaclient/tests/unit/v2/test_share_instances.py +27 -20
  162. manilaclient/tests/unit/v2/test_share_network_subnets.py +17 -15
  163. manilaclient/tests/unit/v2/test_share_networks.py +82 -78
  164. manilaclient/tests/unit/v2/test_share_replica_export_locations.py +7 -5
  165. manilaclient/tests/unit/v2/test_share_replicas.py +32 -19
  166. manilaclient/tests/unit/v2/test_share_servers.py +115 -70
  167. manilaclient/tests/unit/v2/test_share_snapshot_export_locations.py +6 -8
  168. manilaclient/tests/unit/v2/test_share_snapshot_instance_export_locations.py +16 -9
  169. manilaclient/tests/unit/v2/test_share_snapshot_instances.py +15 -9
  170. manilaclient/tests/unit/v2/test_share_snapshots.py +70 -49
  171. manilaclient/tests/unit/v2/test_share_transfers.py +9 -9
  172. manilaclient/tests/unit/v2/test_shares.py +461 -227
  173. manilaclient/tests/unit/v2/test_shell.py +1999 -1315
  174. manilaclient/tests/unit/v2/test_type_access.py +19 -14
  175. manilaclient/tests/unit/v2/test_types.py +203 -117
  176. manilaclient/utils.py +3 -2
  177. manilaclient/v1/__init__.py +1 -1
  178. manilaclient/v1/client.py +75 -48
  179. manilaclient/v1/contrib/list_extensions.py +5 -3
  180. manilaclient/v1/limits.py +7 -5
  181. manilaclient/v1/quota_classes.py +7 -5
  182. manilaclient/v1/quotas.py +7 -5
  183. manilaclient/v1/scheduler_stats.py +7 -5
  184. manilaclient/v1/security_services.py +10 -7
  185. manilaclient/v1/services.py +7 -5
  186. manilaclient/v1/share_networks.py +7 -5
  187. manilaclient/v1/share_servers.py +7 -5
  188. manilaclient/v1/share_snapshots.py +7 -5
  189. manilaclient/v1/share_type_access.py +10 -7
  190. manilaclient/v1/share_types.py +7 -5
  191. manilaclient/v1/shares.py +7 -5
  192. manilaclient/v2/__init__.py +1 -1
  193. manilaclient/v2/availability_zones.py +2 -2
  194. manilaclient/v2/client.py +102 -60
  195. manilaclient/v2/limits.py +26 -19
  196. manilaclient/v2/messages.py +12 -5
  197. manilaclient/v2/quota_classes.py +121 -56
  198. manilaclient/v2/quotas.py +250 -87
  199. manilaclient/v2/resource_locks.py +25 -14
  200. manilaclient/v2/scheduler_stats.py +4 -10
  201. manilaclient/v2/security_services.py +127 -46
  202. manilaclient/v2/services.py +15 -11
  203. manilaclient/v2/share_access_rules.py +3 -7
  204. manilaclient/v2/share_backups.py +26 -15
  205. manilaclient/v2/share_export_locations.py +16 -14
  206. manilaclient/v2/share_group_snapshots.py +50 -26
  207. manilaclient/v2/share_group_type_access.py +11 -7
  208. manilaclient/v2/share_group_types.py +23 -14
  209. manilaclient/v2/share_groups.py +84 -34
  210. manilaclient/v2/share_instance_export_locations.py +11 -9
  211. manilaclient/v2/share_instances.py +6 -4
  212. manilaclient/v2/share_network_subnets.py +57 -33
  213. manilaclient/v2/share_networks.py +82 -41
  214. manilaclient/v2/share_replica_export_locations.py +18 -13
  215. manilaclient/v2/share_replicas.py +34 -17
  216. manilaclient/v2/share_servers.py +83 -38
  217. manilaclient/v2/share_snapshot_export_locations.py +11 -7
  218. manilaclient/v2/share_snapshot_instance_export_locations.py +11 -7
  219. manilaclient/v2/share_snapshot_instances.py +7 -6
  220. manilaclient/v2/share_snapshots.py +59 -33
  221. manilaclient/v2/share_transfers.py +26 -16
  222. manilaclient/v2/share_type_access.py +5 -6
  223. manilaclient/v2/share_types.py +105 -55
  224. manilaclient/v2/shares.py +362 -137
  225. manilaclient/v2/shell.py +2331 -1506
  226. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/AUTHORS +6 -0
  227. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/METADATA +11 -13
  228. python_manilaclient-5.7.0.dist-info/RECORD +251 -0
  229. python_manilaclient-5.7.0.dist-info/pbr.json +1 -0
  230. python_manilaclient-5.5.0.dist-info/RECORD +0 -251
  231. python_manilaclient-5.5.0.dist-info/pbr.json +0 -1
  232. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/LICENSE +0 -0
  233. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/WHEEL +0 -0
  234. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/entry_points.txt +0 -0
  235. {python_manilaclient-5.5.0.dist-info → python_manilaclient-5.7.0.dist-info}/top_level.txt +0 -0
manilaclient/__init__.py CHANGED
@@ -32,4 +32,5 @@ except AttributeError:
32
32
  API_MAX_VERSION = api_versions.APIVersion(api_versions.MAX_VERSION)
33
33
  API_MIN_VERSION = api_versions.APIVersion(api_versions.MIN_VERSION)
34
34
  API_DEPRECATED_VERSION = api_versions.APIVersion(
35
- api_versions.DEPRECATED_VERSION)
35
+ api_versions.DEPRECATED_VERSION
36
+ )
@@ -27,13 +27,13 @@ from manilaclient import utils
27
27
 
28
28
  LOG = logging.getLogger(__name__)
29
29
 
30
- MAX_VERSION = '2.89'
30
+ MAX_VERSION = '2.91'
31
31
  MIN_VERSION = '2.0'
32
32
  DEPRECATED_VERSION = '1.0'
33
33
  _VERSIONED_METHOD_MAP = {}
34
34
 
35
35
 
36
- class APIVersion(object):
36
+ class APIVersion:
37
37
  """Top level object to support Manila API Versioning.
38
38
 
39
39
  This class represents an API Version with convenience
@@ -54,44 +54,57 @@ class APIVersion(object):
54
54
  self.ver_major = int(match.group(1))
55
55
  self.ver_minor = int(match.group(2))
56
56
  else:
57
- msg = _("Invalid format of client version '%s'. "
57
+ msg = (
58
+ _(
59
+ "Invalid format of client version '%s'. "
58
60
  "Expected format 'X.Y', where X is a major part and Y "
59
- "is a minor part of version.") % version_str
61
+ "is a minor part of version."
62
+ )
63
+ % version_str
64
+ )
60
65
  raise exceptions.UnsupportedVersion(msg)
61
66
 
62
67
  def __str__(self):
63
68
  """Debug/Logging representation of object."""
64
- return ("API Version Major: %s, Minor: %s"
65
- % (self.ver_major, self.ver_minor))
69
+ return f"API Version Major: {self.ver_major}, Minor: {self.ver_minor}"
66
70
 
67
71
  def __repr__(self):
68
72
  if self.is_null():
69
73
  return "<APIVersion: null>"
70
74
  else:
71
- return "<APIVersion: %s>" % self.get_string()
75
+ return f"<APIVersion: {self.get_string()}>"
72
76
 
73
77
  def __lt__(self, other):
74
78
  if not isinstance(other, APIVersion):
75
- raise TypeError(self.TYPE_ERROR_MSG % {"other": other,
76
- "cls": self.__class__})
79
+ raise TypeError(
80
+ self.TYPE_ERROR_MSG % {"other": other, "cls": self.__class__}
81
+ )
77
82
 
78
- return ((self.ver_major, self.ver_minor) <
79
- (other.ver_major, other.ver_minor))
83
+ return (self.ver_major, self.ver_minor) < (
84
+ other.ver_major,
85
+ other.ver_minor,
86
+ )
80
87
 
81
88
  def __eq__(self, other):
82
89
  if not isinstance(other, APIVersion):
83
- raise TypeError(self.TYPE_ERROR_MSG % {"other": other,
84
- "cls": self.__class__})
90
+ raise TypeError(
91
+ self.TYPE_ERROR_MSG % {"other": other, "cls": self.__class__}
92
+ )
85
93
 
86
- return ((self.ver_major, self.ver_minor) ==
87
- (other.ver_major, other.ver_minor))
94
+ return (self.ver_major, self.ver_minor) == (
95
+ other.ver_major,
96
+ other.ver_minor,
97
+ )
88
98
 
89
99
  def __gt__(self, other):
90
100
  if not isinstance(other, APIVersion):
91
- raise TypeError(self.TYPE_ERROR_MSG % {"other": other,
92
- "cls": self.__class__})
93
- return ((self.ver_major, self.ver_minor) >
94
- (other.ver_major, other.ver_minor))
101
+ raise TypeError(
102
+ self.TYPE_ERROR_MSG % {"other": other, "cls": self.__class__}
103
+ )
104
+ return (self.ver_major, self.ver_minor) > (
105
+ other.ver_major,
106
+ other.ver_minor,
107
+ )
95
108
 
96
109
  def __le__(self, other):
97
110
  return self < other or self == other
@@ -139,15 +152,15 @@ class APIVersion(object):
139
152
  """String representation of an APIVersion object."""
140
153
  if self.is_null():
141
154
  raise ValueError(
142
- _("Null APIVersion cannot be converted to string."))
143
- return "%s.%s" % (self.ver_major, self.ver_minor)
155
+ _("Null APIVersion cannot be converted to string.")
156
+ )
157
+ return f"{self.ver_major}.{self.ver_minor}"
144
158
 
145
159
  def get_major_version(self):
146
- return "%s" % self.ver_major
160
+ return f"{self.ver_major}"
147
161
 
148
162
 
149
- class VersionedMethod(object):
150
-
163
+ class VersionedMethod:
151
164
  def __init__(self, name, start_version, end_version, func):
152
165
  """Versioning information for a single method
153
166
 
@@ -164,11 +177,13 @@ class VersionedMethod(object):
164
177
  self.func = func
165
178
 
166
179
  def __str__(self):
167
- return ("Version Method %s: min: %s, max: %s"
168
- % (self.name, self.start_version, self.end_version))
180
+ return (
181
+ f"Version Method {self.name}: min: {self.start_version}, "
182
+ f"max: {self.end_version}"
183
+ )
169
184
 
170
185
  def __repr__(self):
171
- return "<VersionedMethod %s>" % self.name
186
+ return f"<VersionedMethod {self.name}>"
172
187
 
173
188
 
174
189
  def check_version_supported(api_version):
@@ -176,23 +191,27 @@ def check_version_supported(api_version):
176
191
 
177
192
  :warn Sends warning if version is not supported.
178
193
  """
179
- if (check_version_matches_min_max(api_version) or
180
- check_version_deprecated(api_version)):
194
+ if check_version_matches_min_max(api_version) or check_version_deprecated(
195
+ api_version
196
+ ):
181
197
  return True
182
198
  return False
183
199
 
184
200
 
185
201
  def check_version_matches_min_max(api_version):
186
202
  """Returns True if the API version is within the supported range."""
187
- if (not api_version.matches(
188
- manilaclient.API_MIN_VERSION,
189
- manilaclient.API_MAX_VERSION)):
190
- msg = _("Invalid client version '%(version)s'. "
191
- "Current version range is '%(min)s' through "
192
- " '%(max)s'") % {
203
+ if not api_version.matches(
204
+ manilaclient.API_MIN_VERSION, manilaclient.API_MAX_VERSION
205
+ ):
206
+ msg = _(
207
+ "Invalid client version '%(version)s'. "
208
+ "Current version range is '%(min)s' through "
209
+ " '%(max)s'"
210
+ ) % {
193
211
  "version": api_version.get_string(),
194
212
  "min": manilaclient.API_MIN_VERSION.get_string(),
195
- "max": manilaclient.API_MAX_VERSION.get_string()}
213
+ "max": manilaclient.API_MAX_VERSION.get_string(),
214
+ }
196
215
  warnings.warn(msg)
197
216
  return False
198
217
  return True
@@ -202,7 +221,8 @@ def check_version_deprecated(api_version):
202
221
  """Returns True if API version is deprecated."""
203
222
  if api_version == manilaclient.API_DEPRECATED_VERSION:
204
223
  msg = _("Client version '%(version)s' is deprecated.") % {
205
- "version": api_version.get_string()}
224
+ "version": api_version.get_string()
225
+ }
206
226
  warnings.warn(msg)
207
227
  return True
208
228
  return False
@@ -249,27 +269,29 @@ def discover_version(client, requested_version):
249
269
  :returns: APIVersion
250
270
  """
251
271
  server_start_version, server_end_version = _get_server_version_range(
252
- client)
272
+ client
273
+ )
253
274
 
254
275
  valid_version = requested_version
255
276
  if server_start_version.is_null() and server_end_version.is_null():
256
- msg = ("Server does not support microversions. Changing server "
257
- "version to %(min_version)s.")
277
+ msg = (
278
+ "Server does not support microversions. Changing server "
279
+ "version to %(min_version)s."
280
+ )
258
281
  LOG.debug(msg, {"min_version": DEPRECATED_VERSION})
259
282
  valid_version = APIVersion(DEPRECATED_VERSION)
260
283
  else:
261
284
  valid_version = _validate_requested_version(
262
- requested_version,
263
- server_start_version,
264
- server_end_version)
285
+ requested_version, server_start_version, server_end_version
286
+ )
265
287
 
266
288
  _validate_server_version(server_start_version, server_end_version)
267
289
  return valid_version
268
290
 
269
291
 
270
- def _validate_requested_version(requested_version,
271
- server_start_version,
272
- server_end_version):
292
+ def _validate_requested_version(
293
+ requested_version, server_start_version, server_end_version
294
+ ):
273
295
  """Validates the requested version.
274
296
 
275
297
  Checks 'requested_version' is within the min/max range supported by the
@@ -284,21 +306,34 @@ def _validate_requested_version(requested_version,
284
306
  valid_version = requested_version
285
307
  if not requested_version.matches(server_start_version, server_end_version):
286
308
  if server_end_version <= requested_version:
287
- if (manilaclient.API_MIN_VERSION <= server_end_version and
288
- server_end_version <= manilaclient.API_MAX_VERSION):
289
- msg = _("Requested version %(requested_version)s is "
290
- "not supported. Downgrading requested version "
291
- "to %(server_end_version)s.")
292
- LOG.debug(msg, {
293
- "requested_version": requested_version,
294
- "server_end_version": server_end_version})
309
+ if (
310
+ manilaclient.API_MIN_VERSION <= server_end_version
311
+ and server_end_version <= manilaclient.API_MAX_VERSION
312
+ ):
313
+ msg = _(
314
+ "Requested version %(requested_version)s is "
315
+ "not supported. Downgrading requested version "
316
+ "to %(server_end_version)s."
317
+ )
318
+ LOG.debug(
319
+ msg,
320
+ {
321
+ "requested_version": requested_version,
322
+ "server_end_version": server_end_version,
323
+ },
324
+ )
295
325
  valid_version = server_end_version
296
326
  else:
297
327
  raise exceptions.UnsupportedVersion(
298
- _("The specified version isn't supported by server. The valid "
299
- "version range is '%(min)s' to '%(max)s'") % {
328
+ _(
329
+ "The specified version isn't supported by server. "
330
+ "The valid version range is '%(min)s' to '%(max)s'"
331
+ )
332
+ % {
300
333
  "min": server_start_version.get_string(),
301
- "max": server_end_version.get_string()})
334
+ "max": server_end_version.get_string(),
335
+ }
336
+ )
302
337
 
303
338
  return valid_version
304
339
 
@@ -316,22 +351,34 @@ def _validate_server_version(server_start_version, server_end_version):
316
351
  """
317
352
  if manilaclient.API_MIN_VERSION > server_end_version:
318
353
  raise exceptions.UnsupportedVersion(
319
- _("Server's version is too old. The client's valid version range "
320
- "is '%(client_min)s' to '%(client_max)s'. The server valid "
321
- "version range is '%(server_min)s' to '%(server_max)s'.") % {
322
- 'client_min': manilaclient.API_MIN_VERSION.get_string(),
323
- 'client_max': manilaclient.API_MAX_VERSION.get_string(),
324
- 'server_min': server_start_version.get_string(),
325
- 'server_max': server_end_version.get_string()})
354
+ _(
355
+ "Server's version is too old. "
356
+ "The client's valid version range "
357
+ "is '%(client_min)s' to '%(client_max)s'. The server valid "
358
+ "version range is '%(server_min)s' to '%(server_max)s'."
359
+ )
360
+ % {
361
+ 'client_min': manilaclient.API_MIN_VERSION.get_string(),
362
+ 'client_max': manilaclient.API_MAX_VERSION.get_string(),
363
+ 'server_min': server_start_version.get_string(),
364
+ 'server_max': server_end_version.get_string(),
365
+ }
366
+ )
326
367
  elif manilaclient.API_MAX_VERSION < server_start_version:
327
368
  raise exceptions.UnsupportedVersion(
328
- _("Server's version is too new. The client's valid version range "
329
- "is '%(client_min)s' to '%(client_max)s'. The server valid "
330
- "version range is '%(server_min)s' to '%(server_max)s'.") % {
331
- 'client_min': manilaclient.API_MIN_VERSION.get_string(),
332
- 'client_max': manilaclient.API_MAX_VERSION.get_string(),
333
- 'server_min': server_start_version.get_string(),
334
- 'server_max': server_end_version.get_string()})
369
+ _(
370
+ "Server's version is too new. "
371
+ "The client's valid version range "
372
+ "is '%(client_min)s' to '%(client_max)s'. The server valid "
373
+ "version range is '%(server_min)s' to '%(server_max)s'."
374
+ )
375
+ % {
376
+ 'client_min': manilaclient.API_MIN_VERSION.get_string(),
377
+ 'client_max': manilaclient.API_MAX_VERSION.get_string(),
378
+ 'server_min': server_start_version.get_string(),
379
+ 'server_max': server_end_version.get_string(),
380
+ }
381
+ )
335
382
 
336
383
 
337
384
  def add_versioned_method(versioned_method):
@@ -342,8 +389,11 @@ def add_versioned_method(versioned_method):
342
389
  def get_versioned_methods(func_name, api_version=None):
343
390
  versioned_methods = _VERSIONED_METHOD_MAP.get(func_name, [])
344
391
  if api_version and not api_version.is_null():
345
- return [m for m in versioned_methods
346
- if api_version.matches(m.start_version, m.end_version)]
392
+ return [
393
+ m
394
+ for m in versioned_methods
395
+ if api_version.matches(m.start_version, m.end_version)
396
+ ]
347
397
  return versioned_methods
348
398
 
349
399
 
@@ -353,11 +403,13 @@ def experimental_api(f):
353
403
  @functools.wraps(f)
354
404
  def _wrapper(*args, **kwargs):
355
405
  client = args[0]
356
- if (isinstance(client, manilaclient.v2.client.Client) or
357
- hasattr(client, 'client')):
406
+ if isinstance(client, manilaclient.v2.client.Client) or hasattr(
407
+ client, 'client'
408
+ ):
358
409
  dh = client.client.default_headers
359
410
  dh[constants.EXPERIMENTAL_HTTP_HEADER] = 'true'
360
411
  return f(*args, **kwargs)
412
+
361
413
  return _wrapper
362
414
 
363
415
 
@@ -378,8 +430,9 @@ def wraps(start_version, end_version=MAX_VERSION):
378
430
  def decor(func):
379
431
  func.versioned = True
380
432
  name = utils.get_function_name(func)
381
- versioned_method = VersionedMethod(name, start_version,
382
- end_version, func)
433
+ versioned_method = VersionedMethod(
434
+ name, start_version, end_version, func
435
+ )
383
436
  add_versioned_method(versioned_method)
384
437
 
385
438
  @functools.wraps(func)
@@ -388,11 +441,15 @@ def wraps(start_version, end_version=MAX_VERSION):
388
441
 
389
442
  if not methods:
390
443
  raise exceptions.UnsupportedVersion(
391
- _("API version '%(version)s' is not supported on "
392
- "'%(method)s' method.") % {
444
+ _(
445
+ "API version '%(version)s' is not supported on "
446
+ "'%(method)s' method."
447
+ )
448
+ % {
393
449
  "version": obj.api_version.get_string(),
394
450
  "method": name,
395
- })
451
+ }
452
+ )
396
453
 
397
454
  method = max(methods, key=lambda f: f.start_version)
398
455
 
manilaclient/base.py CHANGED
@@ -25,6 +25,8 @@ import copy
25
25
  import hashlib
26
26
  import os
27
27
 
28
+ from oslo_utils import strutils
29
+
28
30
  from manilaclient import api_versions
29
31
  from manilaclient.common import cliutils
30
32
  from manilaclient import exceptions
@@ -54,6 +56,7 @@ class Manager(utils.HookableMixin):
54
56
  Managers interact with a particular type of API (shares, snapshots,
55
57
  etc.) and provide CRUD operations for them.
56
58
  """
59
+
57
60
  resource_class = None
58
61
 
59
62
  def __init__(self, api):
@@ -64,8 +67,9 @@ class Manager(utils.HookableMixin):
64
67
  def api_version(self):
65
68
  return self.api.api_version
66
69
 
67
- def _list(self, url, response_key, manager=None, body=None,
68
- return_raw=None):
70
+ def _list(
71
+ self, url, response_key, manager=None, body=None, return_raw=None
72
+ ):
69
73
  """List the collection.
70
74
 
71
75
  :param url: a partial URL, e.g., '/shares'
@@ -100,8 +104,9 @@ class Manager(utils.HookableMixin):
100
104
  with self.completion_cache('uuid', obj_class, mode="w"):
101
105
  if return_raw:
102
106
  return data
103
- resource = [obj_class(manager, res, loaded=True)
104
- for res in data if res]
107
+ resource = [
108
+ obj_class(manager, res, loaded=True) for res in data if res
109
+ ]
105
110
  if 'count' in body:
106
111
  return resource, body['count']
107
112
  else:
@@ -121,16 +126,19 @@ class Manager(utils.HookableMixin):
121
126
  Delete is not handled because listings are assumed to be performed
122
127
  often enough to keep the cache reasonably up-to-date.
123
128
  """
124
- base_dir = cliutils.env('manilaclient_UUID_CACHE_DIR',
125
- 'MANILACLIENT_UUID_CACHE_DIR',
126
- default="~/.cache/manilaclient")
129
+ base_dir = cliutils.env(
130
+ 'manilaclient_UUID_CACHE_DIR',
131
+ 'MANILACLIENT_UUID_CACHE_DIR',
132
+ default="~/.cache/manilaclient",
133
+ )
127
134
 
128
135
  # NOTE(sirp): Keep separate UUID caches for each username + endpoint
129
136
  # pair
130
137
  username = cliutils.env('OS_USERNAME', 'MANILA_USERNAME')
131
138
  url = cliutils.env('OS_URL', 'MANILA_URL')
132
- uniqifier = hashlib.sha256(username.encode('utf-8') +
133
- url.encode('utf-8')).hexdigest()
139
+ uniqifier = hashlib.sha256(
140
+ username.encode('utf-8') + url.encode('utf-8')
141
+ ).hexdigest()
134
142
 
135
143
  cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier))
136
144
 
@@ -143,14 +151,14 @@ class Manager(utils.HookableMixin):
143
151
  pass
144
152
 
145
153
  resource = obj_class.__name__.lower()
146
- filename = "%s-%s-cache" % (resource, cache_type.replace('_', '-'))
154
+ filename = "{}-{}-cache".format(resource, cache_type.replace('_', '-'))
147
155
  path = os.path.join(cache_dir, filename)
148
156
 
149
- cache_attr = "_%s_cache" % cache_type
157
+ cache_attr = f"_{cache_type}_cache"
150
158
 
151
159
  try:
152
160
  setattr(self, cache_attr, open(path, mode))
153
- except IOError:
161
+ except OSError:
154
162
  # NOTE(kiall): This is typically a permission denied while
155
163
  # attempting to write the cache file.
156
164
  pass
@@ -164,10 +172,10 @@ class Manager(utils.HookableMixin):
164
172
  delattr(self, cache_attr)
165
173
 
166
174
  def write_to_completion_cache(self, cache_type, val):
167
- cache = getattr(self, "_%s_cache" % cache_type, None)
175
+ cache = getattr(self, f"_{cache_type}_cache", None)
168
176
  if cache:
169
177
  try:
170
- cache.write("%s\n" % val)
178
+ cache.write(f"{val}\n")
171
179
  except UnicodeEncodeError:
172
180
  pass
173
181
 
@@ -183,8 +191,11 @@ class Manager(utils.HookableMixin):
183
191
  def _get_with_base_url(self, url, response_key=None):
184
192
  resp, body = self.api.client.get_with_base_url(url)
185
193
  if response_key:
186
- return [self.resource_class(self, res, loaded=True)
187
- for res in body[response_key] if res]
194
+ return [
195
+ self.resource_class(self, res, loaded=True)
196
+ for res in body[response_key]
197
+ if res
198
+ ]
188
199
  else:
189
200
  return self.resource_class(self, body, loaded=True)
190
201
 
@@ -215,14 +226,14 @@ class Manager(utils.HookableMixin):
215
226
 
216
227
  def _build_query_string(self, search_opts):
217
228
  search_opts = search_opts or {}
218
- params = sorted(
219
- [(k, v) for (k, v) in search_opts.items() if v])
220
- query_string = "?%s" % utils.safe_urlencode(params) if params else ''
229
+ params = sorted([(k, v) for (k, v) in search_opts.items() if v])
230
+ query_string = f"?{utils.safe_urlencode(params)}" if params else ''
221
231
  return query_string
222
232
 
223
233
 
224
234
  class ManagerWithFind(Manager):
225
235
  """Like a `Manager`, but with additional `find()`/`findall()` methods."""
236
+
226
237
  def find(self, **kwargs):
227
238
  """Find a single item with attributes matching ``**kwargs``.
228
239
 
@@ -232,7 +243,7 @@ class ManagerWithFind(Manager):
232
243
  matches = self.findall(**kwargs)
233
244
  num_matches = len(matches)
234
245
  if num_matches == 0:
235
- msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
246
+ msg = f"No {self.resource_class.__name__} matching {kwargs}."
236
247
  raise exceptions.NotFound(404, msg)
237
248
  elif num_matches > 1:
238
249
  raise exceptions.NoUniqueMatch
@@ -250,16 +261,17 @@ class ManagerWithFind(Manager):
250
261
 
251
262
  search_opts = {'all_tenants': 1}
252
263
  resources = self.list(search_opts=search_opts)
253
- if ('v2.shares.ShareManager' in str(self.__class__) and
254
- self.api_version >= api_versions.APIVersion("2.69")):
255
- search_opts_2 = {'all_tenants': 1,
256
- 'is_soft_deleted': True}
264
+ if 'v2.shares.ShareManager' in str(
265
+ self.__class__
266
+ ) and self.api_version >= api_versions.APIVersion("2.69"):
267
+ search_opts_2 = {'all_tenants': 1, 'is_soft_deleted': True}
257
268
  shares_soft_deleted = self.list(search_opts=search_opts_2)
258
269
  resources += shares_soft_deleted
259
270
  for obj in resources:
260
271
  try:
261
- if all(getattr(obj, attr) == value
262
- for (attr, value) in searches):
272
+ if all(
273
+ getattr(obj, attr) == value for (attr, value) in searches
274
+ ):
263
275
  found.append(obj)
264
276
  except AttributeError:
265
277
  continue
@@ -270,7 +282,7 @@ class ManagerWithFind(Manager):
270
282
  raise NotImplementedError
271
283
 
272
284
 
273
- class Resource(object):
285
+ class Resource:
274
286
  """Base class for OpenStack resources (tenant, user, etc.).
275
287
 
276
288
  This is pretty much just a bag for attributes.
@@ -292,11 +304,11 @@ class Resource(object):
292
304
  self._loaded = loaded
293
305
 
294
306
  def __repr__(self):
295
- reprkeys = sorted(k
296
- for k in self.__dict__.keys()
297
- if k[0] != '_' and k != 'manager')
298
- info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
299
- return "<%s %s>" % (self.__class__.__name__, info)
307
+ reprkeys = sorted(
308
+ k for k in self.__dict__.keys() if k[0] != '_' and k != 'manager'
309
+ )
310
+ info = ", ".join(f"{k}={getattr(self, k)}" for k in reprkeys)
311
+ return f"<{self.__class__.__name__} {info}>"
300
312
 
301
313
  @property
302
314
  def human_id(self):
@@ -308,7 +320,7 @@ class Resource(object):
308
320
  return None
309
321
 
310
322
  def _add_details(self, info):
311
- for (k, v) in info.items():
323
+ for k, v in info.items():
312
324
  try:
313
325
  setattr(self, k, v)
314
326
  self._info[k] = v
@@ -366,7 +378,6 @@ class Resource(object):
366
378
 
367
379
 
368
380
  class MetadataCapableResource(Resource, metaclass=abc.ABCMeta):
369
-
370
381
  superresource = None
371
382
 
372
383
  def _get_subresource_and_resource(self, superresource):
@@ -388,7 +399,8 @@ class MetadataCapableResource(Resource, metaclass=abc.ABCMeta):
388
399
  """
389
400
 
390
401
  resource, subresource = self._get_subresource_and_resource(
391
- superresource)
402
+ superresource
403
+ )
392
404
 
393
405
  return self.manager.get_metadata(resource, subresource=subresource)
394
406
 
@@ -403,10 +415,12 @@ class MetadataCapableResource(Resource, metaclass=abc.ABCMeta):
403
415
  by default
404
416
  """
405
417
  resource, subresource = self._get_subresource_and_resource(
406
- superresource)
418
+ superresource
419
+ )
407
420
 
408
- return self.manager.set_metadata(resource, metadata,
409
- subresource=subresource)
421
+ return self.manager.set_metadata(
422
+ resource, metadata, subresource=subresource
423
+ )
410
424
 
411
425
  def delete_metadata(self, keys, superresource=None):
412
426
  """Delete specified keys from the given resource.
@@ -418,10 +432,12 @@ class MetadataCapableResource(Resource, metaclass=abc.ABCMeta):
418
432
  by default
419
433
  """
420
434
  resource, subresource = self._get_subresource_and_resource(
421
- superresource)
435
+ superresource
436
+ )
422
437
 
423
- return self.manager.delete_metadata(resource, keys,
424
- subresource=subresource)
438
+ return self.manager.delete_metadata(
439
+ resource, keys, subresource=subresource
440
+ )
425
441
 
426
442
  def update_all_metadata(self, metadata, superresource=None):
427
443
  """Update all metadata for this resource.
@@ -434,11 +450,12 @@ class MetadataCapableResource(Resource, metaclass=abc.ABCMeta):
434
450
  by default
435
451
  """
436
452
  resource, subresource = self._get_subresource_and_resource(
437
- superresource)
453
+ superresource
454
+ )
438
455
 
439
- return self.manager.update_all_metadata(resource,
440
- metadata,
441
- subresource=subresource)
456
+ return self.manager.update_all_metadata(
457
+ resource, metadata, subresource=subresource
458
+ )
442
459
 
443
460
 
444
461
  class MetadataCapableManager(ManagerWithFind, metaclass=abc.ABCMeta):
@@ -458,8 +475,9 @@ class MetadataCapableManager(ManagerWithFind, metaclass=abc.ABCMeta):
458
475
  subresource = getid(subresource)
459
476
  resource = f"{resource}{self.subresource_path}/{subresource}"
460
477
 
461
- return self._get(f"{self.resource_path}/{resource}/metadata",
462
- "metadata")
478
+ return self._get(
479
+ f"{self.resource_path}/{resource}/metadata", "metadata"
480
+ )
463
481
 
464
482
  def set_metadata(self, resource, metadata, subresource=None):
465
483
  """Set or update metadata for resource.
@@ -475,9 +493,9 @@ class MetadataCapableManager(ManagerWithFind, metaclass=abc.ABCMeta):
475
493
  subresource = getid(subresource)
476
494
  resource = f"{resource}{self.subresource_path}/{subresource}"
477
495
 
478
- return self._create(f"{self.resource_path}/{resource}/metadata",
479
- body,
480
- "metadata")
496
+ return self._create(
497
+ f"{self.resource_path}/{resource}/metadata", body, "metadata"
498
+ )
481
499
 
482
500
  def delete_metadata(self, resource, keys, subresource=None):
483
501
  """Delete specified keys from resource metadata.
@@ -508,5 +526,4 @@ class MetadataCapableManager(ManagerWithFind, metaclass=abc.ABCMeta):
508
526
  subresource = getid(subresource)
509
527
  resource = f"{resource}{self.subresource_path}/{subresource}"
510
528
 
511
- return self._update(f"{self.resource_path}/{resource}/metadata",
512
- body)
529
+ return self._update(f"{self.resource_path}/{resource}/metadata", body)