Init: mediaserver

This commit is contained in:
2023-02-08 12:13:28 +01:00
parent 848bc9739c
commit f7c23d4ba9
31914 changed files with 6175775 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
================================
Purestorage.Fusion Release Notes
================================
.. contents:: Topics
v1.3.0
======
Bugfixes
--------
- fusion_pg - Add missing 'region' parameter
- fusion_tn - Add missing 'region' parameter
v1.2.0
======
Minor Changes
-------------
- fusion_info - Added API Client information
Bugfixes
--------
- fusion_info - Fixed issue with storage endpoint dict formatting
v1.1.1
======
v1.1.0
======
Minor Changes
-------------
- fusion_az - Add delete AZ option
- fusion_az - Allow any region to be specificed instead of limited to a known list
- fusion_pp - Add delete PP option
- fusion_sc - Add delete SC option
- fusion_ss - Add delete SS option
Bugfixes
--------
- Allow correct use of environmental variables for App ID and private file file
New Modules
-----------
- purestorage.fusion.fusion_region - Manage Regions in Pure Storage Fusion
v1.0.3
======
v1.0.2
======
v1.0.1
======
v1.0.0
======
New Modules
-----------
- purestorage.fusion.fusion_api_client - Manage API clients in Pure Storage Fusion
- purestorage.fusion.fusion_array - Manage arrays in Pure Storage Fusion
- purestorage.fusion.fusion_az - Create Availability Zones in Pure Storage Fusion
- purestorage.fusion.fusion_hap - Manage host access policies in Pure Storage Fusion
- purestorage.fusion.fusion_hw - Create hardware types in Pure Storage Fusion
- purestorage.fusion.fusion_info - Collect information from Pure Fusion
- purestorage.fusion.fusion_nig - Manage Network Interface Groups in Pure Storage Fusion
- purestorage.fusion.fusion_pg - Manage placement groups in Pure Storage Fusion
- purestorage.fusion.fusion_pp - Manage protection policies in Pure Storage Fusion
- purestorage.fusion.fusion_ra - Manage role assignments in Pure Storage Fusion
- purestorage.fusion.fusion_sc - Manage storage classes in Pure Storage Fusion
- purestorage.fusion.fusion_ss - Manage storage services in Pure Storage Fusion
- purestorage.fusion.fusion_tenant - Manage tenants in Pure Storage Fusion
- purestorage.fusion.fusion_tn - Manage tenant networks in Pure Storage Fusion
- purestorage.fusion.fusion_ts - Manage tenant spaces in Pure Storage Fusion
- purestorage.fusion.fusion_volume - Manage volumes in Pure Storage Fusion

View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@@ -0,0 +1,488 @@
{
"files": [
{
"name": ".",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "roles",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "roles/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "tests",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "tests/sanity",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "tests/sanity/ignore-2.13.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "19d3e95154438bfa5680971ee3e9c191421b3c074558663b034701ba8c2be975",
"format": 1
},
{
"name": "tests/sanity/ignore-2.14.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "19d3e95154438bfa5680971ee3e9c191421b3c074558663b034701ba8c2be975",
"format": 1
},
{
"name": "tests/sanity/ignore-2.11.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "19d3e95154438bfa5680971ee3e9c191421b3c074558663b034701ba8c2be975",
"format": 1
},
{
"name": "tests/sanity/ignore-2.12.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "19d3e95154438bfa5680971ee3e9c191421b3c074558663b034701ba8c2be975",
"format": 1
},
{
"name": "tests/sanity/ignore-2.15.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "19d3e95154438bfa5680971ee3e9c191421b3c074558663b034701ba8c2be975",
"format": 1
},
{
"name": ".github",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": ".github/CONTRIBUTING.md",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "ed15d670a6a61e8159059927017e7ba7c8bcc94623884ced7beb39ef445c7b95",
"format": 1
},
{
"name": ".github/workflows",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": ".github/workflows/black.yaml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "6e148aa01ada21b2789ad9bf5d3e07d89ebfa3d73165e1896a81a2084d76453f",
"format": 1
},
{
"name": ".github/workflows/stale.yml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "0bdef4889afabcd627fc30711a0809c7468b8c9e64cbcebe1334f794a41e7bd9",
"format": 1
},
{
"name": ".github/workflows/main.yml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "72c94fad53179fbd2cbb2a538612ee3450b1b17ec9bf85ec69ffdab70ed42868",
"format": 1
},
{
"name": ".github/workflows/ansible-lint.yaml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "f6b84d3e503c6fc862d20e87d7728fb584429a3adf1df28cd328dda1d7bef03b",
"format": 1
},
{
"name": ".github/ISSUE_TEMPLATE",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": ".github/ISSUE_TEMPLATE/feature_request.md",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "1f48c52f209a971b8e7eae4120144d28fcf8ee38a7778a7b4d8cf1ab356617d2",
"format": 1
},
{
"name": ".github/ISSUE_TEMPLATE/bug_report.md",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "0c8d64f29fb4536513653bf8c97da30f3340e2041b91c8952db1515d6b23a7b3",
"format": 1
},
{
"name": ".github/pull_request_template.md",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "565ead1b588caaa10cd6f2ed1bb6c809eb2ad93bf75da3a198690cac778432d6",
"format": 1
},
{
"name": "meta",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "meta/runtime.yml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "0043c6e59e95f05ef05493d124296db4876fd30c48a0ee7e256c757523ea4996",
"format": 1
},
{
"name": "README.md",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "f5534b7604d29dcab75d0a50a7c739184228734c27b77f77e3a7144b766df3d3",
"format": 1
},
{
"name": "requirements.txt",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "cbff3e100f867b38f6dd94b4dc8d9f8900270223683514951a8783dcdf67602a",
"format": 1
},
{
"name": "docs",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/roles",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "playbooks/templates",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/templates/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "playbooks/files",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/files/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "playbooks/vars",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/vars/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "playbooks/tasks",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "playbooks/tasks/.keep",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "CHANGELOG.rst",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "0c3259edb09680274a604d01f918a3bac4c1af757026eeda89c7a775bb35b7d2",
"format": 1
},
{
"name": ".gitignore",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "c6173de459fa5dd8e4b0778f30d2066c09b851c08724e28396ae33fbfb928c67",
"format": 1
},
{
"name": "changelogs",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "changelogs/config.yaml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "1762f9f7012a7e135eacb3e2d2c35bdcb25570cdfc33da7a190fa36edc604aec",
"format": 1
},
{
"name": "changelogs/.plugin-cache.yaml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "d97221997b1831f7ab418d3615e7c9a86f95f20bc2638f1bc8f012d484b64845",
"format": 1
},
{
"name": "changelogs/changelog.yaml",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "1caf37a3fd1baa5a230a17da9010184cf2f556085ce82f50fd6e9a7a75236da4",
"format": 1
},
{
"name": "COPYING.GPLv3",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903",
"format": 1
},
{
"name": "plugins",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "plugins/modules",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "plugins/modules/fusion_region.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "ee063c086a5e1848825f8959fcc0a337a42c582a4849af616b298699edffac86",
"format": 1
},
{
"name": "plugins/modules/fusion_hap.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "8b229266b7c775df5a589c84f658a2a19921a233cceee210cc1620dab91aeba0",
"format": 1
},
{
"name": "plugins/modules/fusion_array.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "a3b1d8758c8740621bf950291b1e538f2117c2dcbdfdf3f954321e933944e36b",
"format": 1
},
{
"name": "plugins/modules/fusion_pp.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "afcea0541fb04563f5598a4446183ecb55538f7b380791ef3d52f45172c870ae",
"format": 1
},
{
"name": "plugins/modules/fusion_ss.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "cdf4e13356749ebb38eff81c72395caceb583c131b13c5b6d0407eb1bd7c842c",
"format": 1
},
{
"name": "plugins/modules/fusion_az.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "fe76374a649589886fba6f2ab1d954a8461cfa704701f679fa07b0a791652dd9",
"format": 1
},
{
"name": "plugins/modules/fusion_hw.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "1dba13410b4499b283ac789f81efcfe12f3e0f74531374894da09dbcd54bcba6",
"format": 1
},
{
"name": "plugins/modules/fusion_pg.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "188e16b907dd3698ea63f2d98912aa8dc7553eed211a4d278f0591804a8ed86e",
"format": 1
},
{
"name": "plugins/modules/fusion_tn.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "79e4ff4e7ee7b3010be4159ad2cd68e50a4d3ccbda9b0d726889bf0789a28667",
"format": 1
},
{
"name": "plugins/modules/fusion_info.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "6283caa7a5cc60ab963a9060d73c008bf36472d4d17eac965e035e73968b411d",
"format": 1
},
{
"name": "plugins/modules/fusion_api_client.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "7aca485ab5974daa341768c8208192955dc346b90f5b49a1a16bc7e78ee5e402",
"format": 1
},
{
"name": "plugins/modules/fusion_ra.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "a8391873a1ab3ee69bf31bd057a785ba50f23f03cfc201a1db2c0ec5a893fb44",
"format": 1
},
{
"name": "plugins/modules/fusion_nig.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "75eb65ccd73302952803f34b4d8f3f63db0314f3207b4dfb414a073ed6087427",
"format": 1
},
{
"name": "plugins/modules/fusion_tenant.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "1b08b4680dd479123edbf187638ce010d0460885466e1ab3c2e7c1758120f4a1",
"format": 1
},
{
"name": "plugins/modules/fusion_volume.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "fa8c0a96643a1e6652134ee618a928f23fcce455f51d1a42e6646425405457d2",
"format": 1
},
{
"name": "plugins/modules/fusion_ts.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "3f0f02e2fa638fc68aa59ded2521de3113985fa756764384028cde46a08665ed",
"format": 1
},
{
"name": "plugins/modules/fusion_sc.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "a5163bbc91cfa46084559690a69fc4442e4f52ab44fc6fcf68e953a6ec60a338",
"format": 1
},
{
"name": "plugins/doc_fragments",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "plugins/doc_fragments/purestorage.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "acb04998503efe6b905ebc1e45d7e123747cca2925673214e9d95077ae5ddab9",
"format": 1
},
{
"name": "plugins/inventory",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "plugins/inventory/__init__.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"format": 1
},
{
"name": "plugins/module_utils",
"ftype": "dir",
"chksum_type": null,
"chksum_sha256": null,
"format": 1
},
{
"name": "plugins/module_utils/fusion.py",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "44abc76a763655f1e5975b11f5b36fac039c8cfe0372eff5954da44e6dd6d783",
"format": 1
}
],
"format": 1
}

View File

@@ -0,0 +1,34 @@
{
"collection_info": {
"namespace": "purestorage",
"name": "fusion",
"version": "1.3.0",
"authors": [
"Pure Storage Ansible Team <pure-ansible-team@purestorage.com>"
],
"readme": "README.md",
"tags": [
"purestorage",
"fusion",
"storage"
],
"description": "Collection of modules to manage Pure Fusion",
"license": [
"GPL-3.0-or-later"
],
"license_file": null,
"dependencies": {},
"repository": "https://github.com/Pure-Storage-Ansible/Fusion-Collection",
"documentation": "https://github.com/Pure-Storage-Ansible/Fusion-Collection",
"homepage": null,
"issues": "https://github.com/Pure-Storage-Ansible/Fusion-Collection/issues"
},
"file_manifest_file": {
"name": "FILES.json",
"ftype": "file",
"chksum_type": "sha256",
"chksum_sha256": "fbf044698e656754c88572f088ff05e8b9bf880adae7e099e3a4084c5b94ba39",
"format": 1
},
"format": 1
}

View File

