| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
ANSIBLE_METADATA = { |
| 13 |
"metadata_version": "1.1", |
| 14 |
"status": ["preview"], |
| 15 |
"supported_by": "community", |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
DOCUMENTATION = """ |
| 20 |
--- |
| 21 |
module: purefb_fs |
| 22 |
version_added: "1.0.0" |
| 23 |
short_description: Manage filesystemon Pure Storage FlashBlade` |
| 24 |
description: |
| 25 |
- This module manages filesystems on Pure Storage FlashBlade. |
| 26 |
author: Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 27 |
options: |
| 28 |
name: |
| 29 |
description: |
| 30 |
- Filesystem Name. |
| 31 |
required: true |
| 32 |
type: str |
| 33 |
state: |
| 34 |
description: |
| 35 |
- Create, delete or modifies a filesystem. |
| 36 |
required: false |
| 37 |
default: present |
| 38 |
type: str |
| 39 |
choices: [ "present", "absent" ] |
| 40 |
eradicate: |
| 41 |
description: |
| 42 |
- Define whether to eradicate the filesystem on delete or leave in trash. |
| 43 |
required: false |
| 44 |
type: bool |
| 45 |
default: false |
| 46 |
size: |
| 47 |
description: |
| 48 |
- Volume size in M, G, T or P units. See examples. |
| 49 |
- If size is not set at filesystem creation time the filesystem size becomes unlimited. |
| 50 |
type: str |
| 51 |
required: false |
| 52 |
nfsv3: |
| 53 |
description: |
| 54 |
- Define whether to NFSv3 protocol is enabled for the filesystem. |
| 55 |
required: false |
| 56 |
type: bool |
| 57 |
default: true |
| 58 |
nfsv4: |
| 59 |
description: |
| 60 |
- Define whether to NFSv4.1 protocol is enabled for the filesystem. |
| 61 |
required: false |
| 62 |
type: bool |
| 63 |
default: true |
| 64 |
nfs_rules: |
| 65 |
description: |
| 66 |
- Define the NFS rules in operation. |
| 67 |
- If not set at filesystem creation time it defaults to I(*(rw,no_root_squash)) |
| 68 |
- Supported binary options are ro/rw, secure/insecure, fileid_32bit/no_fileid_32bit, |
| 69 |
root_squash/no_root_squash, all_squash/no_all_squash and atime/noatime |
| 70 |
- Supported non-binary options are anonuid=#, anongid=#, sec=(sys|krb5) |
| 71 |
- Superceeded by I(export_policy) if provided |
| 72 |
required: false |
| 73 |
type: str |
| 74 |
smb: |
| 75 |
description: |
| 76 |
- Define whether to SMB protocol is enabled for the filesystem. |
| 77 |
required: false |
| 78 |
type: bool |
| 79 |
default: false |
| 80 |
smb_aclmode: |
| 81 |
description: |
| 82 |
- Specify the ACL mode for the SMB protocol. |
| 83 |
- Deprecated from Purity//FB 3.1.1. Use I(access_control) instead. |
| 84 |
required: false |
| 85 |
type: str |
| 86 |
default: shared |
| 87 |
choices: [ "shared", "native" ] |
| 88 |
http: |
| 89 |
description: |
| 90 |
- Define whether to HTTP/HTTPS protocol is enabled for the filesystem. |
| 91 |
required: false |
| 92 |
type: bool |
| 93 |
default: false |
| 94 |
snapshot: |
| 95 |
description: |
| 96 |
- Define whether a snapshot directory is enabled for the filesystem. |
| 97 |
required: false |
| 98 |
type: bool |
| 99 |
default: false |
| 100 |
writable: |
| 101 |
description: |
| 102 |
- Define if a filesystem is writable. |
| 103 |
required: false |
| 104 |
type: bool |
| 105 |
promote: |
| 106 |
description: |
| 107 |
- Promote/demote a filesystem. |
| 108 |
- Can only demote the file-system if it is in a replica-link relationship. |
| 109 |
required: false |
| 110 |
type: bool |
| 111 |
fastremove: |
| 112 |
description: |
| 113 |
- Define whether the fast remove directory is enabled for the filesystem. |
| 114 |
required: false |
| 115 |
type: bool |
| 116 |
default: false |
| 117 |
hard_limit: |
| 118 |
description: |
| 119 |
- Define whether the capacity for a filesystem is a hard limit. |
| 120 |
- CAUTION This will cause the filesystem to go Read-Only if the |
| 121 |
capacity has already exceeded the logical size of the filesystem. |
| 122 |
required: false |
| 123 |
type: bool |
| 124 |
default: false |
| 125 |
user_quota: |
| 126 |
description: |
| 127 |
- Default quota in M, G, T or P units for a user under this file system. |
| 128 |
required: false |
| 129 |
type: str |
| 130 |
group_quota: |
| 131 |
description: |
| 132 |
- Default quota in M, G, T or P units for a group under this file system. |
| 133 |
required: false |
| 134 |
type: str |
| 135 |
policy: |
| 136 |
description: |
| 137 |
- Filesystem policy to assign to or remove from a filesystem. |
| 138 |
required: false |
| 139 |
type: str |
| 140 |
policy_state: |
| 141 |
description: |
| 142 |
- Add or delete a policy from a filesystem |
| 143 |
required: false |
| 144 |
default: present |
| 145 |
type: str |
| 146 |
choices: [ "absent", "present" ] |
| 147 |
delete_link: |
| 148 |
description: |
| 149 |
- Define if the filesystem can be deleted even if it has a replica link |
| 150 |
required: false |
| 151 |
default: false |
| 152 |
type: bool |
| 153 |
discard_snaps: |
| 154 |
description: |
| 155 |
- Allow a filesystem to be demoted. |
| 156 |
required: false |
| 157 |
default: false |
| 158 |
type: bool |
| 159 |
access_control: |
| 160 |
description: |
| 161 |
- The access control style that is utilized for client actions such |
| 162 |
as setting file and directory ACLs. |
| 163 |
type: str |
| 164 |
default: shared |
| 165 |
choices: [ 'nfs', 'smb', 'shared', 'independent', 'mode-bits' ] |
| 166 |
safeguard_acls: |
| 167 |
description: |
| 168 |
- Safeguards ACLs on a filesystem. |
| 169 |
- Performs different roles depending on the filesystem protocol enabled. |
| 170 |
- See Purity//FB documentation for detailed description. |
| 171 |
type: bool |
| 172 |
default: true |
| 173 |
export_policy: |
| 174 |
description: |
| 175 |
- Name of NFS export policy to assign to filesystem |
| 176 |
- Overrides I(nfs_rules) |
| 177 |
type: str |
| 178 |
version_added: "1.9.0" |
| 179 |
share_policy: |
| 180 |
description: |
| 181 |
- Name of SMB share policy to assign to filesystem |
| 182 |
- Only valid with REST 2.10 or higher |
| 183 |
- Remove policy with empty string |
| 184 |
type: str |
| 185 |
version_added: "1.12.0" |
| 186 |
client_policy: |
| 187 |
description: |
| 188 |
- Name of SMB client policy to assign to filesystem |
| 189 |
- Only valid with REST 2.10 or higher |
| 190 |
- Remove policy with empty string |
| 191 |
type: str |
| 192 |
version_added: "1.12.0" |
| 193 |
continuous_availability: |
| 194 |
description: |
| 195 |
- Defines if the file system will be continuously available during |
| 196 |
disruptive scenarios such as network disruption, blades failover, etc |
| 197 |
type: bool |
| 198 |
default: true |
| 199 |
version_added: "1.15.0" |
| 200 |
group_ownership: |
| 201 |
description: |
| 202 |
- The group ownership for new files and directories in a file system |
| 203 |
type: str |
| 204 |
choices: [ 'creator', 'parent-directory' ] |
| 205 |
default: creator |
| 206 |
version_added: "1.17.0" |
| 207 |
ignore_usage: |
| 208 |
description: |
| 209 |
- Allow update operations that lead to a hard_limit_enabled file |
| 210 |
system with usage over its limiting value |
| 211 |
type: bool |
| 212 |
default: false |
| 213 |
version_added: "1.22.0" |
| 214 |
cancel_in_progress: |
| 215 |
description: |
| 216 |
- Whether to cancel any existing storage class transitons that are in progress |
| 217 |
if the file system is requested to changed to another storage class |
| 218 |
type: bool |
| 219 |
default: false |
| 220 |
version_added: "1.22.0" |
| 221 |
storage_class: |
| 222 |
description: |
| 223 |
- Name of storage class in Fusion fleet file system is associated with |
| 224 |
type: str |
| 225 |
version_added: "1.22.0" |
| 226 |
context: |
| 227 |
description: |
| 228 |
- Name of fleet member on which to perform the operation. |
| 229 |
- This requires the array receiving the request is a member of a fleet |
| 230 |
and the context name to be a member of the same fleet. |
| 231 |
type: str |
| 232 |
default: "" |
| 233 |
version_added: "1.22.0" |
| 234 |
extends_documentation_fragment: |
| 235 |
- purestorage.flashblade.purestorage.fb |
| 236 |
""" |
| 237 |
|
| 238 |
EXAMPLES = """ |
| 239 |
- name: Create new filesystem named foo |
| 240 |
purestorage.flashblade.purefb_fs: |
| 241 |
name: foo |
| 242 |
size: 1T |
| 243 |
state: present |
| 244 |
fb_url: 10.10.10.2 |
| 245 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 246 |
|
| 247 |
- name: Delete filesystem named foo |
| 248 |
purestorage.flashblade.purefb_fs: |
| 249 |
name: foo |
| 250 |
state: absent |
| 251 |
fb_url: 10.10.10.2 |
| 252 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 253 |
|
| 254 |
- name: Recover filesystem named foo |
| 255 |
purestorage.flashblade.purefb_fs: |
| 256 |
name: foo |
| 257 |
state: present |
| 258 |
fb_url: 10.10.10.2 |
| 259 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 260 |
|
| 261 |
- name: Eradicate filesystem named foo |
| 262 |
purestorage.flashblade.purefb_fs: |
| 263 |
name: foo |
| 264 |
state: absent |
| 265 |
eradicate: true |
| 266 |
fb_url: 10.10.10.2 |
| 267 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 268 |
|
| 269 |
- name: Promote filesystem named foo ready for failover |
| 270 |
purestorage.flashblade.purefb_fs: |
| 271 |
name: foo |
| 272 |
promote: true |
| 273 |
fb_url: 10.10.10.2 |
| 274 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 275 |
|
| 276 |
- name: Demote filesystem named foo after failover |
| 277 |
purestorage.flashblade.purefb_fs: |
| 278 |
name: foo |
| 279 |
promote: false |
| 280 |
fb_url: 10.10.10.2 |
| 281 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 282 |
|
| 283 |
- name: Modify attributes of an existing filesystem named foo |
| 284 |
purestorage.flashblade.purefb_fs: |
| 285 |
name: foo |
| 286 |
size: 2T |
| 287 |
nfsv3: false |
| 288 |
nfsv4: true |
| 289 |
user_quota: 10K |
| 290 |
group_quota: 25M |
| 291 |
nfs_rules: '10.21.200.0/24(ro)' |
| 292 |
snapshot: true |
| 293 |
fastremove: true |
| 294 |
hard_limit: true |
| 295 |
smb: true |
| 296 |
state: present |
| 297 |
fb_url: 10.10.10.2 |
| 298 |
api_token: T-55a68eb5-c785-4720-a2ca-8b03903bf641 |
| 299 |
""" |
| 300 |
|
| 301 |
RETURN = """ |
| 302 |
""" |
| 303 |
|
| 304 |
HAS_PYPURECLIENT = True |
| 305 |
try: |
| 306 |
from pypureclient.flashblade import ( |
| 307 |
FileSystemPatch, |
| 308 |
NfsPatch, |
| 309 |
Reference, |
| 310 |
Smb, |
| 311 |
FileSystemPost, |
| 312 |
Nfs, |
| 313 |
SmbPost, |
| 314 |
Http, |
| 315 |
MultiProtocolPost, |
| 316 |
MultiProtocol, |
| 317 |
StorageClassInfo, |
| 318 |
) |
| 319 |
except ImportError: |
| 320 |
HAS_PYPURECLIENT = False |
| 321 |
|
| 322 |
from ansible.module_utils.basic import AnsibleModule, human_to_bytes |
| 323 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 324 |
get_system, |
| 325 |
purefb_argument_spec, |
| 326 |
) |
| 327 |
|
| 328 |
|
| 329 |
EXPORT_POLICY_API_VERSION = "2.3" |
| 330 |
SMB_POLICY_API_VERSION = "2.10" |
| 331 |
CA_API_VERSION = "2.12" |
| 332 |
GOWNER_API_VERSION = "2.13" |
| 333 |
CONTEXT_API_VERSION = "2.17" |
| 334 |
|
| 335 |
|
| 336 |
def get_fs(module, blade): |
| 337 |
"""Return Filesystem or None""" |
| 338 |
api_version = list(blade.get_versions().items) |
| 339 |
if CONTEXT_API_VERSION in api_version: |
| 340 |
res = blade.get_file_systems( |
| 341 |
context_names=[module.params["context"]], |
| 342 |
names=[module.params["name"]], |
| 343 |
) |
| 344 |
else: |
| 345 |
res = blade.get_file_systems(names=[module.params["name"]]) |
| 346 |
if res.status_code == 200: |
| 347 |
return list(res.items)[0] |
| 348 |
return None |
| 349 |
|
| 350 |
|
| 351 |
def create_fs(module, blade): |
| 352 |
"""Create Filesystem""" |
| 353 |
changed = True |
| 354 |
api_version = list(blade.get_versions().items) |
| 355 |
if not module.check_mode: |
| 356 |
if not module.params["nfs_rules"]: |
| 357 |
module.params["nfs_rules"] = "*(rw,no_root_squash)" |
| 358 |
if module.params["size"]: |
| 359 |
size = human_to_bytes(module.params["size"]) |
| 360 |
else: |
| 361 |
size = 0 |
| 362 |
|
| 363 |
if module.params["user_quota"]: |
| 364 |
user_quota = human_to_bytes(module.params["user_quota"]) |
| 365 |
else: |
| 366 |
user_quota = None |
| 367 |
if module.params["group_quota"]: |
| 368 |
group_quota = human_to_bytes(module.params["group_quota"]) |
| 369 |
else: |
| 370 |
group_quota = None |
| 371 |
|
| 372 |
if module.params["access_control"] == "nfs" and not ( |
| 373 |
module.params["nfsv3"] or module.params["nfsv4"] |
| 374 |
): |
| 375 |
module.fail_json( |
| 376 |
msg="Cannot set access_control to nfs when NFS is not enabled." |
| 377 |
) |
| 378 |
if ( |
| 379 |
module.params["access_control"] in ["smb", "independent"] |
| 380 |
and not module.params["smb"] |
| 381 |
): |
| 382 |
module.fail_json( |
| 383 |
msg="Cannot set access_control to smb or independent when SMB is not enabled." |
| 384 |
) |
| 385 |
if module.params["smb"] and not ( |
| 386 |
module.params["nfsv3"] or module.params["nfsv4"] |
| 387 |
): |
| 388 |
module.params["nfs_rules"] = "" |
| 389 |
if module.params["safeguard_acls"] and ( |
| 390 |
module.params["access_control"] in ["mode-bits", "independent"] |
| 391 |
): |
| 392 |
module.fail_json( |
| 393 |
msg="ACL Safeguarding cannot be enabled if access_control is mode-bits or independent." |
| 394 |
) |
| 395 |
fs_obj = FileSystemPost( |
| 396 |
provisioned=size, |
| 397 |
fast_remove_directory_enabled=module.params["fastremove"], |
| 398 |
hard_limit_enabled=module.params["hard_limit"], |
| 399 |
snapshot_directory_enabled=module.params["snapshot"], |
| 400 |
nfs=Nfs( |
| 401 |
v3_enabled=module.params["nfsv3"], |
| 402 |
v4_1_enabled=module.params["nfsv4"], |
| 403 |
rules=module.params["nfs_rules"], |
| 404 |
), |
| 405 |
smb=SmbPost(enabled=module.params["smb"]), |
| 406 |
http=Http(enabled=module.params["http"]), |
| 407 |
multi_protocol=MultiProtocolPost( |
| 408 |
safeguard_acls=module.params["safeguard_acls"], |
| 409 |
access_control_style=module.params["access_control"], |
| 410 |
), |
| 411 |
default_user_quota=user_quota, |
| 412 |
default_group_quota=group_quota, |
| 413 |
) |
| 414 |
if CONTEXT_API_VERSION in api_version: |
| 415 |
res = blade.post_file_systems( |
| 416 |
names=[module.params["name"]], |
| 417 |
file_system=fs_obj, |
| 418 |
context_names=[module.params["context"]], |
| 419 |
) |
| 420 |
else: |
| 421 |
res = blade.post_file_systems( |
| 422 |
names=[module.params["name"]], file_system=fs_obj |
| 423 |
) |
| 424 |
if res.status_code != 200: |
| 425 |
module.fail_json( |
| 426 |
msg="Failed to create filesystem {0}. Error: {1}".format( |
| 427 |
module.params["name"], res.errors[0].message |
| 428 |
) |
| 429 |
) |
| 430 |
if module.params["policy"]: |
| 431 |
if CONTEXT_API_VERSION in api_version: |
| 432 |
res = blade.get_policies( |
| 433 |
names=[module.params["policy"]], |
| 434 |
context_names=[module.params["context"]], |
| 435 |
) |
| 436 |
else: |
| 437 |
res = blade.get_policies(names=[module.params["policy"]]) |
| 438 |
if res.status_code != 200: |
| 439 |
_delete_fs(module, blade) |
| 440 |
module.fail_json( |
| 441 |
msg="Policy {0} doesn't exist.".format(module.params["policy"]) |
| 442 |
) |
| 443 |
if CONTEXT_API_VERSION in api_version: |
| 444 |
res = blade.post_policies_file_systems( |
| 445 |
policy_names=[module.params["policy"]], |
| 446 |
member_names=[module.params["name"]], |
| 447 |
context_names=[module.params["context"]], |
| 448 |
) |
| 449 |
else: |
| 450 |
res = blade.post_policies_file_systems( |
| 451 |
policy_names=[module.params["policy"]], |
| 452 |
member_names=[module.params["name"]], |
| 453 |
) |
| 454 |
if res.status_code != 200: |
| 455 |
_delete_fs(module, blade) |
| 456 |
module.fail_json( |
| 457 |
msg="Failed to apply policy {0} when creating filesystem {1}. Error: {2}".format( |
| 458 |
module.params["policy"], |
| 459 |
module.params["name"], |
| 460 |
res.errors[0].message, |
| 461 |
) |
| 462 |
) |
| 463 |
if EXPORT_POLICY_API_VERSION in api_version and module.params["export_policy"]: |
| 464 |
export_attr = FileSystemPatch( |
| 465 |
nfs=NfsPatch( |
| 466 |
export_policy=Reference(name=module.params["export_policy"]) |
| 467 |
) |
| 468 |
) |
| 469 |
if CONTEXT_API_VERSION in api_version: |
| 470 |
res = blade.patch_file_systems( |
| 471 |
names=[module.params["name"]], |
| 472 |
file_system=export_attr, |
| 473 |
context_names=[module.params["context"]], |
| 474 |
) |
| 475 |
else: |
| 476 |
res = blade.patch_file_systems( |
| 477 |
names=[module.params["name"]], file_system=export_attr |
| 478 |
) |
| 479 |
if res.status_code != 200: |
| 480 |
module.fail_json( |
| 481 |
msg="Filesystem {0} created, but failed to assign export " |
| 482 |
"policy {1}. Error: {2}".format( |
| 483 |
module.params["name"], |
| 484 |
module.params["export_policy"], |
| 485 |
res.errors[0].message, |
| 486 |
) |
| 487 |
) |
| 488 |
if SMB_POLICY_API_VERSION in api_version: |
| 489 |
if module.params["client_policy"]: |
| 490 |
export_attr = FileSystemPatch( |
| 491 |
smb=Smb( |
| 492 |
client_policy=Reference(name=module.params["client_policy"]) |
| 493 |
) |
| 494 |
) |
| 495 |
if CONTEXT_API_VERSION in api_version: |
| 496 |
res = blade.patch_file_systems( |
| 497 |
names=[module.params["name"]], |
| 498 |
file_system=export_attr, |
| 499 |
context_names=[module.params["context"]], |
| 500 |
) |
| 501 |
else: |
| 502 |
res = blade.patch_file_systems( |
| 503 |
names=[module.params["name"]], file_system=export_attr |
| 504 |
) |
| 505 |
if res.status_code != 200: |
| 506 |
module.fail_json( |
| 507 |
msg="Filesystem {0} created, but failed to assign client " |
| 508 |
"policy {1}. Error: {2}".format( |
| 509 |
module.params["name"], |
| 510 |
module.params["client_policy"], |
| 511 |
res.errors[0].message, |
| 512 |
) |
| 513 |
) |
| 514 |
if module.params["share_policy"]: |
| 515 |
export_attr = FileSystemPatch( |
| 516 |
smb=Smb(share_policy=Reference(name=module.params["share_policy"])) |
| 517 |
) |
| 518 |
if CONTEXT_API_VERSION in api_version: |
| 519 |
res = blade.patch_file_systems( |
| 520 |
names=[module.params["name"]], |
| 521 |
file_system=export_attr, |
| 522 |
context_names=[module.params["context"]], |
| 523 |
) |
| 524 |
else: |
| 525 |
res = blade.patch_file_systems( |
| 526 |
names=[module.params["name"]], |
| 527 |
file_system=export_attr, |
| 528 |
) |
| 529 |
if res.status_code != 200: |
| 530 |
module.fail_json( |
| 531 |
msg="Filesystem {0} created, but failed to assign share " |
| 532 |
"policy {1}. Error: {2}".format( |
| 533 |
module.params["name"], |
| 534 |
module.params["share_policy"], |
| 535 |
res.errors[0].message, |
| 536 |
) |
| 537 |
) |
| 538 |
if CA_API_VERSION in api_version: |
| 539 |
ca_attr = FileSystemPatch( |
| 540 |
smb=Smb( |
| 541 |
continuous_availability_enabled=module.params[ |
| 542 |
"continuous_availability" |
| 543 |
] |
| 544 |
) |
| 545 |
) |
| 546 |
if CONTEXT_API_VERSION in api_version: |
| 547 |
res = blade.patch_file_systems( |
| 548 |
names=[module.params["name"]], |
| 549 |
file_system=ca_attr, |
| 550 |
context_names=[module.params["context"]], |
| 551 |
) |
| 552 |
else: |
| 553 |
res = blade.patch_file_systems( |
| 554 |
names=[module.params["name"]], file_system=ca_attr |
| 555 |
) |
| 556 |
if res.status_code != 200: |
| 557 |
module.fail_json( |
| 558 |
msg="Filesystem {0} created, but failed to set continuous availability" |
| 559 |
"Error: {1}".format( |
| 560 |
module.params["name"], |
| 561 |
res.errors[0].message, |
| 562 |
) |
| 563 |
) |
| 564 |
if GOWNER_API_VERSION in api_version and module.params["group_ownership"]: |
| 565 |
go_attr = FileSystemPatch( |
| 566 |
group_ownership=module.params["group_ownership"] |
| 567 |
) |
| 568 |
if CONTEXT_API_VERSION in api_version: |
| 569 |
res = blade.patch_file_systems( |
| 570 |
names=[module.params["name"]], |
| 571 |
file_system=go_attr, |
| 572 |
context_names=[module.params["context"]], |
| 573 |
) |
| 574 |
else: |
| 575 |
res = blade.patch_file_systems( |
| 576 |
names=[module.params["name"]], file_system=go_attr |
| 577 |
) |
| 578 |
if res.status_code != 200: |
| 579 |
module.fail_json( |
| 580 |
msg="Filesystem {0} created, but failed to set group ownership" |
| 581 |
"Error: {1}".format( |
| 582 |
module.params["name"], |
| 583 |
res.errors[0].message, |
| 584 |
) |
| 585 |
) |
| 586 |
if CONTEXT_API_VERSION in api_version and module.params["storage_class"]: |
| 587 |
res = blade.patch_file_systems( |
| 588 |
names=[module.params["name"]], |
| 589 |
file_system=FileSystemPatch( |
| 590 |
storage_class=StorageClassInfo( |
| 591 |
name=module.params["storage_class"] |
| 592 |
) |
| 593 |
), |
| 594 |
cancel_in_progress_storage_class_transition=False, |
| 595 |
context_names=[module.params["context"]], |
| 596 |
) |
| 597 |
|
| 598 |
module.exit_json(changed=changed) |
| 599 |
|
| 600 |
|
| 601 |
def modify_fs(module, blade): |
| 602 |
"""Modify Filesystem""" |
| 603 |
changed = False |
| 604 |
change_client = False |
| 605 |
change_export = False |
| 606 |
change_share = False |
| 607 |
change_ca = False |
| 608 |
change_go = False |
| 609 |
change_sc = False |
| 610 |
mod_fs = False |
| 611 |
api_version = list(blade.get_versions().items) |
| 612 |
if module.params["policy"] and module.params["policy_state"] == "present": |
| 613 |
if CONTEXT_API_VERSION in api_version: |
| 614 |
res = blade.get_policies( |
| 615 |
names=[module.params["policy"]], |
| 616 |
context_names=[module.params["context"]], |
| 617 |
) |
| 618 |
else: |
| 619 |
res = blade.get_policies(names=[module.params["policy"]]) |
| 620 |
if res.status_code != 200: |
| 621 |
module.fail_json( |
| 622 |
msg="Policy {0} doesn't exist.".format(module.params["policy"]) |
| 623 |
) |
| 624 |
if CONTEXT_API_VERSION in api_version: |
| 625 |
res = blade.get_policies_file_systems( |
| 626 |
policy_names=[module.params["policy"]], |
| 627 |
member_names=[module.params["name"]], |
| 628 |
context_names=[module.params["context"]], |
| 629 |
) |
| 630 |
else: |
| 631 |
res = blade.get_policies_file_systems( |
| 632 |
policy_names=[module.params["policy"]], |
| 633 |
member_names=[module.params["name"]], |
| 634 |
) |
| 635 |
if res.status_code != 200: |
| 636 |
if CONTEXT_API_VERSION in api_version: |
| 637 |
res = blade.patch_policies_file_systems( |
| 638 |
policy_names=[module.params["policy"]], |
| 639 |
member_names=[module.params["name"]], |
| 640 |
context_names=[module.params["context"]], |
| 641 |
) |
| 642 |
else: |
| 643 |
res = blade.patch_policies_file_systems( |
| 644 |
policy_names=[module.params["policy"]], |
| 645 |
member_names=[module.params["name"]], |
| 646 |
) |
| 647 |
mod_fs = True |
| 648 |
if res.status_code != 200: |
| 649 |
module.fail_json( |
| 650 |
msg="Failed to add filesystem {0} to policy {1}. Error: {2}".format( |
| 651 |
module.params["name"], |
| 652 |
module.params["policy"], |
| 653 |
res.errors[0].message, |
| 654 |
) |
| 655 |
) |
| 656 |
if module.params["policy"] and module.params["policy_state"] == "absent": |
| 657 |
if CONTEXT_API_VERSION in api_version: |
| 658 |
res = blade.get_policies( |
| 659 |
names=[module.params["policy"]], |
| 660 |
context_names=[module.params["context"]], |
| 661 |
) |
| 662 |
else: |
| 663 |
res = blade.get_policies(names=[module.params["policy"]]) |
| 664 |
if res.status_code == 200: |
| 665 |
if CONTEXT_API_VERSION in api_version: |
| 666 |
res = blade.get_policies_file_systems( |
| 667 |
policy_names=[module.params["policy"]], |
| 668 |
member_names=[module.params["name"]], |
| 669 |
context_names=[module.params["context"]], |
| 670 |
) |
| 671 |
else: |
| 672 |
res = blade.get_policies_file_systems( |
| 673 |
policy_names=[module.params["policy"]], |
| 674 |
member_names=[module.params["name"]], |
| 675 |
) |
| 676 |
if res.status_code == 200: |
| 677 |
if CONTEXT_API_VERSION in api_version: |
| 678 |
res = blade.delete_policies_file_systems( |
| 679 |
policy_names=[module.params["policy"]], |
| 680 |
member_names=[module.params["name"]], |
| 681 |
context_names=[module.params["context"]], |
| 682 |
) |
| 683 |
else: |
| 684 |
res = blade.delete_policies_file_systems( |
| 685 |
policy_names=[module.params["policy"]], |
| 686 |
member_names=[module.params["name"]], |
| 687 |
) |
| 688 |
mod_fs = True |
| 689 |
if res.status_code != 200: |
| 690 |
module.fail_json( |
| 691 |
msg="Failed to remove filesystem {0} from policy {1}. Error: {2}".format( |
| 692 |
module.params["name"], |
| 693 |
module.params["policy"], |
| 694 |
res.errors[0].message, |
| 695 |
) |
| 696 |
) |
| 697 |
if module.params["user_quota"]: |
| 698 |
user_quota = human_to_bytes(module.params["user_quota"]) |
| 699 |
if module.params["group_quota"]: |
| 700 |
group_quota = human_to_bytes(module.params["group_quota"]) |
| 701 |
fsys = get_fs(module, blade) |
| 702 |
new_fsys = { |
| 703 |
"destroyed": fsys.destroyed, |
| 704 |
"provisioned": fsys.provisioned, |
| 705 |
"nfsv3": fsys.nfs.v3_enabled, |
| 706 |
"nfsv4": fsys.nfs.v4_1_enabled, |
| 707 |
"nfs_rules": fsys.nfs.rules, |
| 708 |
"default_user_quota": fsys.default_user_quota, |
| 709 |
"default_group_quota": fsys.default_group_quota, |
| 710 |
"group_ownership": fsys.group_ownership, |
| 711 |
"smb": fsys.smb.enabled, |
| 712 |
"http": fsys.http.enabled, |
| 713 |
"snapshot": fsys.snapshot_directory_enabled, |
| 714 |
"fastremove": fsys.fast_remove_directory_enabled, |
| 715 |
"hardlimit": fsys.hard_limit_enabled, |
| 716 |
"safeguard_acls": fsys.multi_protocol.safeguard_acls, |
| 717 |
"acs": fsys.multi_protocol.access_control_style, |
| 718 |
"writable": fsys.writable, |
| 719 |
"promotion_status": fsys.promotion_status, |
| 720 |
"requested_promotion_state": fsys.requested_promotion_state, |
| 721 |
"storage_class": getattr(getattr(fsys, "storage_class", None), "name", None), |
| 722 |
} |
| 723 |
if fsys.destroyed: |
| 724 |
new_fsys["destroyed"] = False |
| 725 |
mod_fs = True |
| 726 |
if module.params["size"]: |
| 727 |
if human_to_bytes(module.params["size"]) != fsys.provisioned: |
| 728 |
new_fsys["provisioned"] = human_to_bytes(module.params["size"]) |
| 729 |
mod_fs = True |
| 730 |
if module.params["nfsv3"] != fsys.nfs.v3_enabled: |
| 731 |
new_fsys["nfsv3"] = module.params["nfsv3"] |
| 732 |
mod_fs = True |
| 733 |
if module.params["nfsv4"] != fsys.nfs.v4_1_enabled: |
| 734 |
new_fsys["nfsv4"] = module.params["nfsv4"] |
| 735 |
mod_fs = True |
| 736 |
if module.params["nfs_rules"] is not None: |
| 737 |
if sorted(fsys.nfs.rules) != sorted(module.params["nfs_rules"]): |
| 738 |
new_fsys["nfs_rules"] = module.params["nfs_rules"] |
| 739 |
mod_fs = True |
| 740 |
if module.params["user_quota"] and user_quota != fsys.default_user_quota: |
| 741 |
new_fsys["default_user_quota"] = user_quota |
| 742 |
mod_fs = True |
| 743 |
if module.params["group_quota"] and group_quota != fsys.default_group_quota: |
| 744 |
new_fsys["default_group_quota"] = group_quota |
| 745 |
mod_fs = True |
| 746 |
if module.params["http"] and not fsys.http.enabled: |
| 747 |
new_fsys["http"] = module.params["http"] |
| 748 |
mod_fs = True |
| 749 |
if module.params["snapshot"] and not fsys.snapshot_directory_enabled: |
| 750 |
new_fsys["snapshot_directory_enabled"] = module.params["snapshot"] |
| 751 |
mod_fs = True |
| 752 |
if module.params["fastremove"] and not fsys.fast_remove_directory_enabled: |
| 753 |
new_fsys["fast_remove_directory_enabled"] = module.params["fastremove"] |
| 754 |
mod_fs = True |
| 755 |
if module.params["hard_limit"] and not fsys.hard_limit_enabled: |
| 756 |
new_fsys["hard_limit_enabled"] = module.params["hard_limit"] |
| 757 |
mod_fs = True |
| 758 |
if module.params["safeguard_acls"] and not fsys.multi_protocol.safeguard_acls: |
| 759 |
new_fsys["safeguard_acls"] = module.params["safeguard_acls"] |
| 760 |
mod_fs = True |
| 761 |
if module.params["access_control"] != fsys.multi_protocol.access_control_style: |
| 762 |
new_fsys["acs"] = module.params["access_control"] |
| 763 |
mod_fs = True |
| 764 |
if module.params["writable"] is not None: |
| 765 |
if not module.params["writable"] and fsys.writable: |
| 766 |
new_fsys["writable"] = module.params["writable"] |
| 767 |
mod_fs = True |
| 768 |
if ( |
| 769 |
module.params["writable"] |
| 770 |
and not fsys.writable |
| 771 |
and fsys.promotion_status == "promoted" |
| 772 |
): |
| 773 |
new_fsys["writable"] = module.params["writable"] |
| 774 |
mod_fs = True |
| 775 |
if module.params["promote"] is not None: |
| 776 |
if module.params["promote"] and fsys.promotion_status != "promoted": |
| 777 |
new_fsys["requested_promotion_state"] = "promoted" |
| 778 |
mod_fs = True |
| 779 |
if not module.params["promote"] and fsys.promotion_status == "promoted": |
| 780 |
|
| 781 |
if CONTEXT_API_VERSION in api_version: |
| 782 |
res = blade.get_file_system_replica_links( |
| 783 |
local_file_system_names=[module.params["name"]], |
| 784 |
context_names=[module.params["context"]], |
| 785 |
) |
| 786 |
else: |
| 787 |
res = blade.get_file_system_replica_links( |
| 788 |
local_file_system_names=[module.params["name"]] |
| 789 |
) |
| 790 |
if res.status_code != 200: |
| 791 |
module.fail_json( |
| 792 |
msg="Filesystem {0} not demoted. Not in a replica-link".format( |
| 793 |
module.params["name"] |
| 794 |
) |
| 795 |
) |
| 796 |
new_fsys["requested_promotion_state"] = "demoted" |
| 797 |
mod_fs = True |
| 798 |
if mod_fs: |
| 799 |
changed = True |
| 800 |
if not module.check_mode: |
| 801 |
if CONTEXT_API_VERSION in api_version: |
| 802 |
if new_fsys["destroyed"] != fsys.destroyed: |
| 803 |
delres = blade.patch_file_systems( |
| 804 |
names=module.params["name"], |
| 805 |
context_names=[module.params["context"]], |
| 806 |
file_system=FileSystemPatch(destroyed=new_fsys["destroyed"]), |
| 807 |
) |
| 808 |
if delres.status_code != 200: |
| 809 |
module.fail_json( |
| 810 |
msg="Failed to update filesystem {0} deleted status. Error {1}".format( |
| 811 |
module.params["name"], res.errors[0].message |
| 812 |
) |
| 813 |
) |
| 814 |
res = blade.patch_file_systems( |
| 815 |
names=module.params["name"], |
| 816 |
context_names=[module.params["context"]], |
| 817 |
file_system=FileSystemPatch( |
| 818 |
default_group_quota=new_fsys["default_group_quota"], |
| 819 |
default_user_quota=new_fsys["default_user_quota"], |
| 820 |
fast_remove_directory_enabled=new_fsys["fastremove"], |
| 821 |
hard_limit_enabled=new_fsys["hardlimit"], |
| 822 |
http=Http(enabled=new_fsys["http"]), |
| 823 |
multi_protocol=MultiProtocol( |
| 824 |
access_control_style=new_fsys["acs"], |
| 825 |
safeguard_acls=new_fsys["safeguard_acls"], |
| 826 |
), |
| 827 |
nfs=NfsPatch( |
| 828 |
rules=new_fsys["nfs_rules"], |
| 829 |
v3_enabled=new_fsys["nfsv3"], |
| 830 |
v4_1_enabled=new_fsys["nfsv4"], |
| 831 |
), |
| 832 |
provisioned=new_fsys["provisioned"], |
| 833 |
requested_promotion_state=new_fsys["requested_promotion_state"], |
| 834 |
smb=Smb(enabled=new_fsys["smb"]), |
| 835 |
writable=new_fsys["writable"], |
| 836 |
), |
| 837 |
discard_non_snapshotted_data=module.params["discard_snaps"], |
| 838 |
ignore_usage=module.params["ignore_usage"], |
| 839 |
) |
| 840 |
else: |
| 841 |
if new_fsys["destroyed"] != fsys.destroyed: |
| 842 |
delres = blade.patch_file_systems( |
| 843 |
names=module.params["name"], |
| 844 |
file_system=FileSystemPatch(destroyed=new_fsys["destroyed"]), |
| 845 |
) |
| 846 |
if delres.status_code != 200: |
| 847 |
module.fail_json( |
| 848 |
msg="Failed to update filesystem {0} deleted status. Error {1}".format( |
| 849 |
module.params["name"], res.errors[0].message |
| 850 |
) |
| 851 |
) |
| 852 |
res = blade.patch_file_systems( |
| 853 |
names=module.params["name"], |
| 854 |
file_system=FileSystemPatch( |
| 855 |
default_group_quota=new_fsys["default_group_quota"], |
| 856 |
default_user_quota=new_fsys["default_user_quota"], |
| 857 |
fast_remove_directory_enabled=new_fsys["fastremove"], |
| 858 |
hard_limit_enabled=new_fsys["hardlimit"], |
| 859 |
http=Http(enabled=new_fsys["http"]), |
| 860 |
multi_protocol=MultiProtocol( |
| 861 |
access_control_style=new_fsys["acs"], |
| 862 |
safeguard_acls=new_fsys["safeguard_acls"], |
| 863 |
), |
| 864 |
nfs=NfsPatch( |
| 865 |
rules=new_fsys["nfs_rules"], |
| 866 |
v3_enabled=new_fsys["nfsv3"], |
| 867 |
v4_1_enabled=new_fsys["nfsv4"], |
| 868 |
), |
| 869 |
provisioned=new_fsys["provisioned"], |
| 870 |
requested_promotion_state=new_fsys["requested_promotion_state"], |
| 871 |
smb=Smb(enabled=new_fsys["smb"]), |
| 872 |
writable=new_fsys["writable"], |
| 873 |
), |
| 874 |
discard_non_snapshotted_data=module.params["discard_snaps"], |
| 875 |
ignore_usage=module.params["ignore_usage"], |
| 876 |
) |
| 877 |
if res.status_code != 200: |
| 878 |
module.fail_json( |
| 879 |
msg="Failed to update filesystem {0}. Error {1}".format( |
| 880 |
module.params["name"], res.errors[0].message |
| 881 |
) |
| 882 |
) |
| 883 |
if CONTEXT_API_VERSION in api_version: |
| 884 |
current_fs = list( |
| 885 |
blade.get_file_systems( |
| 886 |
context_names=[module.params["context"]], |
| 887 |
filter="name='" + module.params["name"] + "'", |
| 888 |
).items |
| 889 |
)[0] |
| 890 |
else: |
| 891 |
current_fs = list( |
| 892 |
blade.get_file_systems(filter="name='" + module.params["name"] + "'").items |
| 893 |
)[0] |
| 894 |
if EXPORT_POLICY_API_VERSION in api_version and module.params["export_policy"]: |
| 895 |
change_export = False |
| 896 |
if ( |
| 897 |
current_fs.nfs.export_policy.name |
| 898 |
and current_fs.nfs.export_policy.name != module.params["export_policy"] |
| 899 |
): |
| 900 |
change_export = True |
| 901 |
if not current_fs.nfs.export_policy.name and module.params["export_policy"]: |
| 902 |
change_export = True |
| 903 |
if change_export and not module.check_mode: |
| 904 |
export_attr = FileSystemPatch( |
| 905 |
nfs=NfsPatch( |
| 906 |
export_policy=Reference(name=module.params["export_policy"]) |
| 907 |
) |
| 908 |
) |
| 909 |
if CONTEXT_API_VERSION in api_version: |
| 910 |
res = blade.patch_file_systems( |
| 911 |
names=[module.params["name"]], |
| 912 |
file_system=export_attr, |
| 913 |
context_names=[module.params["context"]], |
| 914 |
) |
| 915 |
else: |
| 916 |
res = blade.patch_file_systems( |
| 917 |
names=[module.params["name"]], file_system=export_attr |
| 918 |
) |
| 919 |
if res.status_code != 200: |
| 920 |
module.fail_json( |
| 921 |
msg="Failed to modify export policy {1} for " |
| 922 |
"filesystem {0}. Error: {2}".format( |
| 923 |
module.params["name"], |
| 924 |
module.params["export_policy"], |
| 925 |
res.errors[0].message, |
| 926 |
) |
| 927 |
) |
| 928 |
if SMB_POLICY_API_VERSION in api_version and module.params["client_policy"]: |
| 929 |
if ( |
| 930 |
current_fs.smb.client_policy.name |
| 931 |
and current_fs.smb.client_policy.name != module.params["client_policy"] |
| 932 |
): |
| 933 |
change_client = True |
| 934 |
if not current_fs.smb.client_policy.name and module.params["client_policy"]: |
| 935 |
change_client = True |
| 936 |
if change_client and not module.check_mode: |
| 937 |
client_attr = FileSystemPatch( |
| 938 |
smb=Smb(client_policy=Reference(name=module.params["client_policy"])) |
| 939 |
) |
| 940 |
if CONTEXT_API_VERSION in api_version: |
| 941 |
res = blade.patch_file_systems( |
| 942 |
names=[module.params["name"]], |
| 943 |
file_system=client_attr, |
| 944 |
context_names=[module.params["context"]], |
| 945 |
) |
| 946 |
else: |
| 947 |
res = blade.patch_file_systems( |
| 948 |
names=[module.params["name"]], file_system=client_attr |
| 949 |
) |
| 950 |
if res.status_code != 200: |
| 951 |
module.fail_json( |
| 952 |
msg="Failed to modify client policy {1} for " |
| 953 |
"filesystem {0}. Error: {2}".format( |
| 954 |
module.params["name"], |
| 955 |
module.params["client_policy"], |
| 956 |
res.errors[0].message, |
| 957 |
) |
| 958 |
) |
| 959 |
if SMB_POLICY_API_VERSION in api_version and module.params["share_policy"]: |
| 960 |
if ( |
| 961 |
current_fs.smb.share_policy.name |
| 962 |
and current_fs.smb.share_policy.name != module.params["share_policy"] |
| 963 |
): |
| 964 |
change_share = True |
| 965 |
if not current_fs.smb.share_policy.name and module.params["share_policy"]: |
| 966 |
change_share = True |
| 967 |
if change_share and not module.check_mode: |
| 968 |
share_attr = FileSystemPatch( |
| 969 |
smb=Smb(share_policy=Reference(name=module.params["share_policy"])) |
| 970 |
) |
| 971 |
if CONTEXT_API_VERSION in api_version: |
| 972 |
res = blade.patch_file_systems( |
| 973 |
names=[module.params["name"]], |
| 974 |
file_system=share_attr, |
| 975 |
context_names=[module.params["context"]], |
| 976 |
) |
| 977 |
else: |
| 978 |
res = blade.patch_file_systems( |
| 979 |
names=[module.params["name"]], file_system=share_attr |
| 980 |
) |
| 981 |
if res.status_code != 200: |
| 982 |
module.fail_json( |
| 983 |
msg="Failed to modify share policy {1} for " |
| 984 |
"filesystem {0}. Error: {2}".format( |
| 985 |
module.params["name"], |
| 986 |
module.params["share_policy"], |
| 987 |
res.errors[0].message, |
| 988 |
) |
| 989 |
) |
| 990 |
if CA_API_VERSION in api_version: |
| 991 |
if ( |
| 992 |
module.params["continuous_availability"] |
| 993 |
!= current_fs.smb.continuous_availability_enabled |
| 994 |
): |
| 995 |
change_ca = True |
| 996 |
if not module.check_mode and change_ca: |
| 997 |
ca_attr = FileSystemPatch( |
| 998 |
smb=Smb( |
| 999 |
continuous_availability_enabled=module.params[ |
| 1000 |
"continuous_availability" |
| 1001 |
] |
| 1002 |
) |
| 1003 |
) |
| 1004 |
if CONTEXT_API_VERSION in api_version: |
| 1005 |
res = blade.patch_file_systems( |
| 1006 |
names=[module.params["name"]], |
| 1007 |
file_system=ca_attr, |
| 1008 |
context_names=[module.params["context"]], |
| 1009 |
) |
| 1010 |
else: |
| 1011 |
res = blade.patch_file_systems( |
| 1012 |
names=[module.params["name"]], file_system=ca_attr |
| 1013 |
) |
| 1014 |
if res.status_code != 200: |
| 1015 |
module.fail_json( |
| 1016 |
msg="Failed to modify continuous availability for " |
| 1017 |
"filesystem {0}. Error: {1}".format( |
| 1018 |
module.params["name"], |
| 1019 |
res.errors[0].message, |
| 1020 |
) |
| 1021 |
) |
| 1022 |
if GOWNER_API_VERSION in api_version: |
| 1023 |
if module.params["group_ownership"] != current_fs.group_ownership: |
| 1024 |
change_go = True |
| 1025 |
if not module.check_mode and change_go: |
| 1026 |
go_attr = FileSystemPatch(group_ownership=module.params["group_ownership"]) |
| 1027 |
if CONTEXT_API_VERSION in api_version: |
| 1028 |
res = blade.patch_file_systems( |
| 1029 |
names=[module.params["name"]], |
| 1030 |
file_system=go_attr, |
| 1031 |
context_names=[module.params["context"]], |
| 1032 |
) |
| 1033 |
else: |
| 1034 |
res = blade.patch_file_systems( |
| 1035 |
names=[module.params["name"]], file_system=go_attr |
| 1036 |
) |
| 1037 |
if res.status_code != 200: |
| 1038 |
module.fail_json( |
| 1039 |
msg="Failed to modify group ownership for " |
| 1040 |
"filesystem {0}. Error: {1}".format( |
| 1041 |
module.params["name"], |
| 1042 |
res.errors[0].message, |
| 1043 |
) |
| 1044 |
) |
| 1045 |
if CONTEXT_API_VERSION in api_version and module.params["storage_class"]: |
| 1046 |
if module.params["storage_class"] != current_fs.storage_class: |
| 1047 |
change_sc = True |
| 1048 |
res = blade.patch_file_systems( |
| 1049 |
names=[module.params["name"]], |
| 1050 |
file_system=FileSystemPatch( |
| 1051 |
storage_class=StorageClassInfo(name=module.params["storage_class"]) |
| 1052 |
), |
| 1053 |
cancel_in_progress_storage_class_transition=module.params[ |
| 1054 |
"cancel_in_progress" |
| 1055 |
], |
| 1056 |
context_names=[module.params["context"]], |
| 1057 |
) |
| 1058 |
|
| 1059 |
module.exit_json( |
| 1060 |
changed=( |
| 1061 |
changed |
| 1062 |
or change_export |
| 1063 |
or change_share |
| 1064 |
or change_ca |
| 1065 |
or change_go |
| 1066 |
or change_sc |
| 1067 |
or change_client |
| 1068 |
) |
| 1069 |
) |
| 1070 |
|
| 1071 |
|
| 1072 |
def _delete_fs(module, blade): |
| 1073 |
"""In module Delete Filesystem""" |
| 1074 |
res = blade.patch_file_systems( |
| 1075 |
name=module.params["name"], |
| 1076 |
file_system=FileSystemPatch( |
| 1077 |
nfs=NfsPatch(v3_enabled=False, v4_1_enabled=False), |
| 1078 |
smb=Smb(enabled=False), |
| 1079 |
http=Http(enabled=False), |
| 1080 |
multi_protocol=MultiProtocol(access_control_style="shared"), |
| 1081 |
destroyed=True, |
| 1082 |
), |
| 1083 |
) |
| 1084 |
if res.status_code != 200: |
| 1085 |
module.fail_json( |
| 1086 |
msg="Failed to delete filesystem {0}. Error: {1}".format( |
| 1087 |
module.params["name"], res.errors[0].message |
| 1088 |
) |
| 1089 |
) |
| 1090 |
|
| 1091 |
res = blade.delete_file_systems(name=module.params["name"]) |
| 1092 |
if res.status_code != 200: |
| 1093 |
module.fail_json( |
| 1094 |
msg="Failed to eradicate deleted filesystem {0}. Error: {1}".format( |
| 1095 |
module.params["name"], res.errors[0].message |
| 1096 |
) |
| 1097 |
) |
| 1098 |
|
| 1099 |
|
| 1100 |
def delete_fs(module, blade): |
| 1101 |
"""Delete Filesystem""" |
| 1102 |
changed = True |
| 1103 |
if not module.check_mode: |
| 1104 |
res = blade.patch_file_systems( |
| 1105 |
names=[module.params["name"]], |
| 1106 |
file_system=FileSystemPatch( |
| 1107 |
nfs=NfsPatch(v3_enabled=False, v4_1_enabled=False), |
| 1108 |
smb=Smb(enabled=False), |
| 1109 |
http=Http(enabled=False), |
| 1110 |
destroyed=True, |
| 1111 |
), |
| 1112 |
delete_link_on_eradication=module.params["delete_link"], |
| 1113 |
) |
| 1114 |
if res.status_code != 200: |
| 1115 |
module.fail_json( |
| 1116 |
msg="Failed to delete filesystem {0}. Error: {1}".format( |
| 1117 |
module.params["name"], res.errors[0].message |
| 1118 |
) |
| 1119 |
) |
| 1120 |
if module.params["eradicate"]: |
| 1121 |
res = blade.delete_file_systems(names=[module.params["name"]]) |
| 1122 |
if res.status_code != 200: |
| 1123 |
module.fail_json( |
| 1124 |
msg="Failed to eradicate filesystem {0}. Error: {1}".format( |
| 1125 |
module.params["name"], res.errors[0].message |
| 1126 |
) |
| 1127 |
) |
| 1128 |
module.exit_json(changed=changed) |
| 1129 |
|
| 1130 |
|
| 1131 |
def eradicate_fs(module, blade): |
| 1132 |
"""Eradicate Filesystem""" |
| 1133 |
changed = True |
| 1134 |
if not module.check_mode: |
| 1135 |
res = blade.delete_file_systems(names=[module.params["name"]]) |
| 1136 |
if res.status_code != 200: |
| 1137 |
module.fail_json( |
| 1138 |
msg="Failed to eradicate filesystem {0}. Error: {1}".format( |
| 1139 |
module.params["name"], res.errors[0].message |
| 1140 |
) |
| 1141 |
) |
| 1142 |
module.exit_json(changed=changed) |
| 1143 |
|
| 1144 |
|
| 1145 |
def main(): |
| 1146 |
argument_spec = purefb_argument_spec() |
| 1147 |
argument_spec.update( |
| 1148 |
dict( |
| 1149 |
name=dict(type="str", required=True), |
| 1150 |
eradicate=dict(default="false", type="bool"), |
| 1151 |
nfsv3=dict(default="true", type="bool"), |
| 1152 |
nfsv4=dict(default="true", type="bool"), |
| 1153 |
nfs_rules=dict(type="str"), |
| 1154 |
smb=dict(default="false", type="bool"), |
| 1155 |
http=dict(default="false", type="bool"), |
| 1156 |
snapshot=dict(default="false", type="bool"), |
| 1157 |
writable=dict(type="bool"), |
| 1158 |
promote=dict(type="bool"), |
| 1159 |
fastremove=dict(default="false", type="bool"), |
| 1160 |
hard_limit=dict(default="false", type="bool"), |
| 1161 |
user_quota=dict(type="str"), |
| 1162 |
policy=dict(type="str"), |
| 1163 |
group_quota=dict(type="str"), |
| 1164 |
smb_aclmode=dict( |
| 1165 |
type="str", default="shared", choices=["shared", "native"] |
| 1166 |
), |
| 1167 |
group_ownership=dict( |
| 1168 |
choices=["creator", "parent-directory"], default="creator" |
| 1169 |
), |
| 1170 |
policy_state=dict(default="present", choices=["present", "absent"]), |
| 1171 |
state=dict(default="present", choices=["present", "absent"]), |
| 1172 |
delete_link=dict(default=False, type="bool"), |
| 1173 |
discard_snaps=dict(default=False, type="bool"), |
| 1174 |
safeguard_acls=dict(default=True, type="bool"), |
| 1175 |
access_control=dict( |
| 1176 |
type="str", |
| 1177 |
default="shared", |
| 1178 |
choices=["nfs", "smb", "shared", "independent", "mode-bits"], |
| 1179 |
), |
| 1180 |
size=dict(type="str"), |
| 1181 |
export_policy=dict(type="str"), |
| 1182 |
share_policy=dict(type="str"), |
| 1183 |
client_policy=dict(type="str"), |
| 1184 |
continuous_availability=dict(type="bool", default="true"), |
| 1185 |
ignore_usage=dict(type="bool", default=False), |
| 1186 |
cancel_in_progress=dict(type="bool", default=False), |
| 1187 |
context=dict(type="str", default=""), |
| 1188 |
storage_class=dict(type="str"), |
| 1189 |
) |
| 1190 |
) |
| 1191 |
|
| 1192 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 1193 |
|
| 1194 |
state = module.params["state"] |
| 1195 |
blade = get_system(module) |
| 1196 |
fsys = get_fs(module, blade) |
| 1197 |
|
| 1198 |
if module.params["eradicate"] and state == "present": |
| 1199 |
module.warn("Eradicate flag ignored without state=absent") |
| 1200 |
|
| 1201 |
if module.params["smb_aclmode"] == "native": |
| 1202 |
module.fail_json( |
| 1203 |
msg="Native SMB ACL mode is no longer supported. " |
| 1204 |
"Use the access_control parameter." |
| 1205 |
) |
| 1206 |
if state == "present" and not fsys: |
| 1207 |
create_fs(module, blade) |
| 1208 |
elif state == "present" and fsys: |
| 1209 |
modify_fs(module, blade) |
| 1210 |
elif state == "absent" and fsys and not fsys.destroyed: |
| 1211 |
delete_fs(module, blade) |
| 1212 |
elif state == "absent" and fsys and fsys.destroyed and module.params["eradicate"]: |
| 1213 |
eradicate_fs(module, blade) |
| 1214 |
elif state == "absent" and not fsys: |
| 1215 |
module.exit_json(changed=False) |
| 1216 |
module.exit_json(changed=False) |
| 1217 |
|
| 1218 |
|
| 1219 |
if __name__ == "__main__": |
| 1220 |
main() |