@@ -0,0 +1,95 @@
<a href="https://github.com/Pure-Storage-Ansible/Fusion-Collection/releases/latest"><img src="https://img.shields.io/github/v/tag/Pure-Storage-Ansible/Fusion-Collection?label=release">
<a href="COPYING.GPLv3"><img src="https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg"></a>
<img src="https://cla-assistant.io/readme/badge/Pure-Storage-Ansible/Fusion-Collection">
<img src="https://github.com/Pure-Storage-Ansible/Fusion-Collection/workflows/Pure%20Storage%20Ansible%20CI/badge.svg">
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
# Pure Storage Fusion Collection
The Pure Storage Fusion collection consists of the latest versions of the Fusion modules.
## Requirements
- ansible-core >= 2.11
- Python >= 3.5
- Authorized API Application ID for Pure Storage Pure1 and associated Private Key
- Refer to Pure Storage documentation on how to create these.
- purefusion >= 1.0.4
- netaddr
- time
## Available Modules
- fusion_api_client: Manage API clients in Pure Storage Fusion
- fusion_array: Manage arrays in Pure Storage Fusion
- fusion_az: Create Availability Zones in Pure Storage Fusion
- fusion_hap: Manage host access policies in Pure Storage Fusion
- fusion_hw: Create hardware types in Pure Storage Fusion
- fusion_info: Collect information from Pure Fusion
- fusion_nig: Manage Network Interface Groups in Pure Storage Fusion
- fusion_pg: Manage placement groups in Pure Storage Fusion
- fusion_pp: Manage protection policies in Pure Storage Fusion
- fusion_ra: Manage role assignments in Pure Storage Fusion
- fusion_region: Manage regions in Pure Storage Fusion
- fusion_sc: Manage storage classes in Pure Storage Fusion
- fusion_ss: Manage storage services in Pure Storage Fusion
- fusion_tenant: Manage tenants in Pure Storage Fusion
- fusion_tn: Manage tenant networks in Pure Storage Fusion
- fusion_ts: Manage tenant spaces in Pure Storage Fusion
- fusion_volume: Manage volumes in Pure Storage Fusion
## Instructions
Ansible must be installed [Install guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
```
sudo pip install ansible
```
Python PureFusion SDK must be installed
```
sudo pip install purefusion
```
Install the Pure Storage Fusion collection on your Ansible management host - [Galaxy link](https://galaxy.ansible.com/purestorage/fusion)
```
ansible-galaxy collection install purestorage.fusion
```
## Example Playbook
```yaml
- hosts: localhost
tasks:
- name: Collect information for Pure Storage fleet in Pure1
purestorage.fusion.fusion_info:
gather_subset: all
app_id: <Pure1 API Application ID>
key_file: <private key file name>
```
## Contributing to this collection
Ongoing development efforts and contributions to this collection are tracked as issues in this repository.
We welcome community contributions to this collection. If you find problems, need an enhancement or need a new module, please open an issue or create a PR against the [Pure Storage Fusion Ansible collection repository](https://github.com/Pure-Storage-Ansible/Fusion-Collection/issues).
Code of Conduct
---------------
This collection follows the Ansible project's
[Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html).
Please read and familiarize yourself with this document.
Releasing, Versioning and Deprecation
-------------------------------------
This collection follows [Semantic Versioning](https://semver.org). More details on versioning can be found [in the Ansible docs](https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html#collection-versions).
New minor and major releases as well as deprecations will follow new releases and deprecations of the Pure Storage Fusion product, its REST API and the corresponding Python SDK, which this project relies on.
## License
[BSD-2-Clause](https://directory.fsf.org/wiki?title=License:FreeBSD)
[GPL-3.0-or-later](https://www.gnu.org/licenses/gpl-3.0.en.html)
## Author
This collection was created in 2022 by [Simon Dodsley](@sdodsley) for, and on behalf of, the [Pure Storage Ansible Team](pure-ansible-team@purestorage.com)

View File

@@ -0,0 +1,102 @@
objects:
role: {}
plugins:
become: {}
cache: {}
callback: {}
cliconf: {}
connection: {}
httpapi: {}
inventory: {}
lookup: {}
module:
fusion_api_client:
description: Manage API clients in Pure Storage Fusion
name: fusion_api_client
namespace: ''
version_added: 1.0.0
fusion_array:
description: Manage arrays in Pure Storage Fusion
name: fusion_array
namespace: ''
version_added: 1.0.0
fusion_az:
description: Create Availability Zones in Pure Storage Fusion
name: fusion_az
namespace: ''
version_added: 1.0.0
fusion_hap:
description: Manage host access policies in Pure Storage Fusion
name: fusion_hap
namespace: ''
version_added: 1.0.0
fusion_hw:
description: Create hardware types in Pure Storage Fusion
name: fusion_hw
namespace: ''
version_added: 1.0.0
fusion_info:
description: Collect information from Pure Fusion
name: fusion_info
namespace: ''
version_added: 1.0.0
fusion_nig:
description: Manage Network Interface Groups in Pure Storage Fusion
name: fusion_nig
namespace: ''
version_added: 1.0.0
fusion_pg:
description: Manage placement groups in Pure Storage Fusion
name: fusion_pg
namespace: ''
version_added: 1.0.0
fusion_pp:
description: Manage protection policies in Pure Storage Fusion
name: fusion_pp
namespace: ''
version_added: 1.0.0
fusion_ra:
description: Manage role assignments in Pure Storage Fusion
name: fusion_ra
namespace: ''
version_added: 1.0.0
fusion_region:
description: Manage Regions in Pure Storage Fusion
name: fusion_region
namespace: ''
version_added: 1.1.0
fusion_sc:
description: Manage storage classes in Pure Storage Fusion
name: fusion_sc
namespace: ''
version_added: 1.0.0
fusion_ss:
description: Manage storage services in Pure Storage Fusion
name: fusion_ss
namespace: ''
version_added: 1.0.0
fusion_tenant:
description: Manage tenants in Pure Storage Fusion
name: fusion_tenant
namespace: ''
version_added: 1.0.0
fusion_tn:
description: Manage tenant networks in Pure Storage Fusion
name: fusion_tn
namespace: ''
version_added: 1.0.0
fusion_ts:
description: Manage tenant spaces in Pure Storage Fusion
name: fusion_ts
namespace: ''
version_added: 1.0.0
fusion_volume:
description: Manage volumes in Pure Storage Fusion
name: fusion_volume
namespace: ''
version_added: 1.0.0
netconf: {}
shell: {}
strategy: {}
vars: {}
version: 1.3.0

View File

@@ -0,0 +1,105 @@
ancestor: null
releases:
1.0.0:
modules:
- description: Manage API clients in Pure Storage Fusion
name: fusion_api_client
namespace: ''
- description: Manage arrays in Pure Storage Fusion
name: fusion_array
namespace: ''
- description: Create Availability Zones in Pure Storage Fusion
name: fusion_az
namespace: ''
- description: Manage host access policies in Pure Storage Fusion
name: fusion_hap
namespace: ''
- description: Create hardware types in Pure Storage Fusion
name: fusion_hw
namespace: ''
- description: Collect information from Pure Fusion
name: fusion_info
namespace: ''
- description: Manage Network Interface Groups in Pure Storage Fusion
name: fusion_nig
namespace: ''
- description: Manage placement groups in Pure Storage Fusion
name: fusion_pg
namespace: ''
- description: Manage protection policies in Pure Storage Fusion
name: fusion_pp
namespace: ''
- description: Manage role assignments in Pure Storage Fusion
name: fusion_ra
namespace: ''
- description: Manage storage classes in Pure Storage Fusion
name: fusion_sc
namespace: ''
- description: Manage storage services in Pure Storage Fusion
name: fusion_ss
namespace: ''
- description: Manage tenants in Pure Storage Fusion
name: fusion_tenant
namespace: ''
- description: Manage tenant networks in Pure Storage Fusion
name: fusion_tn
namespace: ''
- description: Manage tenant spaces in Pure Storage Fusion
name: fusion_ts
namespace: ''
- description: Manage volumes in Pure Storage Fusion
name: fusion_volume
namespace: ''
release_date: '2022-05-25'
1.0.1:
release_date: '2022-05-27'
1.0.2:
release_date: '2022-06-13'
1.0.3:
fragments:
- 27_review_fixes.yaml
release_date: '2022-06-27'
1.1.0:
changes:
bugfixes:
- Allow correct use of environmental variables for App ID and private file file
minor_changes:
- fusion_az - Add delete AZ option
- fusion_az - Allow any region to be specificed instead of limited to a known
list
- fusion_pp - Add delete PP option
- fusion_sc - Add delete SC option
- fusion_ss - Add delete SS option
fragments:
- 27_review_fixes.yaml
- 28_any_region.yaml
- 29_use_env.yaml
- 31_add_delete_az.yaml
- 32_add_delete_pp.yaml
- 33_add_delete_sc.yaml
- 34_add_delete_ss.yaml
modules:
- description: Manage Regions in Pure Storage Fusion
name: fusion_region
namespace: ''
release_date: '2022-09-01'
1.1.1:
release_date: '2022-09-23'
1.2.0:
changes:
bugfixes:
- fusion_info - Fixed issue with storage endpoint dict formatting
minor_changes:
- fusion_info - Added API Client information
fragments:
- 39_fix_info.yaml
- 41_add_api_client.yaml
release_date: '2022-12-02'
1.3.0:
changes:
bugfixes:
- fusion_pg - Add missing 'region' parameter
- fusion_tn - Add missing 'region' parameter
fragments:
- 44_fix_missing_regions.yaml
release_date: '2022-12-21'

View File

@@ -0,0 +1,32 @@
changelog_filename_template: ../CHANGELOG.rst
changelog_filename_version_depth: 0
changes_file: changelog.yaml
changes_format: combined
ignore_other_fragment_extensions: true
keep_fragments: false
mention_ancestor: true
new_plugins_after_name: removed_features
notesdir: fragments
prelude_section_name: release_summary
prelude_section_title: Release Summary
sanitize_changelog: true
sections:
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
title: Purestorage.Fusion
trivial_section_name: trivial
use_fqcn: true

View File

@@ -0,0 +1,2 @@
---
requires_ansible: ">=2.11.0"

View File

@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2021, Simon Dodsley <simon@purestorage.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
class ModuleDocFragment(object):
# Standard Pure Storage documentation fragment
DOCUMENTATION = r"""
options:
- See separate platform section for more details
requirements:
- See separate platform section for more details
notes:
- Ansible modules are available for the following Pure Storage products: FlashArray, FlashBlade, Pure1, Fusion
"""
# Documentation fragment for Fusion
FUSION = r"""
options:
key_file:
description:
- Path to the private key file
- Defaults to the set environment variable under FUSION_PRIVATE_KEY_FILE.
type: str
app_id:
description:
- Application ID from Pure1 Registration page
- eg. pure1:apikey:dssf2331sd
- Defaults to the set environment variable under FUSION_APP_ID
type: str
notes:
- This module requires the I(purefusion) Python library
- You must set C(FUSION_APP_ID) and C(FUSION_PRIVATE_KEY_FILE) environment variables
if I(app_id) and I(key_file) arguments are not passed to the module directly
requirements:
- python >= 3.5
- purefusion
"""

View File

@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Simon Dodsley <simon@purestorage.com>,2021
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
HAS_FUSION = True
try:
import fusion
except ImportError:
HAS_FUSION = False
from os import environ
import platform
TOKEN_EXCHANGE_URL = "https://api.pure1.purestorage.com/oauth2/1.0/token"
VERSION = 1.0
USER_AGENT_BASE = "Ansible"
def get_fusion(module):
"""Return System Object or Fail"""
user_agent = "%(base)s %(class)s/%(version)s (%(platform)s)" % {
"base": USER_AGENT_BASE,
"class": __name__,
"version": VERSION,
"platform": platform.platform(),
}
app_id = module.params["app_id"]
key_file = module.params["key_file"]
if HAS_FUSION:
config = fusion.Configuration()
if app_id and key_file:
try:
config.issuer_id = app_id
config.private_key_file = key_file
client = fusion.ApiClient(config)
client.set_default_header("User-Agent", user_agent)
except Exception:
module.fail_json(msg="Unknown failure. Please contact Pure Support")
elif environ.get("FUSION_APP_ID") and environ.get("FUSION_PRIVATE_KEY_FILE"):
try:
config.issuer_id = environ.get("FUSION_APP_ID")
config.private_key_file = environ.get("FUSION_PRIVATE_KEY_FILE")
client = fusion.ApiClient(config)
client.set_default_header("User-Agent", user_agent)
except Exception:
module.fail_json(msg="Unknown failure. Please contact Pure Support")
else:
module.fail_json(
msg="You must set FUSION_APP_ID and FUSION_PRIVATE_KEY_FILE environment variables "
"or the app_id and key_file module arguments"
)
try:
api_instance = fusion.DefaultApi(client)
api_instance.get_version()
except Exception as err:
module.fail_json(msg="Fusion authentication failed: {0}".format(err))
else:
module.fail_json(msg="fusion SDK is not installed.")
return client
def fusion_argument_spec():
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""
return dict(
app_id=dict(no_log=True),
key_file=dict(no_log=False),
)

View File

@@ -0,0 +1,152 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_api_client
version_added: '1.0.0'
short_description: Manage API clients in Pure Storage Fusion
description:
- Create or delete an API Client in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the client.
type: str
required: true
state:
description:
- Define whether the client should exist or not.
default: present
choices: [ present, absent ]
type: str
public_key:
description:
- The API clients PEM formatted (Base64 encoded) RSA public key.
- Include the C(—BEGIN PUBLIC KEY—) and C(—END PUBLIC KEY—) lines.
type: str
required: true
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new API client foo
purestorage.fusion.fusion_api_client:
name: "foo client"
public_key: "{{lookup('file', 'public_pem_file') }}"
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_client(module, fusion):
"""Get API Client - True or False"""
id_api_instance = purefusion.IdentityManagerApi(fusion)
try:
clients = id_api_instance.list_api_clients()
for client in range(0, len(clients)):
if (
clients[client].public_key == module.params["public_key"]
and clients[client].display_name == module.params["name"]
):
return clients[client].id
return False
except purefusion.rest.ApiException:
return False
def delete_client(module, fusion):
"""Delete API Client"""
id_api_instance = purefusion.IdentityManagerApi(fusion)
changed = True
if not module.check_mode:
try:
id_api_instance.delete_api_client(api_client_id=get_client(module, fusion))
except purefusion.rest.ApiException as err:
module.fail_json(
msg="API Client {0} deletion failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def create_client(module, fusion):
"""Create API Client"""
id_api_instance = purefusion.IdentityManagerApi(fusion)
changed = True
if not module.check_mode:
try:
client = purefusion.APIClientPost(
public_key=module.params["public_key"],
display_name=module.params["name"],
)
id_api_instance.create_api_client(client)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="API Client {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
public_key=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
client = get_client(module, fusion)
if not client and state == "present":
create_client(module, fusion)
elif client and state == "absent":
delete_client(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,293 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_array
version_added: '1.0.0'
short_description: Manage arrays in Pure Storage Fusion
description:
- Create or delete an array in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the array.
type: str
required: true
state:
description:
- Define whether the array should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the array.
- If not provided, defaults to I(name).
type: str
region:
description:
- The region the AZ is in.
type: str
required: true
availability_zone:
aliases: [ az ]
description:
- The availability zone the array is located in.
type: str
required: true
hardware_type:
description:
- Hardware type to which the storage class applies.
choices: [ flash-array-x, flash-array-c, flash-array-x-optane, flash-array-xl ]
required: true
type: str
host_name:
description:
- Management IP address of the array, or FQDN.
required: true
type: str
appliance_id:
description:
- Appliance ID of the array.
required: true
type: str
maintenance_mode:
description:
- Set the array in maintenance mode or not.
type: bool
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new array foo
purestorage.fusion.fusion_array:
name: foo
az: zone_1
hardware_type: bigfast
display_name: "foo array"
appliance_id: 1227571-198887878-35016350232000707
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
import math
import time
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def wait_operation_finish(module, op_id, fusion):
"""
wait_operation_finish wait until operation status is Succeeded or Failed. Then returns you that operation.
if the operation takes longer than expected, it will raise an Exception
"""
op_cli = purefusion.OperationsApi(fusion)
while True:
op = op_cli.get_operation(op_id)
if op.status == "Succeeded" or op.status == "Failed":
return op
time.sleep(int(math.ceil(op.retry_in / 1000)))
def wait_operation_succeeded(module, op_id, fusion):
"""
wait_operation_succeeded calls wait_operation_finish and expect the result is succeeded.
if the operation is in other status, it will raise an expection
"""
op = wait_operation_finish(module, op_id, fusion)
if op.status == "Succeeded":
return op
else:
# this is how we handle asynchronous error
# if operation failed, the error field should be set. We can check it by op.error
# op.error uses fusion.models.error.Error
module.fail_json("Operation failed: {0}".format(op.error.message))
def get_array(module, fusion):
"""Return Array or None"""
array_api_instance = purefusion.ArraysApi(fusion)
try:
return array_api_instance.get_array(
array_name=module.params["name"],
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def create_array(module, fusion):
"""Create Array"""
array_api_instance = purefusion.ArraysApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
array = purefusion.ArrayPost(
hardware_type=module.params["hardware_type"],
display_name=display_name,
host_name=module.params["host_name"],
name=module.params["name"],
appliance_id=module.params["appliance_id"],
)
res = array_api_instance.create_array(
array,
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
wait_operation_succeeded(module, res.id, fusion)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Array {0} creation failed.: {1}".format(module.params["name"], err)
)
if module.params["maintenance_mode"] is not None:
array = purefusion.ArrayPatch(
maintenance_mode=purefusion.NullableBoolean(
module.params["maintenance_mode"]
),
)
res = array_api_instance.update_array(
array,
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
array_name=module.params["name"],
)
wait_operation_succeeded(module, res.id, fusion)
module.exit_json(changed=changed)
def update_array(module, fusion, array):
"""Update Array"""
array_api_instance = purefusion.ArraysApi(fusion)
changed = False
if (
module.params["display_name"]
and module.params["display_name"] != array.display_name
):
display_name = module.params["display_name"]
changed = True
if not module.check_mode:
array = purefusion.ArrayPatch(
display_name=purefusion.NullableString(display_name),
)
res = array_api_instance.update_array(
array,
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
array_name=module.params["name"],
)
wait_operation_succeeded(module, res.id, fusion)
if module.params["maintenance_mode"] is not None:
if module.params["maintenance_mode"] != array.maintenance_mode:
maint_mode = module.params["maintenance_mode"]
changed = True
if not module.check_mode:
array = purefusion.ArrayPatch(
maintenance_mode=purefusion.NullableBoolean(maint_mode),
)
res = array_api_instance.update_array(
array,
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
array_name=module.params["name"],
)
wait_operation_succeeded(module, res.id, fusion)
module.exit_json(changed=changed)
def delete_array(module, fusion):
"""Delete Array - not currently available"""
array_api_instance = purefusion.ArraysApi(fusion)
changed = True
if not module.check_mode:
try:
res = array_api_instance.delete_array(
region_name=module.params["region"],
availability_zone_name=module.params["availability_zone"],
array_name=module.params["name"],
)
wait_operation_succeeded(module, res.id, fusion)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Array {0} creation failed.: {1}".format(module.params["name"], err)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
availability_zone=dict(type="str", required=True, aliases=["az"]),
display_name=dict(type="str"),
region=dict(type="str", required=True),
appliance_id=dict(type="str", required=True),
host_name=dict(type="str", required=True),
hardware_type=dict(
type="str",
required=True,
choices=[
"flash-array-x",
"flash-array-c",
"flash-array-x-optane",
"flash-array-xl",
],
),
maintenance_mode=dict(type="bool"),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
array = get_array(module, fusion)
if not array and state == "present":
create_array(module, fusion)
elif array and state == "present":
update_array(module, fusion, array)
elif array and state == "absent":
delete_array(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,186 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_az
version_added: '1.0.0'
short_description: Create Availability Zones in Pure Storage Fusion
description:
- Manage an Availability Zone in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the Availability Zone.
type: str
required: true
state:
description:
- Define whether the Availability Zone should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the Availability Zone.
- If not provided, defaults to I(name).
type: str
region:
description:
- Region within which the AZ is created.
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new AZ foo
purestorage.fusion.fusion_az:
name: foo
display_name: "foo AZ"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete AZ foo
purestorage.fusion.fusion_az:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_az(module, fusion):
"""Get Availability Zone or None"""
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
try:
return az_api_instance.get_availability_zone(
availability_zone_name=module.params["name"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def get_region(module, fusion):
"""Get Region or None"""
region_api_instance = purefusion.RegionsApi(fusion)
try:
return region_api_instance.get_region(
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def delete_az(module, fusion):
"""Delete Availability Zone"""
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
changed = True
if not module.check_mode:
try:
az_api_instance.delete_availability_zone(
region_name=module.params["region"],
availability_zone_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Availability Zone {0} deletion failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def create_az(module, fusion):
"""Create Availability Zone"""
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
azone = purefusion.AvailabilityZonePost(
name=module.params["name"],
display_name=display_name,
)
az_api_instance.create_availability_zone(
azone, region_name=module.params["region"]
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Availability Zone {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
region=dict(type="str"),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
azone = get_az(module, fusion)
if not get_region(module, fusion):
module.fail_json(
msg="Region {0} does not exist.".format(module.params["region"])
)
if not azone and state == "present":
create_az(module, fusion)
elif azone and state == "absent":
delete_az(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,270 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_hap
version_added: '1.0.0'
short_description: Manage host access policies in Pure Storage Fusion
description:
- Create or delete host access policies in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
- Setting passwords is not an idempotent action.
- Only iSCSI transport is currently supported.
- iSCSI CHAP is not yet supported.
options:
name:
description:
- The name of the host access policy.
type: str
required: true
display_name:
description:
- The human name of the host access policy.
type: str
state:
description:
- Define whether the host access policy should exist or not.
- When removing host access policy all connected volumes must
have been previously disconnected.
type: str
default: present
choices: [ absent, present ]
wwns:
type: list
elements: str
description:
- CURRENTLY NOT SUPPORTED.
- List of wwns for the host access policy.
iqn:
type: str
description:
- IQN for the host access policy.
nqn:
type: str
description:
- CURRENTLY NOT SUPPORTED.
- NQN for the host access policy.
personality:
type: str
description:
- Define which operating system the host is.
default: linux
choices: ['linux','hpux', 'vms', 'aix', 'esxi', 'solaris', 'hitachi-vsp', 'oracle-vm-server']
target_user:
type: str
description:
- CURRENTLY NOT SUPPORTED.
- Sets the target user name for CHAP authentication.
- Required with I(target_password).
- To clear the username/password pair use C(clear) as the password.
target_password:
type: str
description:
- CURRENTLY NOT SUPPORTED.
- Sets the target password for CHAP authentication.
- Password length between 12 and 255 characters.
- To clear the username/password pair use C(clear) as the password.
host_user:
type: str
description:
- CURRENTLY NOT SUPPORTED.
- Sets the host user name for CHAP authentication.
- Required with I(host_password).
- To clear the username/password pair use C(clear) as the password.
host_password:
type: str
description:
- CURRENTLY NOT SUPPORTED.
- Sets the host password for CHAP authentication.
- Password length between 12 and 255 characters.
- To clear the username/password pair use C(clear) as the password.
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new AIX host access policy
purestorage.fusion.fusion_hap:
name: foo
personality: aix
iqn: "iqn.2005-03.com.RedHat:linux-host1"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete host access policy
purestorage.flasharray.purefa_host:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
import re
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def _check_iqn(module, fusion):
hap_api_instance = purefusion.HostAccessPoliciesApi(fusion)
hosts = hap_api_instance.list_host_access_policies().items
for host in range(0, len(hosts)):
if (
hosts[host].iqn == module.params["iqn"]
and hosts[host].name != module.params["name"]
):
module.fail_json(
msg="Supplied IQN {0} already used by host access polivy {1}".format(
module.params["iqn"], hosts[host].name
)
)
def get_host(module, fusion):
"""Return host or None"""
hap_api_instance = purefusion.HostAccessPoliciesApi(fusion)
try:
hap_api_instance.get_host_access_policy(
host_access_policy_name=module.params["name"]
)
return True
except purefusion.rest.ApiException:
return False
def create_hap(module, fusion):
"""Create a new host access policy"""
hap_api_instance = purefusion.HostAccessPoliciesApi(fusion)
changed = True
if not module.check_mode:
try:
hap_api_instance.create_host_access_policy(
purefusion.HostAccessPoliciesPost(
iqn=module.params["iqn"],
personality=module.params["personality"],
name=module.params["name"],
display_name=module.params["display_name"],
)
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Host Access Policy {0} creation failed: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_hap(module, fusion):
"""Delete a Host Access Policy"""
hap_api_instance = purefusion.HostAccessPoliciesApi(fusion)
changed = True
if not module.check_mode:
try:
hap_api_instance.delete_host_access_policy(
host_access_policy_name=module.params["name"]
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Host Access Policy {0} deletion failed: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["absent", "present"]),
nqn=dict(type="str"),
iqn=dict(type="str"),
wwns=dict(type="list", elements="str"),
host_password=dict(type="str", no_log=True),
host_user=dict(type="str"),
target_password=dict(type="str", no_log=True),
target_user=dict(type="str"),
display_name=dict(type="str"),
personality=dict(
type="str",
default="linux",
choices=[
"linux",
"hpux",
"vms",
"aix",
"esxi",
"solaris",
"hitachi-vsp",
"oracle-vm-server",
],
),
)
)
required_if = [["state", "present", ["personality", "iqn"]]]
required_together = [
["host_password", "host_user"],
["target_password", "target_user"],
]
module = AnsibleModule(
argument_spec,
supports_check_mode=True,
required_together=required_together,
required_if=required_if,
)
fusion = get_fusion(module)
module.params["name"] = module.params["name"].lower()
hap_pattern = re.compile("^[a-zA-Z0-9]([a-zA-Z0-9-_]{0,61}[a-zA-Z0-9])?$")
iqn_pattern = re.compile(
r"^iqn\.\d{4}-\d{2}((?<!-)\.(?!-)[a-zA-Z0-9\-]+){1,63}(?<!-)(?<!\.)(:[^:]+)?$"
)
if not hap_pattern.match(module.params["name"]):
module.fail_json(
msg="Host Access Policy {0} does not conform to naming convention".format(
module.params["name"]
)
)
if not iqn_pattern.match(module.params["iqn"]):
module.fail_json(
msg="IQN {0} is not a valid iSCSI IQN".format(module.params["name"])
)
state = module.params["state"]
host = get_host(module, fusion)
_check_iqn(module, fusion)
if not host and state == "present":
create_hap(module, fusion)
elif host and state == "absent":
delete_hap(module, fusion)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,150 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_hw
version_added: '1.0.0'
short_description: Create hardware types in Pure Storage Fusion
description:
- Create a hardware type in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the hardware type.
type: str
required: true
state:
description:
- Define whether the hardware type should exist or not.
- Currently there is no mechanism to delete a hardware type.
default: present
choices: [ present ]
type: str
display_name:
description:
- The human name of the hardware type.
- If not provided, defaults to I(name).
type: str
media_type:
description:
- Volume size limit in M, G, T or P units.
type: str
required: true
array_type:
description:
- The array type for the hardware type.
choices: [ FA//X, FA//C ]
type: str
required: true
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new hardware type foo
purestorage.fusion.fusion_hw:
name: foo
array_type: "FA//X"
media_type: NVME
display_name: "NVME arrays"
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_hw(module, fusion):
"""Get Hardware Type or None"""
hw_api_instance = purefusion.HardwareTypesApi(fusion)
try:
return hw_api_instance.get_hardware_type(
hardware_type_name=module.params["name"]
)
except purefusion.rest.ApiException:
return None
def create_hw(module, fusion):
"""Create Hardware Type"""
hw_api_instance = purefusion.HardwareTypesApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
hw_type = purefusion.HardwareTypePost(
name=module.params["name"],
array_type=module.params["array_type"],
media_type=module.params["media_type"],
display_name=display_name,
)
hw_api_instance.create_hardware_type(hw_type)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Hardware Type {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
array_type=dict(type="str", choices=["FA//X", "FA//C"], required=True),
media_type=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["present"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
h_type = get_hw(module, fusion)
if not h_type and state == "present":
create_hw(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,919 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2021, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_info
version_added: '1.0.0'
short_description: Collect information from Pure Fusion
description:
- Collect information from a Pure Fusion environment.
- By default, the module will collect basic
information including counts for arrays, availabiliy_zones, volunmes, snapshots
. Fleet capacity and data reduction rates are also provided.
- Additional information can be collected based on the configured set of arguements.
author:
- Pure Storage ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
gather_subset:
description:
- When supplied, this argument will define the information to be collected.
Possible values for this include all, minimum, roles, users, placements,
arrays, hardware_types, volumes, host, storage_classes, protection_policies,
placement_groups, interfaces, zones, nigs, storage_endpoints, snapshots,
storage_services, tenants, tenant_spaces, network_interface_groups and
api_clients.
type: list
elements: str
required: false
default: minimum
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Collect default set of information
purestorage.fusion.fusion_info:
app_id: key_name
key_file: "az-admin-private-key.pem"
register: fusion_info
- name: Show default information
ansible.builtin.debug:
msg: "{{ fusion_info['fusion_info']['default'] }}"
- name: Collect all information
purestorage.fusion.fusion_info:
gather_subset:
- all
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Show all information
ansible.builtin.debug:
msg: "{{ fusion_info['fusion_info'] }}"
"""
RETURN = r"""
fusion_info:
description: Returns the information collected from Fusion
returned: always
type: complex
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
import time
def _convertMicroseconds(micros):
seconds = (micros / 1000) % 60
minutes = (micros / (1000 * 60)) % 60
hours = (micros / (1000 * 60 * 60)) % 24
return seconds, minutes, hours
def generate_default_dict(fusion):
default_info = {}
arrays_api_instance = purefusion.ArraysApi(fusion)
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
default_api_instance = purefusion.DefaultApi(fusion)
hw_api_instance = purefusion.HardwareTypesApi(fusion)
host_access_api_instance = purefusion.HostAccessPoliciesApi(fusion)
id_api_instance = purefusion.IdentityManagerApi(fusion)
nic_api_instance = purefusion.NetworkInterfacesApi(fusion)
nig_api_instance = purefusion.NetworkInterfaceGroupsApi(fusion)
plgrp_api_instance = purefusion.PlacementGroupsApi(fusion)
protpol_api_instance = purefusion.ProtectionPoliciesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
role_assign_api_instance = purefusion.RoleAssignmentsApi(fusion)
roles_api_instance = purefusion.RolesApi(fusion)
snapshot_api_instance = purefusion.SnapshotsApi(fusion)
send_api_instance = purefusion.StorageEndpointsApi(fusion)
storage_srv_api_instance = purefusion.StorageServicesApi(fusion)
storage_class_api_instance = purefusion.StorageClassesApi(fusion)
tenant_api_instance = purefusion.TenantsApi(fusion)
tenantspace_api_instance = purefusion.TenantSpacesApi(fusion)
vol_api_instance = purefusion.VolumesApi(fusion)
default_info["version"] = default_api_instance.get_version().version
storage_services = storage_srv_api_instance.list_storage_services()
default_info["storage_services"] = len(storage_services.items)
sclass = 0
for storserv in range(0, len(storage_services.items)):
sclass = sclass + len(
storage_class_api_instance.list_storage_classes(
storage_service_name=storage_services.items[storserv].name
).items
)
default_info["storage_classes"] = sclass
protection_policies = protpol_api_instance.list_protection_policies()
default_info["protection_policies"] = len(protection_policies.items)
users = id_api_instance.list_users()
default_info["users"] = len(users)
host_access_policies = host_access_api_instance.list_host_access_policies()
default_info["host_access_policies"] = len(host_access_policies.items)
hw_types = hw_api_instance.list_hardware_types()
default_info["hardware_types"] = len(hw_types.items)
tenants = tenant_api_instance.list_tenants()
default_info["tenants"] = len(tenants.items)
tenant_spaces = 0
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenant_spaces + len(
tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
)
default_info["tenant_spaces"] = tenant_spaces
roles = roles_api_instance.list_roles()
assignments = 0
default_info["roles"] = len(roles)
for role in range(0, len(roles)):
assignments = assignments + len(
role_assign_api_instance.list_role_assignments(role_name=roles[role].name)
)
default_info["role_assignments"] = assignments
regions = regions_api_instance.list_regions()
default_info["regions"] = len(regions.items)
azs = 0
for count in range(0, len(regions.items)):
azs = azs + len(
az_api_instance.list_availability_zones(
region_name=regions.items[count].name
).items
)
default_info["availability_zones"] = azs
arrays = nigs = sendpoints = nics = 0
for count in range(0, len(regions.items)):
azones = az_api_instance.list_availability_zones(
region_name=regions.items[count].name
)
for azone in range(0, len(azones.items)):
array_details = arrays_api_instance.list_arrays(
availability_zone_name=azones.items[azone].name,
region_name=regions.items[count].name,
)
for array_detail in range(0, len(array_details.items)):
nics = nics + len(
nic_api_instance.list_network_interfaces(
availability_zone_name=azones.items[azone].name,
region_name=regions.items[count].name,
array_name=array_details.items[array_detail].name,
).items
)
nigs = nigs + len(
nig_api_instance.list_network_interface_groups(
availability_zone_name=azones.items[azone].name,
region_name=regions.items[count].name,
).items
)
sendpoints = sendpoints + len(
send_api_instance.list_storage_endpoints(
availability_zone_name=azones.items[azone].name,
region_name=regions.items[count].name,
).items
)
arrays = arrays + len(array_details.items)
default_info["appiiances"] = arrays
default_info["network_interfaces"] = nics
default_info["network_interface_groups"] = nigs
volumes = placement_grps = snapshots = 0
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
volumes = volumes + len(
vol_api_instance.list_volumes(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
).items
)
placement_grps = placement_grps + len(
plgrp_api_instance.list_placement_groups(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
).items
)
snapshots = snapshots + len(
snapshot_api_instance.list_snapshots(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
).items
)
default_info["volumes"] = volumes
default_info["placements_groups"] = placement_grps
default_info["snapshots"] = snapshots
return default_info
def generate_nics_dict(fusion):
nics_info = {}
nic_api_instance = purefusion.NetworkInterfacesApi(fusion)
arrays_api_instance = purefusion.ArraysApi(fusion)
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
regions = regions_api_instance.list_regions()
for region in range(0, len(regions.items)):
azs = az_api_instance.list_availability_zones(
region_name=regions.items[region].name
)
for count in range(0, len(azs.items)):
array_details = arrays_api_instance.list_arrays(
availability_zone_name=azs.items[count].name,
region_name=regions.items[region].name,
)
for array_detail in range(0, len(array_details.items)):
array_name = (
azs.items[count].name + "/" + array_details.items[array_detail].name
)
nics_info[array_name] = {}
nics = nic_api_instance.list_network_interfaces(
availability_zone_name=azs.items[count].name,
region_name=regions.items[region].name,
array_name=array_details.items[array_detail].name,
)
for nic in range(0, len(nics.items)):
nics_info[array_name][nics.items[nic].name] = {
"enabled": nics.items[nic].enabled,
"display_name": nics.items[nic].display_name,
"interface_type": nics.items[nic].interface_type,
"services": nics.items[nic].services,
"max_speed": nics.items[nic].max_speed,
"vlan": nics.items[nic].eth.vlan,
"address": nics.items[nic].eth.address,
"mac_address": nics.items[nic].eth.mac_address,
"gateway": nics.items[nic].eth.gateway,
"mtu": nics.items[nic].eth.mtu,
"network_interface_group": nics.items[
nic
].network_interface_group.name,
"availability_zone": nics.items[nic].availability_zone.name,
}
return nics_info
def generate_hap_dict(fusion):
hap_info = {}
api_instance = purefusion.HostAccessPoliciesApi(fusion)
hosts = api_instance.list_host_access_policies()
for host in range(0, len(hosts.items)):
name = hosts.items[host].name
hap_info[name] = {
"personality": hosts.items[host].personality,
"display_name": hosts.items[host].display_name,
"iqn": hosts.items[host].iqn,
}
return hap_info
def generate_array_dict(fusion):
array_info = {}
array_api_instance = purefusion.ArraysApi(fusion)
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
regions = regions_api_instance.list_regions()
for region in range(0, len(regions.items)):
azs = az_api_instance.list_availability_zones(
region_name=regions.items[region].name
)
for az in range(0, len(azs.items)):
arrays = array_api_instance.list_arrays(
availability_zone_name=azs.items[az].name,
region_name=regions.items[region].name,
)
for array in range(0, len(arrays.items)):
array_name = arrays.items[array].name
array_space = array_api_instance.get_array_space(
availability_zone_name=azs.items[az].name,
array_name=array_name,
region_name=regions.items[region].name,
)
array_perf = array_api_instance.get_array_performance(
availability_zone_name=azs.items[az].name,
array_name=array_name,
region_name=regions.items[region].name,
)
array_info[array_name] = {
"region": regions.items[region].name,
"availability_zone": azs.items[az].name,
"host_name": arrays.items[array].host_name,
"maintenance_mode": arrays.items[array].maintenance_mode,
"unavailable_mode": arrays.items[array].unavailable_mode,
"display_name": arrays.items[array].display_name,
"hardware_type": arrays.items[array].hardware_type.name,
"appliance_id": arrays.items[array].appliance_id,
"apartment_id": getattr(arrays.items[array], "apartment_id", None),
"space": {
"total_physical_space": array_space.total_physical_space,
},
"performance": {
"read_bandwidth": array_perf.read_bandwidth,
"read_latency_us": array_perf.read_latency_us,
"reads_per_sec": array_perf.reads_per_sec,
"write_bandwidth": array_perf.write_bandwidth,
"write_latency_us": array_perf.write_latency_us,
"writes_per_sec": array_perf.writes_per_sec,
},
}
return array_info
def generate_pg_dict(fusion):
pg_info = {}
tenant_api_instance = purefusion.TenantsApi(fusion)
tenantspace_api_instance = purefusion.TenantSpacesApi(fusion)
pg_api_instance = purefusion.PlacementGroupsApi(fusion)
tenants = tenant_api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
groups = pg_api_instance.list_placement_groups(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
)
for group in range(0, len(groups.items)):
group_name = (
tenants.items[tenant].name
+ "/"
+ tenant_spaces[tenant_space].name
+ "/"
+ groups.items[group].name
)
pg_info[group_name] = {
"tenant": groups.items[group].tenant.name,
"display_name": groups.items[group].display_name,
"placement_engine": groups.items[group].placement_engine,
"tenant_space": groups.items[group].tenant_space.name,
"az": groups.items[group].availability_zone.name,
"array": getattr(groups.items[group].array, "name", None),
}
return pg_info
def generate_placements_dict(fusion):
pl_info = {}
tenant_api_instance = purefusion.TenantsApi(fusion)
tenantspace_api_instance = purefusion.TenantSpacesApi(fusion)
pl_api_instance = purefusion.PlacementsApi(fusion)
tenants = tenant_api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
placements = pl_api_instance.list_placements(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
)
for placement in range(0, len(placements.items)):
pl_name = (
tenants.items[tenant].name
+ "/"
+ tenant_spaces[tenant_space].name
+ "/"
+ placements.items[placement].name
)
pl_info[pl_name] = {
"tenant": tenants.items[tenant].name,
"tenant_space": tenant_spaces[tenant_space].name,
"display_name": placements.items[placement].display_name,
"placement_group": placements.items[placement].placement_group.name,
"storage_class": placements.items[placement].storage_class.name,
"array": placements.items[placement].array.name,
"protocols": {
"iscsi": {},
"fc": {},
"nvme": {},
},
}
if placements.items[placement].protocols.iscsi:
pl_info[pl_name]["protocols"]["iscsi"] = {
"iqn": placements.items[placement].protocols.iscsi.iqn,
"addresses": placements.items[
placement
].protocols.iscsi.addresses,
}
return pl_info
def generate_ts_dict(fusion):
ts_info = {}
tenant_api_instance = purefusion.TenantsApi(fusion)
tenantspace_api_instance = purefusion.TenantSpacesApi(fusion)
tenants = tenant_api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
ts_name = (
tenants.items[tenant].name + "/" + tenant_spaces[tenant_space].name
)
ts_info[ts_name] = {
"tenant": tenants.items[tenant].name,
"display_name": tenant_spaces[tenant_space].display_name,
}
return ts_info
def generate_pp_dict(fusion):
pp_info = {}
api_instance = purefusion.ProtectionPoliciesApi(fusion)
policies = api_instance.list_protection_policies()
for policy in range(0, len(policies.items)):
policy_name = policies.items[policy].name
pp_info[policy_name] = {
"objectives": policies.items[policy].objectives,
}
return pp_info
def generate_tenant_dict(fusion):
tenant_info = {}
api_instance = purefusion.TenantsApi(fusion)
tenants = api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
name = tenants.items[tenant].name
tenant_info[name] = {
"display_name": tenants.items[tenant].display_name,
}
return tenant_info
def generate_zones_dict(fusion):
zones_info = {}
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
regions = regions_api_instance.list_regions()
for region in range(0, len(regions.items)):
zones = az_api_instance.list_availability_zones(
region_name=regions.items[region].name
)
for zone in range(0, len(zones.items)):
az_name = zones.items[zone].name
zones_info[az_name] = {
"display_name": zones.items[zone].display_name,
"region": zones.items[zone].region.name,
}
return zones_info
def generate_ras_dict(fusion):
ras_info = {}
ras_api_instance = purefusion.RoleAssignmentsApi(fusion)
role_api_instance = purefusion.RolesApi(fusion)
roles = role_api_instance.list_roles()
for role in range(0, len(roles)):
ras = ras_api_instance.list_role_assignments(role_name=roles[role].name)
for assignment in range(0, len(ras)):
name = ras[assignment].name
ras_info[name] = {
"display_name": ras[assignment].display_name,
"role": ras[assignment].role.name,
"scope": ras[assignment].scope.name,
}
return ras_info
def generate_roles_dict(fusion):
roles_info = {}
api_instance = purefusion.RolesApi(fusion)
roles = api_instance.list_roles()
for role in range(0, len(roles)):
name = roles[role].name
roles_info[name] = {
"display_name": roles[role].display_name,
"scopes": roles[role].assignable_scopes,
}
return roles_info
def generate_api_client_dict(fusion):
client_info = {}
api_instance = purefusion.IdentityManagerApi(fusion)
clients = api_instance.list_api_clients()
for client in range(0, len(clients)):
name = clients[client].name
client_info[name] = {
"display_name": clients[client].display_name,
"issuer": clients[client].issuer,
"public_key": clients[client].public_key,
"creator_id": clients[client].creator_id,
"last_key_update": time.strftime(
"%a, %d %b %Y %H:%M:%S %Z",
time.localtime(clients[client].last_key_update / 1000),
),
"last_used": time.strftime(
"%a, %d %b %Y %H:%M:%S %Z",
time.localtime(clients[client].last_used / 1000),
),
}
return client_info
def generate_users_dict(fusion):
users_info = {}
api_instance = purefusion.IdentityManagerApi(fusion)
users = api_instance.list_users()
for user in range(0, len(users)):
name = users[user].name
users_info[name] = {
"display_name": users[user].display_name,
"email": users[user].email,
"id": users[user].id,
}
return users_info
def generate_hardware_dict(fusion):
hardware_info = {}
api_instance = purefusion.HardwareTypesApi(fusion)
hw_types = api_instance.list_hardware_types()
for hw_type in range(0, len(hw_types.items)):
type_name = hw_types.items[hw_type].name
hardware_info[type_name] = {
"array_type": hw_types.items[hw_type].array_type,
"display_name": hw_types.items[hw_type].display_name,
"media_type": hw_types.items[hw_type].media_type,
}
return hardware_info
def generate_storageclass_dict(fusion):
sc_info = {}
ss_api_instance = purefusion.StorageServicesApi(fusion)
sc_api_instance = purefusion.StorageClassesApi(fusion)
services = ss_api_instance.list_storage_services()
for service in range(0, len(services.items)):
classes = sc_api_instance.list_storage_classes(
storage_service_name=services.items[service].name,
)
for s_class in range(0, len(classes.items)):
sc_name = classes.items[s_class].name
sc_info[sc_name] = {
"bandwidth_limit": getattr(
classes.items[s_class], "bandwidth_limit", None
),
"iops_limit": getattr(classes.items[s_class], "iops_limit", None),
"size_limit": getattr(classes.items[s_class], "size_limit", None),
"display_name": classes.items[s_class].display_name,
"storage_service": services.items[service].name,
}
return sc_info
def generate_storserv_dict(fusion):
ss_dict = {}
ss_api_instance = purefusion.StorageServicesApi(fusion)
services = ss_api_instance.list_storage_services()
for service in range(0, len(services.items)):
ss_dict[services.items[service].name] = {
"display_name": services.items[service].display_name,
"hardware_types": [],
}
for hwtype in range(0, len(services.items[service].hardware_types)):
ss_dict[services.items[service].name]["hardware_types"].append(
services.items[service].hardware_types[hwtype].name
)
return ss_dict
def generate_se_dict(fusion):
se_dict = {}
se_api_instance = purefusion.StorageEndpointsApi(fusion)
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
regions = regions_api_instance.list_regions()
for region in range(0, len(regions.items)):
azs = az_api_instance.list_availability_zones(
region_name=regions.items[region].name
)
for az in range(0, len(azs.items)):
endpoints = se_api_instance.list_storage_endpoints(
region_name=regions.items[region].name,
availability_zone_name=azs.items[az].name,
)
for endpoint in range(0, len(endpoints.items)):
name = (
regions.items[region].name
+ "/"
+ azs.items[az].name
+ "/"
+ endpoints.items[endpoint].name
)
se_dict[name] = {
"display_name": endpoints.items[endpoint].display_name,
"endpoint_type": endpoints.items[endpoint].endpoint_type,
"iscsi_interfaces": [],
}
for iface in range(
0, len(endpoints.items[endpoint].iscsi.discovery_interfaces)
):
se_dict[name]["iscsi_interfaces"].append(
{
"address": endpoints.items[endpoint]
.iscsi.discovery_interfaces[iface]
.address,
"gateway": endpoints.items[endpoint]
.iscsi.discovery_interfaces[iface]
.gateway,
"mtu": endpoints.items[endpoint]
.iscsi.discovery_interfaces[iface]
.mtu,
"network_interface_group": endpoints.items[endpoint]
.iscsi.discovery_interfaces[iface]
.network_interface_groups[0]
.name,
}
)
return se_dict
def generate_nig_dict(fusion):
nig_dict = {}
nig_api_instance = purefusion.NetworkInterfaceGroupsApi(fusion)
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
regions_api_instance = purefusion.RegionsApi(fusion)
regions = regions_api_instance.list_regions()
for region in range(0, len(regions.items)):
azs = az_api_instance.list_availability_zones(
region_name=regions.items[region].name
)
for az in range(0, len(azs.items)):
nigs = nig_api_instance.list_network_interface_groups(
region_name=regions.items[region].name,
availability_zone_name=azs.items[az].name,
)
for nig in range(0, len(nigs.items)):
name = (
regions.items[region].name
+ "/"
+ azs.items[az].name
+ "/"
+ nigs.items[nig].name
)
nig_dict[name] = {
"display_name": nigs.items[nig].display_name,
"gateway": nigs.items[nig].eth.gateway,
"prefix": nigs.items[nig].eth.prefix,
"mtu": nigs.items[nig].eth.mtu,
}
return nig_dict
def generate_snap_dict(fusion):
snap_dict = {}
vsnap_dict = {}
tenant_api_instance = purefusion.TenantsApi(fusion)
tenantspace_api_instance = purefusion.TenantSpacesApi(fusion)
snap_api_instance = purefusion.SnapshotsApi(fusion)
vsnap_api_instance = purefusion.VolumeSnapshotsApi(fusion)
tenants = tenant_api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenantspace_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
snaps = snap_api_instance.list_snapshots(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
)
for snap in range(0, len(snaps.items)):
snap_name = (
tenants.items[tenant].name
+ "/"
+ tenant_spaces[tenant_space].name
+ "/"
+ snaps.items[snap].name
)
secs, mins, hours = _convertMicroseconds(
snaps.items[snap].time_remaining
)
snap_dict[snap_name] = {
"display_name": snaps.items[snap].display_name,
"protection_policy": snaps.items[snap].protection_policy,
"time_remaining": "{0} hours, {1} mins, {2} secs".format(
int(hours), int(mins), int(secs)
),
"volume_snapshots_link": snaps.items[snap].volume_snapshots_link,
}
vsnaps = vsnap_api_instance.list_volume_snapshots(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
snapshot_name=snaps.items[snap].name,
)
for vsnap in range(0, len(vsnaps.items)):
vsnap_name = (
tenants.items[tenant].name
+ "/"
+ tenant_spaces[tenant_space].name
+ "/"
+ snaps.items[snap].name
+ "/"
+ vsnaps.items[vsnap].name
)
secs, mins, hours = _convertMicroseconds(
vsnaps.items[vsnap].time_remaining
)
vsnap_dict[vsnap_name] = {
"size": vsnaps.items[vsnap].size,
"display_name": vsnaps.items[vsnap].display_name,
"protection_policy": vsnaps.items[vsnap].protection_policy,
"serial_number": vsnaps.items[vsnap].serial_number,
"created_at": time.strftime(
"%a, %d %b %Y %H:%M:%S %Z",
time.localtime(vsnaps.items[vsnap].created_at / 1000),
),
"time_remaining": "{0} hours, {1} mins, {2} secs".format(
int(hours), int(mins), int(secs)
),
"placement_group": vsnaps.items[vsnap].placement_group.name,
}
return snap_dict, vsnap_dict
def generate_volumes_dict(fusion):
volume_info = {}
tenant_api_instance = purefusion.TenantsApi(fusion)
vol_api_instance = purefusion.VolumesApi(fusion)
tenant_space_api_instance = purefusion.TenantSpacesApi(fusion)
tenants = tenant_api_instance.list_tenants()
for tenant in range(0, len(tenants.items)):
tenant_spaces = tenant_space_api_instance.list_tenant_spaces(
tenant_name=tenants.items[tenant].name
).items
for tenant_space in range(0, len(tenant_spaces)):
volumes = vol_api_instance.list_volumes(
tenant_name=tenants.items[tenant].name,
tenant_space_name=tenant_spaces[tenant_space].name,
)
for volume in range(0, len(volumes.items)):
vol_name = (
tenants.items[tenant].name
+ "/"
+ tenant_spaces[tenant_space].name
+ "/"
+ volumes.items[volume].name
)
volume_info[vol_name] = {
"tenant": tenants.items[tenant].name,
"tenant_space": tenant_spaces[tenant_space].name,
"name": volumes.items[volume].name,
"size": volumes.items[volume].size,
"display_name": volumes.items[volume].display_name,
"array": volumes.items[volume].array.name,
"placement_group": volumes.items[volume].placement_group.name,
"source_volume_snapshot": getattr(
volumes.items[volume].source_volume_snapshot, "name", None
),
"protection_policy": getattr(
volumes.items[volume].protection_policy, "name", None
),
"storage_class": volumes.items[volume].storage_class.name,
"serial_number": volumes.items[volume].serial_number,
"target": {},
}
volume_info[vol_name]["target"] = {
"iscsi": {
"addresses": volumes.items[volume].target.iscsi.addresses,
"iqn": volumes.items[volume].target.iscsi.iqn,
},
"nvme": {
"addresses": None,
"nqn": None,
},
"fc": {
"addresses": None,
"wwns": None,
},
}
return volume_info
def main():
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(gather_subset=dict(default="minimum", type="list", elements="str"))
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
if not HAS_FUSION:
module.fail_json(msg="fusion SDK required for this module")
fusion = get_fusion(module)
subset = [test.lower() for test in module.params["gather_subset"]]
valid_subsets = (
"all",
"minimum",
"roles",
"users",
"placements",
"arrays",
"hardware_types",
"volumes",
"hosts",
"storage_classes",
"protection_policies",
"placement_groups",
"interfaces",
"zones",
"nigs",
"storage_endpoints",
"snapshots",
"storage_services",
"tenants",
"tenant_spaces",
"network_interface_groups",
"api_clients",
)
subset_test = (test in valid_subsets for test in subset)
if not all(subset_test):
module.fail_json(
msg="value must gather_subset must be one or more of: %s, got: %s"
% (",".join(valid_subsets), ",".join(subset))
)
info = {}
if "minimum" in subset or "all" in subset:
info["default"] = generate_default_dict(fusion)
if "hardware_types" in subset or "all" in subset:
info["hardware"] = generate_hardware_dict(fusion)
if "users" in subset or "all" in subset:
info["users"] = generate_users_dict(fusion)
if "zones" in subset or "all" in subset:
info["zones"] = generate_zones_dict(fusion)
if "roles" in subset or "all" in subset:
info["roles"] = generate_roles_dict(fusion)
info["role_assignments"] = generate_ras_dict(fusion)
if "storage_services" in subset or "all" in subset:
info["storage_services"] = generate_storserv_dict(fusion)
if "volumes" in subset or "all" in subset:
info["volumes"] = generate_volumes_dict(fusion)
if "protection_policies" in subset or "all" in subset:
info["protection_policies"] = generate_pp_dict(fusion)
if "placement_groups" in subset or "all" in subset:
info["placement_groups"] = generate_pg_dict(fusion)
if "storage_classes" in subset or "all" in subset:
info["storageclass"] = generate_storageclass_dict(fusion)
if "interfaces" in subset or "all" in subset:
info["interfaces"] = generate_nics_dict(fusion)
if "hosts" in subset or "all" in subset:
info["hosts"] = generate_hap_dict(fusion)
if "arrays" in subset or "all" in subset:
info["arrays"] = generate_array_dict(fusion)
if "tenants" in subset or "all" in subset:
info["tenants"] = generate_tenant_dict(fusion)
if "tenant_spaces" in subset or "all" in subset:
info["tenant_spaces"] = generate_ts_dict(fusion)
if "storage_endpoints" in subset or "all" in subset:
info["storage_endpoints"] = generate_se_dict(fusion)
if "api_clients" in subset or "all" in subset:
info["api_clients"] = generate_api_client_dict(fusion)
if "nigs" in subset or "all" in subset:
info["network_interface_groups"] = generate_nig_dict(fusion)
if "snapshots" in subset or "all" in subset:
info["snapshots"], info["volume_snapshots"] = generate_snap_dict(fusion)
module.exit_json(changed=False, fusion_info=info)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,279 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_nig
version_added: '1.0.0'
short_description: Manage Network Interface Groups in Pure Storage Fusion
description:
- Create, delete and modify network interface groups in Pure Storage Fusion.
- Currently this only supports a single tenant subnet per tenant network
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the network interface group.
type: str
required: true
display_name:
description:
- The human name of the network interface group.
- If not provided, defaults to I(name).
type: str
state:
description:
- Define whether the network interface group should exist or not.
type: str
default: present
choices: [ absent, present ]
availability_zone:
aliases: [ az ]
description:
- The name of the availability zone for the network interface group.
type: str
required: true
region:
description:
- Region for the network interface group.
type: str
required: true
gateway:
description:
- Address of the subnet gateway.
type: str
mtu:
description:
- MTU setting for the subnet.
default: 1500
type: int
group_type:
description:
- The type of network interface group.
type: str
default: eth
choices: [ eth ]
prefix:
description:
- Network prefix in CIDR format.
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new network interface group foo in AZ bar
purestorage.fusion.fusion_nig:
name: foo
availability_zone: bar
region: region1
mtu: 9000
gateway: 10.21.200.1
prefix: 10.21.200.0/24
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete network interface group foo in AZ bar
purestorage.fusion.fusion_nig:
name: foo
availability_zone: bar
region: region1
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
try:
from netaddr import IPNetwork
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_nig(module, fusion):
"""Check Network Interface Group"""
nig_api_instance = purefusion.NetworkInterfaceGroupsApi(fusion)
try:
return nig_api_instance.get_network_interface_group(
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
network_interface_group_name=module.params["name"],
)
except purefusion.rest.ApiException:
return None
def get_az(module, fusion):
"""Availability Zone or None"""
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
try:
return az_api_instance.get_availability_zone(
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def create_nig(module, fusion):
"""Create Network Interface Group"""
nig_api_instance = purefusion.NetworkInterfaceGroupsApi(fusion)
changed = True
if module.params["gateway"] and module.params["gateway"] not in IPNetwork(
module.params["prefix"]
):
module.fail_json(msg="Gateway and subnet prefix are not compatible.")
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
if module.params["group_type"] == "eth":
if module.params["gateway"]:
eth = purefusion.NetworkInterfaceGroupEthPost(
prefix=module.params["prefix"],
gateway=module.params["gateway"],
mtu=module.params["mtu"],
)
else:
eth = purefusion.NetworkInterfaceGroupEthPost(
prefix=module.params["prefix"],
mtu=module.params["mtu"],
)
nig = purefusion.NetworkInterfaceGroupPost(
group_type="eth",
eth=eth,
name=module.params["name"],
display_name=display_name,
)
nig_api_instance.create_network_interface_group(
nig,
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Network Interface Group {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_nig(module, fusion):
"""Delete Network Interface Group"""
changed = True
nig_api_instance = purefusion.NetworkInterfaceGroupsApi(fusion)
if not module.check_mode:
try:
nig_api_instance.delete_network_interface_group(
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
network_interface_group_name=module.params["name"],
)
except purefusion.rest.ApiException:
module.fail_json(
msg="Delete Network Interface Group {0} failed.".format(
module.params["name"]
)
)
module.exit_json(changed=changed)
def update_nig(module, fusion, nig):
"""Update Network Interface Group"""
changed = False
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
availability_zone=dict(type="str", required=True, aliases=["az"]),
region=dict(type="str", required=True),
prefix=dict(type="str"),
gateway=dict(type="str"),
mtu=dict(type="int", default=1500),
group_type=dict(type="str", default="eth", choices=["eth"]),
state=dict(type="str", default="present", choices=["absent", "present"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
if not HAS_NETADDR:
module.fail_json(msg="netaddr module is required")
state = module.params["state"]
fusion = get_fusion(module)
if module.params["prefix"]:
if "/" not in module.params["prefix"]:
module.fail_json(msg="Prefix must be in a CIDR format")
if 8 > int(module.params["prefix"].split("/")[1]) > 32:
module.fail_json(
msg="An invalid CIDR notation has been provided: {0}".format(
module.params["prefix"]
)
)
if not get_az(module, fusion):
module.fail_json(msg="Availability Zone {0} does not exist")
nig = get_nig(module, fusion)
if state == "present" and not nig:
if not module.params["prefix"]:
module.fail_json(
msg="When creating a new network interface group "
"`prefix` must be provided"
)
create_nig(module, fusion)
elif state == "present" and nig:
# TODO: re-add this when SDK bug fixed
module.exit_json(changed=False)
# update_ps(module, fusion, subnet)
elif state == "absent" and nig:
delete_nig(module, fusion)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,247 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_pg
version_added: '1.0.0'
short_description: Manage placement groups in Pure Storage Fusion
description:
- Create, update or delete a placement groups in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the placement group.
type: str
required: true
display_name:
description:
- The human name of the placement group.
- If not provided, defaults to I(name).
type: str
state:
description:
- Define whether the placement group should exist or not.
type: str
default: present
choices: [ absent, present ]
tenant:
description:
- The name of the tenant.
type: str
required: true
tenant_space:
description:
- The name of the tenant space.
type: str
required: true
region:
description:
- The name of the region the availability zone is in.
type: str
required: true
availability_zone:
aliases: [ az ]
description:
- The name of the availability zone to create the placement group in.
type: str
placement_engine:
description:
- For workload placement recommendations from Pure1 Meta, use C(pure1meta).
- Please note that this might increase volume creation time.
type: str
choices: [ heuristics, pure1meta ]
default: heuristics
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new placement group named foo
purestorage.fusion.fusion_pg:
name: foo
tenant: test
tenant_space: space_1
availability_zone: az1
placement_engine: pure1meta
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete placement group foo
purestorage.fusion.fusion_pg:
name: foo
tenant: test
tenant_space: space_1
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_ts(module, fusion):
"""Tenant Space or None"""
ts_api_instance = purefusion.TenantSpacesApi(fusion)
try:
return ts_api_instance.get_tenant_space(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
except purefusion.rest.ApiException:
return None
def get_az(module, fusion):
"""Availability Zone or None"""
api_instance = purefusion.AvailabilityZonesApi(fusion)
try:
return api_instance.get_availability_zone(
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def get_tenant(module, fusion):
"""Return Tenant or None"""
api_instance = purefusion.TenantsApi(fusion)
try:
return api_instance.get_tenant(tenant_name=module.params["tenant"])
except purefusion.rest.ApiException:
return None
def get_pg(module, fusion):
"""Return Placement Group or None"""
pg_api_instance = purefusion.PlacementGroupsApi(fusion)
try:
return pg_api_instance.get_placement_group(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
placement_group_name=module.params["name"],
)
except purefusion.rest.ApiException:
return None
def create_pg(module, fusion):
"""Create Placement Group"""
pg_api_instance = purefusion.PlacementGroupsApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
group = purefusion.PlacementGroupPost(
placement_engine=module.params["placement_engine"].lower(),
availability_zone=module.params["availability_zone"],
name=module.params["name"],
display_name=display_name,
)
pg_api_instance.create_placement_group(
group,
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Placement Group {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_pg(module, fusion):
"""Delete Placement Group"""
changed = True
pg_api_instance = purefusion.PlacementGroupsApi(fusion)
if not module.check_mode:
try:
pg_api_instance.delete_placement_group(
placement_group_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
except purefusion.rest.ApiException:
module.fail_json(
msg="Delete Placement Group {0} failed.".format(module.params["name"])
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
tenant=dict(type="str", required=True),
tenant_space=dict(type="str", required=True),
region=dict(type="str", required=True),
availability_zone=dict(type="str", aliases=["az"]),
state=dict(type="str", default="present", choices=["absent", "present"]),
placement_engine=dict(
type="str", default="heuristics", choices=["heuristics", "pure1meta"]
),
)
)
required_if = [["state", "present", ["availability_zone", "placement_engine"]]]
module = AnsibleModule(
argument_spec, required_if=required_if, supports_check_mode=True
)
state = module.params["state"]
fusion = get_fusion(module)
pgroup = get_pg(module, fusion)
if not (
get_az(module, fusion) and get_tenant(module, fusion) and get_ts(module, fusion)
):
module.fail_json(
msg="Please check the values for `availability_zone`, `tenant` "
"and `tenant_space` to ensure they all exit and have appropriate relationships."
)
if state == "present" and not pgroup:
create_pg(module, fusion)
elif state == "absent" and pgroup:
delete_pg(module, fusion)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,219 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_pp
version_added: '1.0.0'
short_description: Manage protection policies in Pure Storage Fusion
description:
- Manage protection policies in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the protection policy.
type: str
required: true
state:
description:
- Define whether the protection policy should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the protection policy.
- If not provided, defaults to I(name).
type: str
local_rpo:
description:
- Recovery Point Objective for snapshots.
- Value should be specified in minutes.
- Minimum value is 10 minutes.
type: int
required: true
local_retention:
description:
- Retention Duration for periodic snapshots.
- Minimum value is 1 minute.
- Value can be provided as m(inutes), h(ours),
d(ays), w(eeks), or y(ears).
- If no unit is provided, minutes are assumed.
- Must be between 1MB/s and 512GB/s.
type: str
required: true
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new protection policy foo
purestorage.fusion.fusion_pp:
name: foo
local_rpo: 10
local_retention: 4d
display_name: "foo pp"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Create new protection policy foo
purestorage.fusion.fusion_pp:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def human_to_minutes(period):
"""Given a human-readable period (e.g. 2d, 3w),
return the number of minutes. Will return 0 if the argument has
unexpected form.
"""
minutes = period[:-1]
unit = period[-1].lower()
if minutes.isdigit():
minutes = int(minutes)
if unit == "y":
minutes *= 524160
elif unit == "w":
minutes *= 10080
elif unit == "d":
minutes *= 1440
elif unit == "h":
minutes *= 60
else:
minutes = 0
else:
minutes = 0
return minutes
def get_pp(module, fusion):
"""Return Protection Policy or None"""
pp_api_instance = purefusion.ProtectionPoliciesApi(fusion)
try:
return pp_api_instance.get_protection_policy(
protection_policy_name=module.params["name"]
)
except purefusion.rest.ApiException:
return None
def create_pp(module, fusion):
"""Create Protection Policy"""
pp_api_instance = purefusion.ProtectionPoliciesApi(fusion)
local_retention = human_to_minutes(module.params["local_retention"])
if local_retention < 1:
module.fail_json(msg="Local Retention must be a minimum of 1 minutes")
if module.params["local_rpo"] < 10:
module.fail_json(msg="Local RPO must be a minimum of 10 minutes")
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
pp_api_instance.create_protection_policy(
purefusion.ProtectionPolicyPost(
name=module.params["name"],
display_name=display_name,
objectives=[
{
"type": "RPO",
"rpo": "PT" + str(module.params["local_rpo"]) + "M",
},
{
"type": "Retention",
"after": "PT" + str(local_retention) + "M",
},
],
)
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Protection Policy {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_pp(module, fusion):
"""Delete Protection Policy"""
pp_api_instance = purefusion.ProtectionPoliciesApi(fusion)
changed = True
if not module.check_mode:
try:
pp_api_instance.delete_protection_policy(
protection_policy_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Protection Policy {0} deletion failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
local_rpo=dict(type="int", required=True),
local_retention=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
policy = get_pp(module, fusion)
if not policy and state == "present":
create_pp(module, fusion)
elif policy and state == "absent":
delete_pp(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,270 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_ra
version_added: '1.0.0'
short_description: Manage role assignments in Pure Storage Fusion
description:
- Create or delete a storage class in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the role to be assigned/unassigned.
type: str
required: true
state:
description:
- Define whether the role assingment should exist or not.
type: str
default: present
choices: [ absent, present ]
user:
description:
- The username to assign the role to.
- Currently this only supports the Pure1 App ID.
- This should be provide in the same format as I(app_id).
required: true
type: str
scope:
description:
- The level to which the role is assigned.
choices: [ organization, tenant, tenant_space ]
default: organization
type: str
tenant:
description:
- The name of the tenant the user has the role applied to.
- Must be provided if I(scope) is set to either C(tenant) or C(tenant_space).
type: str
tenant_space:
description:
- The name of the tenant_space the user has the role applied to.
- Must be provided if I(scope) is set to C(tenant_space).
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Assign role foo to user in tenant bar
purestorage.fusion.fusion_ra:
name: foo
user: key_name
tenant: bar
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete role foo from user in tenant bar
purestorage.fusion.fusion_ra:
name: foo
user: key_name
tenant: bar
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def human_to_principal(fusion, user_id):
"""Given a human readable Fusion user, such as a Pure 1 App ID
return the associated principal
"""
principal = None
id_api_instance = purefusion.IdentityManagerApi(fusion)
users = id_api_instance.list_users()
for user in range(0, len(users)):
if users[user].name == user_id:
principal = users[user].id
return principal
def human_to_scope(params):
"""Given a scope type and associated tenant
and tenant_space, return the scope_link
"""
scope_link = None
if params["scope"] == "organization":
scope_link = "/"
elif params["scope"] == "tenant":
scope_link = "/tenants/" + params["tenant"]
elif params["scope"] == "tenant_space":
scope_link = (
"/tenants/" + params["tenant"] + "/tenant-spaces/" + params["tenant_space"]
)
return scope_link
def get_role(module, fusion):
"""Return Role or None"""
role_api_instance = purefusion.RolesApi(fusion)
try:
return role_api_instance.get_role(role_name=module.params["name"])
except purefusion.rest.ApiException:
return None
def get_ra(module, fusion):
"""Return Role Assignment or None"""
ra_api_instance = purefusion.RoleAssignmentsApi(fusion)
try:
assignments = ra_api_instance.list_role_assignments(
role_name=module.params["name"]
)
for assign in range(0, len(assignments)):
principal = human_to_principal(fusion, module.params["user"])
scope = human_to_scope(module.params)
if (
assignments[assign].principal == principal
and assignments[assign].scope.self_link == scope
):
return assignments[assign]
return None
except purefusion.rest.ApiException:
return None
def get_tenant(module, fusion):
"""Return tenant or None"""
t_api_instance = purefusion.TenantsApi(fusion)
try:
return t_api_instance.get_tenant(tenant_name=module.params["tenant"])
except purefusion.rest.ApiException:
return None
def get_ts(module, fusion):
"""Return tenant space or None"""
ts_api_instance = purefusion.TenantSpacesApi(fusion)
try:
return ts_api_instance.get_tenant_space(
tenant_space_name=module.params["tenant_space"],
tenant_name=module.params["tenant"],
)
except purefusion.rest.ApiException:
return None
def create_ra(module, fusion):
"""Create Role Assignment"""
ra_api_instance = purefusion.RoleAssignmentsApi(fusion)
changed = True
if not module.check_mode:
scope = human_to_scope(module.params)
principal = human_to_principal(fusion, module.params["user"])
assignment = purefusion.RoleAssignmentPost(scope=scope, principal=principal)
try:
ra_api_instance.create_role_assignment(
assignment, role_name=module.params["name"]
)
except purefusion.rest.ApiException:
module.fail_json(
msg="{0} level Role Assignment creation for user {1} failed".format(
module.params["scope"], module.params["user"]
)
)
module.exit_json(changed=changed)
def delete_ra(module, fusion):
"""Delete Role Assignment"""
changed = True
ra_api_instance = purefusion.RoleAssignmentsApi(fusion)
if not module.check_mode:
ra_name = get_ra(module, fusion).name
try:
ra_api_instance.delete_role_assignment(
role_name=module.params["name"], role_assignment_name=ra_name
)
except purefusion.rest.ApiException:
module.fail_json(
msg="{0} level Role Assignment delete for user {1} failed".format(
module.params["scope"], module.params["user"]
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
tenant=dict(type="str"),
tenant_space=dict(type="str"),
user=dict(type="str", required=True),
scope=dict(
type="str",
default="organization",
choices=["organization", "tenant", "tenant_space"],
),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
required_if = [
["scope", "tenant", ["tenant"]],
["scope", "tenant_space", ["tenant", "tenant_space"]],
]
module = AnsibleModule(
argument_spec, required_if=required_if, supports_check_mode=True
)
fusion = get_fusion(module)
state = module.params["state"]
if not human_to_principal(fusion, module.params["user"]):
module.fail_json(msg="User {0} does not exist".format(module.params["user"]))
if module.params["tenant"] and not get_tenant(module, fusion):
module.fail_json(
msg="Tenant {0} does not exist".format(module.params["tenant"])
)
if module.params["tenant_space"] and not get_ts(module, fusion):
module.fail_json(
msg="Tenant Space {0} does not exist".format(module.params["tenant_space"])
)
role_assignment = get_ra(module, fusion)
if not role_assignment and state == "present":
create_ra(module, fusion)
elif role_assignment and state == "absent":
delete_ra(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,196 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_region
version_added: '1.1.0'
short_description: Manage Regions in Pure Storage Fusion
description:
- Manage regions in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the Region.
type: str
required: true
state:
description:
- Define whether the Region should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the Region.
- If not provided, defaults to I(name).
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new region foo
purestorage.fusion.fusion_region:
name: foo
display_name: "foo Region"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Update region foo
purestorage.fusion.fusion_region:
name: foo
display_name: "new foo Region"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete region foo
purestorage.fusion.fusion_region:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_region(module, fusion):
"""Get Region or None"""
region_api_instance = purefusion.RegionsApi(fusion)
try:
return region_api_instance.get_region(
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def create_region(module, fusion):
"""Create Region"""
reg_api_instance = purefusion.RegionsApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
region = purefusion.RegionPost(
name=module.params["name"],
display_name=display_name,
)
reg_api_instance.create_region(region)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Region {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_region(module, fusion):
"""Delete Region"""
reg_api_instance = purefusion.RegionsApi(fusion)
changed = True
if not module.check_mode:
try:
reg_api_instance.delete_region(region_name=module.params["region"])
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Region {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def update_region(module, fusion, region):
"""Update Region settings"""
changed = False
reg_api_instance = purefusion.RegionsApi(fusion)
if (
module.params["display_name"]
and module.params["display_name"] != region.display_name
):
changed = True
if not module.check_mode:
reg = purefusion.RegionPatch(
display_name=purefusion.NullableString(module.params["display_name"])
)
try:
reg_api_instance.update_region(
reg,
region_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing region display_name failed: {0}".format(err)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
region = get_region(module, fusion)
if not region and state == "present":
create_region(module, fusion)
elif region and state == "present":
update_region(module, fusion, region)
elif region and state == "absent":
delete_region(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,344 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_sc
version_added: '1.0.0'
short_description: Manage storage classes in Pure Storage Fusion
description:
- Manage a storage class in Pure Storage Fusion.
notes:
- Supports C(check_mode).
- It is not currently possible to update bw_limit or
iops_limit after a storage class has been created.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
options:
name:
description:
- The name of the storage class.
type: str
required: true
state:
description:
- Define whether the storage class should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the storage class.
- If not provided, defaults to I(name).
type: str
size_limit:
description:
- Volume size limit in M, G, T or P units.
- Must be between 1MB and 4PB.
- If not provided at creation, this will default to 4PB.
type: str
bw_limit:
description:
- The bandwidth limit in M or G units.
M will set MB/s.
G will set GB/s.
- Must be between 1MB/s and 512GB/s.
- If not provided at creation, this will default to 512GB/s.
type: str
iops_limit:
description:
- The IOPs limit - use value or K or M.
K will mean 1000.
M will mean 1000000.
- Must be between 100 and 100000000.
- If not provided at creation, this will default to 100000000.
type: str
storage_service:
description:
- Storage service to which the storage class belongs.
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new storage class foo
purestorage.fusion.fusion_sc:
name: foo
size_limit: 100G
iops_limit: 100000
bw_limit: 25M
storage_service: service1
display_name: "test class"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Update storage class (only display_name change is supported)
purestorage.fusion.fusion_sc:
name: foo
display_name: "main class"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete storage class
purestorage.fusion.fusion_sc:
name: foo
storage_service: service1
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def human_to_bytes(size):
"""Given a human-readable byte string (e.g. 2G, 30M),
return the number of bytes. Will return 0 if the argument has
unexpected form.
"""
my_bytes = size[:-1]
unit = size[-1].upper()
if my_bytes.isdigit():
my_bytes = int(my_bytes)
if unit == "P":
my_bytes *= 1125899906842624
elif unit == "T":
my_bytes *= 1099511627776
elif unit == "G":
my_bytes *= 1073741824
elif unit == "M":
my_bytes *= 1048576
elif unit == "K":
my_bytes *= 1024
else:
my_bytes = 0
else:
my_bytes = 0
return my_bytes
def human_to_real(iops):
"""Given a human-readable IOPs string (e.g. 2K, 30M),
return the real number. Will return 0 if the argument has
unexpected form.
"""
digit = iops[:-1]
unit = iops[-1].upper()
if unit.isdigit():
digit = iops
elif digit.isdigit():
digit = int(digit)
if unit == "M":
digit *= 1000000
elif unit == "K":
digit *= 1000
else:
digit = 0
else:
digit = 0
return digit
def bytes_to_human(bytes_number):
"""Convert bytes to a human readable string"""
if bytes_number:
labels = ["B", "KB", "MB", "GB", "TB", "PB"]
i = 0
double_bytes = bytes_number
while i < len(labels) and bytes_number >= 1024:
double_bytes = bytes_number / 1024.0
i += 1
bytes_number = bytes_number / 1024
return str(round(double_bytes, 2)) + " " + labels[i]
return None
def get_sc(module, fusion):
"""Return Storage Class or None"""
sc_api_instance = purefusion.StorageClassesApi(fusion)
try:
return sc_api_instance.get_storage_class(
storage_class_name=module.params["name"],
storage_service_name=module.params["storage_service"],
)
except purefusion.rest.ApiException:
return None
def get_ss(module, fusion):
"""Return Storage Service or None"""
ss_api_instance = purefusion.StorageServicesApi(fusion)
try:
return ss_api_instance.get_storage_service(
storage_service_name=module.params["storage_service"]
)
except purefusion.rest.ApiException:
return None
def create_sc(module, fusion):
"""Create Storage Class"""
sc_api_instance = purefusion.StorageClassesApi(fusion)
if not module.params["size_limit"]:
module.params["size_limit"] = "4P"
if not module.params["iops_limit"]:
module.params["iops_limit"] = "100000000"
if not module.params["bw_limit"]:
module.params["bw_limit"] = "512G"
size_limit = human_to_bytes(module.params["size_limit"])
iops_limit = int(human_to_real(module.params["iops_limit"]))
bw_limit = human_to_bytes(module.params["bw_limit"])
if bw_limit not in range(1048576, 549755813889): # 1MB/s to 512GB/s
module.fail_json(msg="Bandwidth limit is not within the required range")
if 100 > iops_limit > 10000000:
module.fail_json(msg="IOPs limit is not within the required range")
if size_limit not in range(1048576, 4503599627370497): # 1MB to 4PB
module.fail_json(msg="Size limit is not within the required range")
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
s_class = purefusion.StorageClassPost(
name=module.params["name"],
size_limit=size_limit,
iops_limit=iops_limit,
bandwidth_limit=bw_limit,
display_name=display_name,
)
sc_api_instance.create_storage_class(
s_class, storage_service_name=module.params["storage_service"]
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Storage Class {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def update_sc(module, fusion):
"""Update Storage Class settings"""
changed = False
sc_api_instance = purefusion.StorageClassesApi(fusion)
s_class = sc_api_instance.get_storage_class(
storage_class_name=module.params["name"],
storage_service_name=module.params["storage_service"],
)
if (
module.params["display_name"]
and module.params["display_name"] != s_class.display_name
):
changed = True
if not module.check_mode:
sclass = purefusion.StorageClassPatch(
display_name=purefusion.NullableString(module.params["display_name"])
)
try:
sc_api_instance.update_storage_class(
sclass,
storage_service_name=module.params["storage_service"],
storage_class_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(msg="Changing display_name failed: {0}".format(err))
module.exit_json(changed=changed)
def delete_sc(module, fusion):
"""Delete Storage Class"""
sc_api_instance = purefusion.StorageClassesApi(fusion)
changed = True
if not module.check_mode:
try:
sc_api_instance.delete_storage_class(
storage_class=module.params["name"],
storage_service_name=module.params["storage_service"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Storage Class {0} deletion failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
iops_limit=dict(type="str"),
bw_limit=dict(type="str"),
size_limit=dict(type="str"),
storage_service=dict(type="str"),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
s_class = get_sc(module, fusion)
if not s_class and not module.params["storage_service"]:
module.fail_json(
msg="`hardware_type` is required when creating a new Storage Class"
)
if module.params["storage_service"] and not get_ss(module, fusion):
module.fail_json(
msg="Storage Service Type {0} does not exist".format(
module.params["storage_service"]
)
)
if not s_class and state == "present":
create_sc(module, fusion)
elif s_class and state == "present":
update_sc(module, fusion)
elif s_class and state == "absent":
delete_sc(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,232 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_ss
version_added: '1.0.0'
short_description: Manage storage services in Pure Storage Fusion
description:
- Manage a storage services in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the storage service.
type: str
required: true
state:
description:
- Define whether the storage service should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the storage service.
- If not provided, defaults to I(name).
type: str
hardware_types:
description:
- Hardware types to which the storage service applies.
required: true
type: list
elements: str
choices: [ flash-array-x, flash-array-c, flash-array-x-optane, flash-array-xl ]
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new storage service foo
purestorage.fusion.fusion_ss:
name: foo
hardware_type:
- flash-array-x
- flash-array-x-optane
display_name: "test class"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Update storage service
purestorage.fusion.fusion_ss:
name: foo
display_name: "main class"
hardware_types:
- flash-array-c
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete storage service
purestorage.fusion.fusion_ss:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_ss(module, fusion):
"""Return Storage Service or None"""
ss_api_instance = purefusion.StorageServicesApi(fusion)
try:
return ss_api_instance.get_storage_service(
storage_service_name=module.params["name"]
)
except purefusion.rest.ApiException:
return None
def create_ss(module, fusion):
"""Create Storage Service"""
ss_api_instance = purefusion.StorageServicesApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
s_service = purefusion.StorageServicePost(
name=module.params["name"],
display_name=display_name,
hardware_types=module.params["hardware_types"],
)
ss_api_instance.create_storage_service(s_service)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Storage Service {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_ss(module, fusion):
"""Delete Storage Service"""
ss_api_instance = purefusion.StorageServicesApi(fusion)
changed = True
if not module.check_mode:
try:
ss_api_instance.delete_storage_service(
storage_service_name=module.params["name"]
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Storage Service {0} deletion failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def update_ss(module, fusion):
"""Update Storage Service"""
changed = False
ss_api_instance = purefusion.StorageServicesApi(fusion)
s_service = ss_api_instance.get_storage_service(
storage_service_name=module.params["name"],
)
hw_types = []
for hw_type in range(0, len(s_service.hardware_types)):
hw_types.append(s_service.hardware_types[hw_type].name)
if (
module.params["display_name"]
and module.params["display_name"] != s_service.display_name
):
changed = True
display_name = module.params["display_name"]
else:
display_name = s_service.display_name
if changed and not module.check_mode:
sservice = purefusion.StorageServicePatch(
display_name=purefusion.NullableString(display_name),
)
try:
ss_api_instance.update_storage_service(
sservice,
storage_service_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing storage service {0} failed. Error: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
hardware_types=dict(
type="list",
required=True,
elements="str",
choices=[
"flash-array-x",
"flash-array-c",
"flash-array-x-optane",
"flash-array-xl",
],
),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
s_service = get_ss(module, fusion)
if not s_service and state == "present":
create_ss(module, fusion)
elif s_service and state == "present":
update_ss(module, fusion)
elif s_service and state == "absent":
delete_ss(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,185 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_tenant
version_added: '1.0.0'
short_description: Manage tenants in Pure Storage Fusion
description:
- Create,delete or update a tenant in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the tenant.
type: str
required: true
state:
description:
- Define whether the tenant should exist or not.
default: present
choices: [ present, absent ]
type: str
display_name:
description:
- The human name of the tenant.
- If not provided, defaults to I(name).
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new tenat foo
purestorage.fusion.fusion_tenant:
name: foo
display_name: "tenant foo"
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete tenat foo
purestorage.fusion.fusion_tenant:
name: foo
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_tenant(module, fusion):
"""Return Tenant or None"""
api_instance = purefusion.TenantsApi(fusion)
try:
return api_instance.get_tenant(tenant_name=module.params["name"])
except purefusion.rest.ApiException:
return None
def create_tenant(module, fusion):
"""Create Tenant"""
api_instance = purefusion.TenantsApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
tenant = purefusion.TenantPost(
name=module.params["name"],
display_name=display_name,
)
api_instance.create_tenant(tenant)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Tenant {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def update_tenant(module, fusion):
"""Update Tenant settings"""
changed = False
api_instance = purefusion.TenantsApi(fusion)
tenant = api_instance.get_tenant(
tenant_name=module.params["name"],
)
if (
module.params["display_name"]
and module.params["display_name"] != tenant.display_name
):
changed = True
if not module.check_mode:
new_tenant = purefusion.TenantPatch(
display_name=purefusion.NullableString(module.params["display_name"]),
)
try:
api_instance.update_tenant(
new_tenant,
tenant_name=module.params["name"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing tenant display_name failed: {0}".format(err)
)
module.exit_json(changed=changed)
def delete_tenant(module, fusion):
"""Delete Tenant"""
changed = True
api_instance = purefusion.TenantsApi(fusion)
if not module.check_mode:
try:
api_instance.delete_tenant(tenant_name=module.params["name"])
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Deleting Tenant {0} failed: {1}".format(module.params["name"], err)
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
state=dict(type="str", default="present", choices=["present", "absent"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
fusion = get_fusion(module)
state = module.params["state"]
tenant = get_tenant(module, fusion)
if not tenant and state == "present":
create_tenant(module, fusion)
elif tenant and state == "present":
update_tenant(module, fusion)
elif tenant and state == "absent":
delete_tenant(module, fusion)
else:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,307 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_tn
version_added: '1.0.0'
short_description: Manage tenant networks in Pure Storage Fusion
description:
- Create or delete tenant networks in Pure Storage Fusion.
notes:
- Supports C(check_mode).
- Currently this only supports a single tenant subnet per tenant network.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
options:
name:
description:
- The name of the tenant network.
type: str
required: true
display_name:
description:
- The human name of the tenant network.
- If not provided, defaults to I(name).
type: str
state:
description:
- Define whether the tenant network should exist or not.
type: str
default: present
choices: [ absent, present ]
region:
description:
- The name of the region the availability zone is in
type: str
required: true
availability_zone:
aliases: [ az ]
description:
- The name of the availability zone for the tenant network.
type: str
required: true
provider_subnets:
description:
- List of provider subnets to assign to the tenant networks subnet.
type: list
elements: str
addresses:
description:
- List of IP addresses to be used in the subnet of the tenant network.
- IP addresses must include a CIDR notation.
- IPv4 and IPv6 are fully supported.
type: list
elements: str
gateway:
description:
- Address of the subnet gateway.
- Currently this must be provided.
type: str
mtu:
description:
- MTU setting for the subnet.
default: 1500
type: int
prefix:
description:
- Network prefix in CIDR format.
- This will be deprecated soon.
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new tenant network foo in AZ bar
purestorage.fusion.fusion_tn:
name: foo
availability_zone: bar
mtu: 9000
gateway: 10.21.200.1
addresses:
- 10.21.200.124/24
- 10.21.200.36/24
provider_subnets:
- subnet-0
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete tenant network foo in AZ bar
purestorage.fusion.fusion_tn:
name: foo
availability_zone: bar
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
try:
from netaddr import IPNetwork
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_ps(module, fusion):
"""Check all Provider Subnets"""
ps_api_instance = purefusion.ProviderSubnetsApi(fusion)
for subnet in range(0, len(module.params["provider_subnets"])):
try:
ps_api_instance.get_provider_subnet(
availability_zone_name=module.params["availability_zone"],
provider_subnet=module.params["provider_subnets"][subnet],
)
except purefusion.rest.ApiException:
return False
return True
def get_az(module, fusion):
"""Availability Zone or None"""
az_api_instance = purefusion.AvailabilityZonesApi(fusion)
try:
return az_api_instance.get_availability_zone(
availability_zone_name=module.params["availability_zone"],
region_name=module.params["region"],
)
except purefusion.rest.ApiException:
return None
def get_tn(module, fusion):
"""Tenant Network or None"""
api_instance = purefusion.TenantNetworksApi(fusion)
try:
return api_instance.get_tenant_network(
tenant_network=module.params["name"],
availability_zone_name=module.params["availability_zone"],
)
except purefusion.rest.ApiException:
return None
def create_tn(module, fusion):
"""Create Tenant Network"""
tn_api_instance = purefusion.TenantNetworksApi(fusion)
changed = True
if module.params["gateway"] and module.params["gateway"] not in IPNetwork(
module.params["prefix"]
):
module.fail_json(msg="Gateway and subnet prefix are not compatible.")
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
if module.params["gateway"]:
tsubnet = purefusion.TenantSubnetPost(
prefix=module.params["prefix"],
addresses=module.params["addresses"],
gateway=module.params["gateway"],
mtu=module.params["mtu"],
provider_subnets=module.params["provider_subnets"],
)
else:
tsubnet = purefusion.TenantSubnetPost(
prefix=module.params["prefix"],
addresses=module.params["addresses"],
mtu=module.params["mtu"],
provider_subnets=module.params["provider_subnets"],
)
tnet = purefusion.TenantNetworkPost(
tenant_subnets=[tsubnet],
name=module.params["name"],
display_name=display_name,
)
tn_api_instance.create_tenant_network(
tnet,
availability_zone_name=module.params["availability_zone"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Tenant Network {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_tn(module, fusion):
"""Delete Tenant Network"""
changed = True
tn_api_instance = purefusion.TenantNetworksApi(fusion)
if not module.check_mode:
try:
tn_api_instance.delete_tenant_network(
availability_zone_name=module.params["availability_zone"],
tenant_network=module.params["name"],
)
except purefusion.rest.ApiException:
module.fail_json(
msg="Delete Tenant Network {0} failed.".format(module.params["name"])
)
module.exit_json(changed=changed)
def update_tn(module, fusion, tenant_network):
"""Update Tenant Network"""
changed = False
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
region=dict(type="str", required=True),
display_name=dict(type="str"),
availability_zone=dict(type="str", required=True, aliases=["az"]),
prefix=dict(type="str"),
gateway=dict(type="str"),
mtu=dict(type="int", default=1500),
provider_subnets=dict(type="list", elements="str"),
addresses=dict(type="list", elements="str"),
state=dict(type="str", default="present", choices=["absent", "present"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
if not HAS_NETADDR:
module.fail_json(msg="netaddr module is required")
state = module.params["state"]
fusion = get_fusion(module)
if not get_az(module, fusion):
module.fail_json(msg="Availability Zone {0} does not exist")
if module.params["provider_subnets"] and not get_ps(module, fusion):
module.fail_json(
msg="Not all of the provider subnets exist in the specified AZ"
)
for address in range(0, len(module.params["addresses"])):
if "/" not in module.params["addresses"][address]:
module.fail_json(msg="All addresses must include a CIDR notation")
if 8 > int(module.params["addresses"][address].split("/")[1]) > 32:
module.fail_json(
msg="An invalid CIDR notation has been provided: {0}".format(
module.params["addresses"][address]
)
)
tnet = get_tn(module, fusion)
if state == "present" and not tnet:
if not (
module.params["addresses"]
and module.params["gateway"] # Soon to be optional
and module.params["prefix"] # To be removed soon
and module.params["provider_subnets"]
):
module.fail_json(
msg="When creating a new tenant network, the following "
"parameters must be supplied: `gateway`, `addresses`, `prefix` "
"and `provider_subnets`"
)
create_tn(module, fusion)
elif state == "present" and tnet:
update_tn(module, fusion, tnet)
elif state == "absent" and tnet:
delete_tn(module, fusion)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,178 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_ts
version_added: '1.0.0'
short_description: Manage tenant spaces in Pure Storage Fusion
description:
- Create, update or delete a tenant spaces in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the tenant space.
type: str
required: true
display_name:
description:
- The human name of the tenant space.
- If not provided, defaults to I(name).
type: str
state:
description:
- Define whether the tenant space should exist or not.
type: str
default: present
choices: [ absent, present ]
tenant:
description:
- The name of the tenant.
type: str
required: true
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new teanat space foo for tenany bar
purestorage.fusion.fusion_ts:
name: foo
tenant: bar
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete tenant space foo in tenant bar
purestorage.fusion.fusion_ts:
name: foo
tenant: bar
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def get_ts(module, fusion):
"""Tenant Space or None"""
ts_api_instance = purefusion.TenantSpacesApi(fusion)
try:
return ts_api_instance.get_tenant_space(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["name"],
)
except purefusion.rest.ApiException:
return None
def get_tenant(module, fusion):
"""Return Tenant or None"""
api_instance = purefusion.TenantsApi(fusion)
try:
return api_instance.get_tenant(tenant_name=module.params["tenant"])
except purefusion.rest.ApiException:
return None
def create_ts(module, fusion):
"""Create Tenant Space"""
ts_api_instance = purefusion.TenantSpacesApi(fusion)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
tspace = purefusion.TenantSpacePost(
name=module.params["name"],
display_name=display_name,
)
ts_api_instance.create_tenant_space(
tspace,
tenant_name=module.params["tenant"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Tenant Space {0} creation failed.: {1}".format(
module.params["name"], err
)
)
module.exit_json(changed=changed)
def delete_ts(module, fusion):
"""Delete Tenant Space"""
changed = True
ts_api_instance = purefusion.TenantSpacesApi(fusion)
if not module.check_mode:
try:
ts_api_instance.delete_tenant_space(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["name"],
)
except purefusion.rest.ApiException:
module.fail_json(
msg="Delete Tenant Space {0} failed.".format(module.params["name"])
)
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
tenant=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["absent", "present"]),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
state = module.params["state"]
fusion = get_fusion(module)
if not get_tenant(module, fusion):
module.fail_json(msg="Tenant {0} does not exist")
tspace = get_ts(module, fusion)
if state == "present" and not tspace:
create_ts(module, fusion)
elif state == "absent" and tspace:
delete_ts(module, fusion)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,648 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2022, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING.GPLv3 or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r"""
---
module: fusion_volume
version_added: '1.0.0'
short_description: Manage volumes in Pure Storage Fusion
description:
- Create, update or delete a volume in Pure Storage Fusion.
author:
- Pure Storage Ansible Team (@sdodsley) <pure-ansible-team@purestorage.com>
notes:
- Supports C(check mode).
options:
name:
description:
- The name of the volume.
type: str
required: true
display_name:
description:
- The human name of the volume.
- If not provided, defaults to I(name).
type: str
state:
description:
- Define whether the volume should exist or not.
type: str
default: present
choices: [ absent, present ]
tenant:
description:
- The name of the tenant.
type: str
required: true
tenant_space:
description:
- The name of the tenant space.
type: str
required: true
eradicate:
description:
- Define whether to eradicate the volume on delete or leave in trash.
type: bool
default: 'no'
size:
description:
- Volume size in M, G, T or P units.
type: str
storage_class:
description:
- The name of the storage class.
type: str
placement_group:
description:
- The name of the plcement group.
type: str
protection_policy:
description:
- The name of the protection policy.
type: str
hosts:
description:
- A list of host access policies to connect the volume to.
type: list
elements: str
rename:
description:
- New name for volume.
type: str
extends_documentation_fragment:
- purestorage.fusion.purestorage.fusion
"""
EXAMPLES = r"""
- name: Create new volume named foo in storage_class fred
purestorage.fusion.fusion_volume:
name: foo
storage_class: fred
size: 1T
tenant: test
tenant_space: space_1
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Extend the size of an existing volume named foo
purestorage.fusion.fusion_volume:
name: foo
size: 2T
tenant: test
tenant_space: space_1
state: present
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Rename volume named foo to bar
purestorage.fusion.fusion_volume:
name: foo
rename: bar
tenant: test
tenant_space: space_1
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
- name: Delete volume named foo
purestorage.fusion.fusion_volume:
name: foo
tenant: test
tenant_space: space_1
state: absent
app_id: key_name
key_file: "az-admin-private-key.pem"
"""
RETURN = r"""
"""
HAS_FUSION = True
try:
import fusion as purefusion
except ImportError:
HAS_FUSION = False
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.fusion.plugins.module_utils.fusion import (
get_fusion,
fusion_argument_spec,
)
def _check_hosts(module, fusion):
current_haps = []
hap_api_instance = purefusion.HostAccessPoliciesApi(fusion)
hosts = hap_api_instance.list_host_access_policies()
for host in range(0, len(hosts.items)):
current_haps.append(hosts.items[host].name)
if not (set(module.params["hosts"]).issubset(set(current_haps))):
module.fail_json(
msg="At least of of the speciied hosts does not currently exist"
)
def _check_target_volume(module, fusion):
vol_api_instance = purefusion.VolumesApi(fusion)
try:
vol_api_instance.get_volume(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
volume_name=module.params["rename"],
)
return True
except purefusion.rest.ApiException:
return False
def human_to_bytes(size):
"""Given a human-readable byte string (e.g. 2G, 30M),
return the number of bytes. Will return 0 if the argument has
unexpected form.
"""
my_bytes = size[:-1]
unit = size[-1].upper()
if my_bytes.isdigit():
my_bytes = int(my_bytes)
if unit == "P":
my_bytes *= 1125899906842624
elif unit == "T":
my_bytes *= 1099511627776
elif unit == "G":
my_bytes *= 1073741824
elif unit == "M":
my_bytes *= 1048576
elif unit == "K":
my_bytes *= 1024
else:
my_bytes = 0
else:
my_bytes = 0
return my_bytes
def bytes_to_human(bytes_number):
"""Convert bytes to a human readable string"""
if bytes_number:
labels = ["B", "KB", "MB", "GB", "TB", "PB"]
i = 0
double_bytes = bytes_number
while i < len(labels) and bytes_number >= 1024:
double_bytes = bytes_number / 1024.0
i += 1
bytes_number = bytes_number / 1024
return str(round(double_bytes, 2)) + " " + labels[i]
return None
def get_volume(module, fusion):
"""Return Volume or None"""
volume_api_instance = purefusion.VolumesApi(fusion)
try:
return volume_api_instance.get_volume(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
volume_name=module.params["name"],
)
except purefusion.rest.ApiException:
return None
def get_sc(module, fusion):
"""Return Storage Class or None"""
sc_api_instance = purefusion.StorageClassesApi(fusion)
try:
return sc_api_instance.get_storage_class(
storage_class_name=module.params["storage_class"]
)
except purefusion.rest.ApiException:
return None
def get_pg(module, fusion):
"""Return Placement Group or None"""
pg_api_instance = purefusion.PlacementGroupsApi(fusion)
try:
return pg_api_instance.get_placement_group(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
placement_group_name=module.params["placement_group"],
)
except purefusion.rest.ApiException:
return None
def get_pp(module, fusion):
"""Return Protection Policy or None"""
pp_api_instance = purefusion.ProtectionPoliciesApi(fusion)
try:
return pp_api_instance.get_protection_policy(
protection_policy_name=module.params["protection_policy"]
)
except purefusion.rest.ApiException:
return None
def get_destroyed_volume(module, fusion):
"""Return Destroyed Volume or None"""
vs_api_instance = purefusion.VolumeSnapshotsApi(fusion)
try:
return vs_api_instance.get_volume_snapshot(
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
except purefusion.rest.ApiException:
return False
def create_volume(module, fusion):
"""Create Volume"""
sc_api_instance = purefusion.StorageClassesApi(fusion)
vol_api_instance = purefusion.VolumesApi(fusion)
if not module.params["size"]:
module.fail_json(msg="Size for a new volume must be specified")
size = human_to_bytes(module.params["size"])
sc_size_limit = sc_api_instance.get_storage_class(
storage_class_name=module.params["storage_class"]
).size_limit
if size > sc_size_limit:
module.fail_json(
msg="Requested size {0} exceeds the storage class limit of {1}".format(
module.params["size"], bytes_to_human(sc_size_limit)
)
)
changed = True
if not module.check_mode:
if not module.params["display_name"]:
display_name = module.params["name"]
else:
display_name = module.params["display_name"]
try:
volume = purefusion.VolumePost(
size=size,
storage_class=module.params["storage_class"],
placement_group=module.params["placement_group"],
name=module.params["name"],
display_name=display_name,
)
vol_api_instance.create_volume(
volume,
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Volume {0} creation failed.: {1}".format(
module.params["name"], err
)
)
if module.params["hosts"]:
volume = purefusion.VolumePatch(
hosts=purefusion.NullableString(module.params["hosts"])
)
module.exit_json(changed=changed)
def update_volume(module, fusion):
"""Update Volume size, placement group, storage class, HAPs"""
changed = False
sc_api_instance = purefusion.StorageClassesApi(fusion)
vol_api_instance = purefusion.VolumesApi(fusion)
vol = vol_api_instance.get_volume(
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
volume_name=module.params["name"],
)
hosts = []
if vol.hosts:
for host in range(0, len(vol.hosts)):
hosts.append(vol.hosts[host].name)
current_vol = {
"size": vol.size,
"hosts": list(dict.fromkeys(hosts)),
"placement_group": vol.placement_group.name,
"protection_policy": getattr(vol.protection_policy, "name", None),
"storage_class": vol.storage_class.name,
"display_name": vol.display_name,
}
new_vol = {
"size": vol.size,
"hosts": list(dict.fromkeys(hosts)),
"placement_group": vol.placement_group.name,
"protection_policy": getattr(vol.protection_policy, "name", None),
"storage_class": vol.storage_class.name,
"display_name": vol.display_name,
}
if (
module.params["storage_class"]
and module.params["storage_class"] != current_vol["storage_class"]
):
new_vol["storage_class"] = module.params["storage_class"]
if (
module.params["size"]
and human_to_bytes(module.params["size"]) != current_vol["size"]
):
if human_to_bytes(module.params["size"]) > current_vol["size"]:
new_vol["size"] = human_to_bytes(module.params["size"])
sc_size_limit = sc_api_instance.get_storage_class(
storage_class_name=new_vol["storage_class"]
).size_limit
if new_vol["size"] > sc_size_limit:
module.fail_json(
msg="Volume size {0} exceeds the storage class limit of {1}".format(
new_vol["size"], sc_size_limit
)
)
if not module.params["size"] and module.params["storage_class"]:
sc_size_limit = sc_api_instance.get_storage_class(
storage_class_name=new_vol["storage_class"]
).size_limit
if current_vol["size"] > sc_size_limit:
module.fail_json(
msg="Volume size {0} exceeds the storage class limit of {1}".format(
new_vol["size"], sc_size_limit
)
)
if (
module.params["placement_group"]
and module.params["placement_group"] != current_vol["placement_group"]
):
new_vol["protection_group"] = module.params["placement_group"]
if (
module.params["protection_policy"]
and module.params["protection_policy"] != current_vol["protection_policy"]
):
new_vol["protection_policy"] = module.params["protection_policy"]
if (
module.params["display_name"]
and module.params["display_name"] != current_vol["display_name"]
):
new_vol["display_name"] = module.params["display_name"]
if (new_vol != current_vol) or module.params["hosts"]:
changed = False
if not module.check_mode:
# PATCH is atomic so has to pass or fail, therefore only one item
# can be changed at a time
if new_vol["display_name"] != current_vol["display_name"]:
volume = purefusion.VolumePatch(
display_name=purefusion.NullableString(new_vol["display_name"])
)
try:
res = vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing display_name failed: {0}".format(err)
)
if new_vol["storage_class"] != current_vol["storage_class"]:
volume = purefusion.VolumePatch(
storage_class=purefusion.NullableString(new_vol["storage_class"])
)
try:
res = vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing storage_class failed: {0}".format(err)
)
if new_vol["size"] != current_vol["size"]:
volume = purefusion.VolumePatch(
size=purefusion.NullableSize(new_vol["size"])
)
try:
res = vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(msg="Changing size failed: {0}".format(err))
if new_vol["placement_group"] != current_vol["placement_group"]:
volume = purefusion.VolumePatch(
placement_group=purefusion.NullableString(
new_vol["placement_group"]
)
)
try:
res = vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing placement_group failed: {0}".format(err)
)
if new_vol["protection_policy"] != current_vol["protection_policy"]:
volume = purefusion.VolumePatch(
protection_policy=purefusion.NullableString(
new_vol["protection_policy"]
)
)
try:
vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(
msg="Changing protection_policy failed: {0}".format(err)
)
if module.params["hosts"]:
if not new_vol["hosts"]:
new_vol["hosts"] = []
for host in module.params["hosts"]:
if module.params["state"] == "absent":
if new_vol["hosts"]:
new_vol["hosts"].remove(host)
else:
new_vol["hosts"].append(host)
new_vol["hosts"] = list(dict.fromkeys(new_vol["hosts"]))
if new_vol["hosts"] != current_vol["hosts"]:
volume = purefusion.VolumePatch(
hosts=purefusion.NullableString(",".join(new_vol["hosts"]))
)
try:
vol_api_instance.update_volume(
volume,
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
changed = True
except purefusion.rest.ApiException as err:
module.fail_json(msg="Changing hosts failed: {0}".format(err))
module.exit_json(changed=changed)
def delete_volume(module, fusion):
"""Delete Volume"""
changed = True
vol_api_instance = purefusion.VolumesApi(fusion)
if not module.check_mode:
try:
vol_api_instance.delete_volume(
volume_name=module.params["name"],
tenant_name=module.params["tenant"],
tenant_space_name=module.params["tenant_space"],
)
if module.params["eradicate"]:
try:
pass
# eradicate_volume(module, array)
except Exception:
module.fail_json(
msg="Eradicate volume {0} failed.".format(module.params["name"])
)
except purefusion.rest.ApiException:
module.fail_json(
msg="Delete volume {0} failed.".format(module.params["name"])
)
module.exit_json(changed=changed)
def eradicate_volume(module, array):
"""Eradicate Deleted Volume"""
changed = True
if not module.check_mode:
try:
array.eradicate_volume(module.params["name"])
except Exception:
module.fail_json(
msg="Eradication of volume {0} failed".format(module.params["name"])
)
module.exit_json(changed=changed)
def recover_volume(module, array):
"""Recover Deleted Volume"""
changed = True
module.warn("Volume recovery not yet supported")
# if not module.check_mode:
# try:
# array.recover_volume(module.params["name"])
# except Exception:
# module.fail_json(
# msg="Recovery of volume {0} failed".format(module.params["name"])
# )
module.exit_json(changed=changed)
def main():
"""Main code"""
argument_spec = fusion_argument_spec()
argument_spec.update(
dict(
name=dict(type="str", required=True),
display_name=dict(type="str"),
rename=dict(type="str"),
tenant=dict(type="str", required=True),
tenant_space=dict(type="str", required=True),
placement_group=dict(type="str"),
storage_class=dict(type="str"),
protection_policy=dict(type="str"),
hosts=dict(type="list", elements="str"),
eradicate=dict(type="bool", default=False),
state=dict(type="str", default="present", choices=["absent", "present"]),
size=dict(type="str"),
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
size = module.params["size"]
state = module.params["state"]
destroyed = False
fusion = get_fusion(module)
volume = get_volume(module, fusion)
if module.params["rename"] and _check_target_volume(module, fusion):
module.fail_json(
msg="Taerget volume name {0} already exists".format(module.params["rename"])
)
if not volume and not (
module.params["storage_class"] and module.params["placement_group"]
):
module.fail_json(
msg="`storage_class` and `placement_group` are required when creating a new volume"
)
if module.params["hosts"]:
_check_hosts(module, fusion)
if module.params["storage_class"] and not get_sc(module, fusion):
module.fail_json(
msg="Storage Class {0} does not exist".format(
module.params["storage_class"]
)
)
if module.params["placement_group"] and not get_pg(module, fusion):
module.fail_json(
msg="Placement Group {0} does not exist in the provide "
"tenant and tenant name space".format(module.params["placement_group"])
)
if module.params["protection_policy"] and not get_pp(module, fusion):
module.fail_json(
msg="Protection Policy {0} does not exist".format(
module.params["protection_policy"]
)
)
# if not volume:
# destroyed = get_destroyed_volume(module, fusion)
if state == "present" and not volume and not destroyed and size:
create_volume(module, fusion)
elif (state == "present" and volume) or (
state == "absent" and volume and module.params["hosts"]
):
update_volume(module, fusion)
elif state == "absent" and volume and not module.params["hosts"]:
delete_volume(module, fusion)
elif state == "absent" and destroyed:
eradicate_volume(module, fusion)
elif state == "present":
if not volume and not size:
module.fail_json(msg="Size must be specified to create a new volume")
elif state == "absent" and not volume:
module.exit_json(changed=False)
module.exit_json(changed=False)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,2 @@
netaddr
purefusion