remove vendored code

Change-Id: I47de33db8e993b900efd3b00691325856e1d4f85
This commit is contained in:
Davanum Srinivas
2019-06-10 12:55:00 -04:00
parent e0821ca3dd
commit bf76df3c64
121 changed files with 0 additions and 79218 deletions

687
Godeps/LICENSES generated
View File

@@ -3932,402 +3932,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================================================
================================================================================
= vendor/github.com/d2g/dhcp4 licensed under: =
Copyright (c) 2013 Skagerrak Software Limited. 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.
* Neither the name of Skagerrak Software Limited nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
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
OWNER 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.
= vendor/github.com/d2g/dhcp4/LICENSE 0187683301a45e8ea393bb2ffd7889c8
================================================================================
================================================================================
= vendor/github.com/d2g/dhcp4client licensed under: =
Mozilla Public License, version 2.0
1. Definitions
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributors Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. “Incompatible With Secondary Licenses”
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of version
1.1 or earlier of the License, but not also under the terms of a
Secondary License.
1.6. “Executable Form”
means any form of the work other than Source Code Form.
1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate
file or files, that is not Covered Software.
1.8. “License”
means this document.
1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the
time of the initial grant or subsequently, any and all of the rights conveyed by
this License.
1.10. “Modifications”
means any of the following:
a. any file in Source Code Form that results from an addition to, deletion
from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process,
and apparatus claims, in any patent Licensable by such Contributor that
would be infringed, but for the grant of the License, by the making,
using, selling, offering for sale, having made, import, or transfer of
either its Contributions or its Contributor Version.
1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. “Source Code Form”
means the form of the work preferred for making modifications.
1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this
License. For legal entities, “You” includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, “control” means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or as
part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its Contributions
or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution become
effective for each Contribution on the date the Contributor first distributes
such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under this
License. No additional rights or licenses will be implied from the distribution
or licensing of Covered Software under this License. Notwithstanding Section
2.1(b) above, no patent license is granted by a Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third partys
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of its
Contributions.
This License does not grant any rights in the trademarks, service marks, or
logos of any Contributor (except as may be necessary to comply with the
notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this License
(see Section 10.2) or under the terms of a Secondary License (if permitted
under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its Contributions
are its original creation(s) or it has sufficient rights to grant the
rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under applicable
copyright doctrines of fair use, fair dealing, or other equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under the
terms of this License. You must inform recipients that the Source Code Form
of the Covered Software is governed by the terms of this License, and how
they can obtain a copy of this License. You may not attempt to alter or
restrict the recipients rights in the Source Code Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this License,
or sublicense it under different terms, provided that the license for
the Executable Form does not attempt to limit or alter the recipients
rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for the
Covered Software. If the Larger Work is a combination of Covered Software
with a work governed by one or more Secondary Licenses, and the Covered
Software is not Incompatible With Secondary Licenses, this License permits
You to additionally distribute such Covered Software under the terms of
such Secondary License(s), so that the recipient of the Larger Work may, at
their option, further distribute the Covered Software under the terms of
either this License or such Secondary License(s).
3.4. Notices
You may not remove or alter the substance of any license notices (including
copyright notices, patent notices, disclaimers of warranty, or limitations
of liability) contained within the Source Code Form of the Covered
Software, except that You may alter any license notices to the extent
required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on behalf
of any Contributor. You must make it absolutely clear that any such
warranty, support, indemnity, or liability obligation is offered by You
alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute, judicial
order, or regulation then You must: (a) comply with the terms of this License
to the maximum extent possible; and (b) describe the limitations and the code
they affect. Such description must be placed in a text file included with all
distributions of the Covered Software under this License. Except to the
extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to
understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
if such Contributor fails to notify You of the non-compliance by some
reasonable means prior to 60 days after You have come back into compliance.
Moreover, Your grants from a particular Contributor are reinstated on an
ongoing basis if such Contributor notifies You of the non-compliance by
some reasonable means, this is the first time You have received notice of
non-compliance with this License from such Contributor, and You become
compliant prior to 30 days after Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions, counter-claims,
and cross-claims) alleging that a Contributor Version directly or
indirectly infringes any patent, then the rights granted to You by any and
all Contributors for the Covered Software under Section 2.1 of this License
shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an “as is” basis, without
warranty of any kind, either expressed, implied, or statutory, including,
without limitation, warranties that the Covered Software is free of defects,
merchantable, fit for a particular purpose or non-infringing. The entire
risk as to the quality and performance of the Covered Software is with You.
Should any Covered Software prove defective in any respect, You (not any
Contributor) assume the cost of any necessary servicing, repair, or
correction. This disclaimer of warranty constitutes an essential part of this
License. No use of any Covered Software is authorized under this License
except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from such
partys negligence to the extent applicable law prohibits such limitation.
Some jurisdictions do not allow the exclusion or limitation of incidental or
consequential damages, so this exclusion and limitation may not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts of
a jurisdiction where the defendant maintains its principal place of business
and such litigation shall be governed by laws of that jurisdiction, without
reference to its conflict-of-law provisions. Nothing in this Section shall
prevent a partys ability to bring cross-claims or counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject matter
hereof. If any provision of this License is held to be unenforceable, such
provision shall be reformed only to the extent necessary to make it
enforceable. Any law or regulation which provides that the language of a
contract shall be construed against the drafter shall not be used to construe
this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version of
the License under which You originally received the Covered Software, or
under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a modified
version of this License if you rename the license and remove any
references to the name of the license steward (except to note that such
modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a relevant
directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - “Incompatible With Secondary Licenses” Notice
This Source Code Form is “Incompatible
With Secondary Licenses”, as defined by
the Mozilla Public License, v. 2.0.
= vendor/github.com/d2g/dhcp4client/LICENSE b278a92d2c1509760384428817710378
================================================================================
================================================================================
= vendor/github.com/davecgh/go-spew licensed under: =
@@ -18390,297 +17994,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
================================================================================
================================================================================
= vendor/github.com/vmware/photon-controller-go-sdk licensed under: =
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
= vendor/github.com/vmware/photon-controller-go-sdk/LICENSE 0de60303c844eac44e45012dac1987de
================================================================================
================================================================================
= vendor/github.com/xanzy/go-cloudstack licensed under: =
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
= vendor/github.com/xanzy/go-cloudstack/LICENSE 136e4f49dbf29942c572a3a8f6e88a77
================================================================================
================================================================================
= vendor/github.com/xiang90/probing licensed under: =

4
go.mod
View File

@@ -43,8 +43,6 @@ require (
github.com/coreos/rkt v1.30.0 // indirect
github.com/cpuguy83/go-md2man v1.0.4
github.com/cyphar/filepath-securejoin v0.0.0-20170720062807-ae69057f2299 // indirect
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c
github.com/d2g/dhcp4client v0.0.0-20170829104524-6e570ed0a266
github.com/davecgh/go-spew v1.1.1
github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd
github.com/docker/distribution v0.0.0-20170726174610-edc3ab29cdff
@@ -148,8 +146,6 @@ require (
github.com/vishvananda/netlink v0.0.0-20171020171820-b2de5d10e38e
github.com/vishvananda/netns v0.0.0-20171111001504-be1fbeda1936 // indirect
github.com/vmware/govmomi v0.20.1
github.com/vmware/photon-controller-go-sdk v0.0.0-20170310013346-4a435daef6cc
github.com/xanzy/go-cloudstack v0.0.0-20160728180336-1e2cbf647e57
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 // indirect
golang.org/x/crypto v0.0.0-20181025213731-e84da0312774
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1

8
go.sum
View File

@@ -89,10 +89,6 @@ github.com/cpuguy83/go-md2man v1.0.4 h1:OwjhDpK9YGCcI5CDf8HcdfsXqr6znFyAJfuZ27ix
github.com/cpuguy83/go-md2man v1.0.4/go.mod h1:N6JayAiVKtlHSnuTCeuLSQVs75hb8q+dYQLjr7cDsKY=
github.com/cyphar/filepath-securejoin v0.0.0-20170720062807-ae69057f2299 h1:2pOMM/RaFhI52FyCITl8aTf5HZ9LoHD8SkjbghAEG1E=
github.com/cyphar/filepath-securejoin v0.0.0-20170720062807-ae69057f2299/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c h1:Xo2rK1pzOm0jO6abTPIQwbAmqBIOj132otexc1mmzFc=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=
github.com/d2g/dhcp4client v0.0.0-20170829104524-6e570ed0a266 h1:1iKpuOrCnaRBKKNoChzmVDXeoFuCS7wsooRncvzVPxo=
github.com/d2g/dhcp4client v0.0.0-20170829104524-6e570ed0a266/go.mod h1:j0hNfjhrt2SxUOw55nL0ATM/z4Yt3t2Kd1mW34z5W5s=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd h1:uVsMphB1eRx7xB1njzL3fuMdWRN8HtVzoUOItHMwv5c=
@@ -388,10 +384,6 @@ github.com/vishvananda/netns v0.0.0-20171111001504-be1fbeda1936 h1:J9gO8RJCAFlln
github.com/vishvananda/netns v0.0.0-20171111001504-be1fbeda1936/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
github.com/vmware/govmomi v0.20.1 h1:7b/SeTUB3tER8ZLGLLLH3xcnB2xeuLULXmfPFqPSRZA=
github.com/vmware/govmomi v0.20.1/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/vmware/photon-controller-go-sdk v0.0.0-20170310013346-4a435daef6cc h1:uyYiBHCUWsifUdIWrBzUUq9B3FSZKFTAuUyMQczS1q8=
github.com/vmware/photon-controller-go-sdk v0.0.0-20170310013346-4a435daef6cc/go.mod h1:e6humHha1ekIwTCm+A5Qed5mG8V4JL+ChHcUOJ+L/8U=
github.com/xanzy/go-cloudstack v0.0.0-20160728180336-1e2cbf647e57 h1:3OK6oXqbbEUeWvTJgg1pZgNjzdCNE6hMu2TragCfwb8=
github.com/xanzy/go-cloudstack v0.0.0-20160728180336-1e2cbf647e57/go.mod h1:s3eL3z5pNXF5FVybcT+LIVdId8pYn709yv6v5mrkrQE=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 h1:j2hhcujLRHAg872RWAV5yaUrEjHEObwDv3aImCaNLek=

5
vendor/BUILD vendored
View File

@@ -151,8 +151,6 @@ filegroup(
"//vendor/github.com/coreos/pkg/dlopen:all-srcs",
"//vendor/github.com/cpuguy83/go-md2man/md2man:all-srcs",
"//vendor/github.com/cyphar/filepath-securejoin:all-srcs",
"//vendor/github.com/d2g/dhcp4:all-srcs",
"//vendor/github.com/d2g/dhcp4client:all-srcs",
"//vendor/github.com/davecgh/go-spew/spew:all-srcs",
"//vendor/github.com/daviddengcn/go-colortext:all-srcs",
"//vendor/github.com/dgrijalva/jwt-go:all-srcs",
@@ -352,9 +350,6 @@ filegroup(
"//vendor/github.com/vishvananda/netlink:all-srcs",
"//vendor/github.com/vishvananda/netns:all-srcs",
"//vendor/github.com/vmware/govmomi:all-srcs",
"//vendor/github.com/vmware/photon-controller-go-sdk/SSPI:all-srcs",
"//vendor/github.com/vmware/photon-controller-go-sdk/photon:all-srcs",
"//vendor/github.com/xanzy/go-cloudstack/cloudstack:all-srcs",
"//vendor/github.com/xiang90/probing:all-srcs",
"//vendor/go.uber.org/atomic:all-srcs",
"//vendor/go.uber.org/multierr:all-srcs",

28
vendor/github.com/d2g/dhcp4/BUILD generated vendored
View File

@@ -1,28 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"constants.go",
"helpers.go",
"option.go",
"packet.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/d2g/dhcp4",
importpath = "github.com/d2g/dhcp4",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

27
vendor/github.com/d2g/dhcp4/LICENSE generated vendored
View File

@@ -1,27 +0,0 @@
Copyright (c) 2013 Skagerrak Software Limited. 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.
* Neither the name of Skagerrak Software Limited nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
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
OWNER 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.

View File

@@ -1,5 +0,0 @@
# DHCP4 - A DHCP library written in Go.
Warning: This library is still being developed. Function calls will change.
I've removed Server Functionality, for me this project supports the underlying DHCP format not the implementation.

View File

@@ -1,121 +0,0 @@
package dhcp4
// OpCodes
const (
BootRequest OpCode = 1 // From Client
BootReply OpCode = 2 // From Server
)
// DHCP Message Type 53
const (
Discover MessageType = 1 // Broadcast Packet From Client - Can I have an IP?
Offer MessageType = 2 // Broadcast From Server - Here's an IP
Request MessageType = 3 // Broadcast From Client - I'll take that IP (Also start for renewals)
Decline MessageType = 4 // Broadcast From Client - Sorry I can't use that IP
ACK MessageType = 5 // From Server, Yes you can have that IP
NAK MessageType = 6 // From Server, No you cannot have that IP
Release MessageType = 7 // From Client, I don't need that IP anymore
Inform MessageType = 8 // From Client, I have this IP and there's nothing you can do about it
)
// DHCP Options
const (
End OptionCode = 255
Pad OptionCode = 0
OptionSubnetMask OptionCode = 1
OptionTimeOffset OptionCode = 2
OptionRouter OptionCode = 3
OptionTimeServer OptionCode = 4
OptionNameServer OptionCode = 5
OptionDomainNameServer OptionCode = 6
OptionLogServer OptionCode = 7
OptionCookieServer OptionCode = 8
OptionLPRServer OptionCode = 9
OptionImpressServer OptionCode = 10
OptionResourceLocationServer OptionCode = 11
OptionHostName OptionCode = 12
OptionBootFileSize OptionCode = 13
OptionMeritDumpFile OptionCode = 14
OptionDomainName OptionCode = 15
OptionSwapServer OptionCode = 16
OptionRootPath OptionCode = 17
OptionExtensionsPath OptionCode = 18
// IP Layer Parameters per Host
OptionIPForwardingEnableDisable OptionCode = 19
OptionNonLocalSourceRoutingEnableDisable OptionCode = 20
OptionPolicyFilter OptionCode = 21
OptionMaximumDatagramReassemblySize OptionCode = 22
OptionDefaultIPTimeToLive OptionCode = 23
OptionPathMTUAgingTimeout OptionCode = 24
OptionPathMTUPlateauTable OptionCode = 25
// IP Layer Parameters per Interface
OptionInterfaceMTU OptionCode = 26
OptionAllSubnetsAreLocal OptionCode = 27
OptionBroadcastAddress OptionCode = 28
OptionPerformMaskDiscovery OptionCode = 29
OptionMaskSupplier OptionCode = 30
OptionPerformRouterDiscovery OptionCode = 31
OptionRouterSolicitationAddress OptionCode = 32
OptionStaticRoute OptionCode = 33
// Link Layer Parameters per Interface
OptionTrailerEncapsulation OptionCode = 34
OptionARPCacheTimeout OptionCode = 35
OptionEthernetEncapsulation OptionCode = 36
// TCP Parameters
OptionTCPDefaultTTL OptionCode = 37
OptionTCPKeepaliveInterval OptionCode = 38
OptionTCPKeepaliveGarbage OptionCode = 39
// Application and Service Parameters
OptionNetworkInformationServiceDomain OptionCode = 40
OptionNetworkInformationServers OptionCode = 41
OptionNetworkTimeProtocolServers OptionCode = 42
OptionVendorSpecificInformation OptionCode = 43
OptionNetBIOSOverTCPIPNameServer OptionCode = 44
OptionNetBIOSOverTCPIPDatagramDistributionServer OptionCode = 45
OptionNetBIOSOverTCPIPNodeType OptionCode = 46
OptionNetBIOSOverTCPIPScope OptionCode = 47
OptionXWindowSystemFontServer OptionCode = 48
OptionXWindowSystemDisplayManager OptionCode = 49
OptionNetworkInformationServicePlusDomain OptionCode = 64
OptionNetworkInformationServicePlusServers OptionCode = 65
OptionMobileIPHomeAgent OptionCode = 68
OptionSimpleMailTransportProtocol OptionCode = 69
OptionPostOfficeProtocolServer OptionCode = 70
OptionNetworkNewsTransportProtocol OptionCode = 71
OptionDefaultWorldWideWebServer OptionCode = 72
OptionDefaultFingerServer OptionCode = 73
OptionDefaultInternetRelayChatServer OptionCode = 74
OptionStreetTalkServer OptionCode = 75
OptionStreetTalkDirectoryAssistance OptionCode = 76
// DHCP Extensions
OptionRequestedIPAddress OptionCode = 50
OptionIPAddressLeaseTime OptionCode = 51
OptionOverload OptionCode = 52
OptionDHCPMessageType OptionCode = 53
OptionServerIdentifier OptionCode = 54
OptionParameterRequestList OptionCode = 55
OptionMessage OptionCode = 56
OptionMaximumDHCPMessageSize OptionCode = 57
OptionRenewalTimeValue OptionCode = 58
OptionRebindingTimeValue OptionCode = 59
OptionVendorClassIdentifier OptionCode = 60
OptionClientIdentifier OptionCode = 61
OptionTFTPServerName OptionCode = 66
OptionBootFileName OptionCode = 67
OptionUserClass OptionCode = 77
OptionClientArchitecture OptionCode = 93
OptionTZPOSIXString OptionCode = 100
OptionTZDatabaseString OptionCode = 101
OptionClasslessRouteFormat OptionCode = 121
)

View File

@@ -1,58 +0,0 @@
package dhcp4
import (
"encoding/binary"
"net"
"time"
)
// IPRange returns how many ips in the ip range from start to stop (inclusive)
func IPRange(start, stop net.IP) int {
//return int(Uint([]byte(stop))-Uint([]byte(start))) + 1
return int(binary.BigEndian.Uint32(stop.To4())) - int(binary.BigEndian.Uint32(start.To4())) + 1
}
// IPAdd returns a copy of start + add.
// IPAdd(net.IP{192,168,1,1},30) returns net.IP{192.168.1.31}
func IPAdd(start net.IP, add int) net.IP { // IPv4 only
start = start.To4()
//v := Uvarint([]byte(start))
result := make(net.IP, 4)
binary.BigEndian.PutUint32(result, binary.BigEndian.Uint32(start)+uint32(add))
//PutUint([]byte(result), v+uint64(add))
return result
}
// IPLess returns where IP a is less than IP b.
func IPLess(a, b net.IP) bool {
b = b.To4()
for i, ai := range a.To4() {
if ai != b[i] {
return ai < b[i]
}
}
return false
}
// IPInRange returns true if ip is between (inclusive) start and stop.
func IPInRange(start, stop, ip net.IP) bool {
return !(IPLess(ip, start) || IPLess(stop, ip))
}
// OptionsLeaseTime - converts a time.Duration to a 4 byte slice, compatible
// with OptionIPAddressLeaseTime.
func OptionsLeaseTime(d time.Duration) []byte {
leaseBytes := make([]byte, 4)
binary.BigEndian.PutUint32(leaseBytes, uint32(d/time.Second))
//PutUvarint(leaseBytes, uint64(d/time.Second))
return leaseBytes
}
// JoinIPs returns a byte slice of IP addresses, one immediately after the other
// This may be useful for creating multiple IP options such as OptionRouter.
func JoinIPs(ips []net.IP) (b []byte) {
for _, v := range ips {
b = append(b, v.To4()...)
}
return
}

View File

@@ -1,40 +0,0 @@
package dhcp4
type OptionCode byte
type Option struct {
Code OptionCode
Value []byte
}
// Map of DHCP options
type Options map[OptionCode][]byte
// SelectOrderOrAll has same functionality as SelectOrder, except if the order
// param is nil, whereby all options are added (in arbitrary order).
func (o Options) SelectOrderOrAll(order []byte) []Option {
if order == nil {
opts := make([]Option, 0, len(o))
for i, v := range o {
opts = append(opts, Option{Code: i, Value: v})
}
return opts
}
return o.SelectOrder(order)
}
// SelectOrder returns a slice of options ordered and selected by a byte array
// usually defined by OptionParameterRequestList. This result is expected to be
// used in ReplyPacket()'s []Option parameter.
func (o Options) SelectOrder(order []byte) []Option {
opts := make([]Option, 0, len(order))
for _, v := range order {
if data, ok := o[OptionCode(v)]; ok {
opts = append(opts, Option{Code: OptionCode(v), Value: data})
}
}
return opts
}
type OpCode byte
type MessageType byte // Option 53

150
vendor/github.com/d2g/dhcp4/packet.go generated vendored
View File

@@ -1,150 +0,0 @@
package dhcp4
import (
"net"
"time"
)
// A DHCP packet
type Packet []byte
func (p Packet) OpCode() OpCode { return OpCode(p[0]) }
func (p Packet) HType() byte { return p[1] }
func (p Packet) HLen() byte { return p[2] }
func (p Packet) Hops() byte { return p[3] }
func (p Packet) XId() []byte { return p[4:8] }
func (p Packet) Secs() []byte { return p[8:10] } // Never Used?
func (p Packet) Flags() []byte { return p[10:12] }
func (p Packet) CIAddr() net.IP { return net.IP(p[12:16]) }
func (p Packet) YIAddr() net.IP { return net.IP(p[16:20]) }
func (p Packet) SIAddr() net.IP { return net.IP(p[20:24]) }
func (p Packet) GIAddr() net.IP { return net.IP(p[24:28]) }
func (p Packet) CHAddr() net.HardwareAddr {
hLen := p.HLen()
if hLen > 16 { // Prevent chaddr exceeding p boundary
hLen = 16
}
return net.HardwareAddr(p[28 : 28+hLen]) // max endPos 44
}
// 192 bytes of zeros BOOTP legacy
func (p Packet) Cookie() []byte { return p[236:240] }
func (p Packet) Options() []byte {
if len(p) > 240 {
return p[240:]
}
return nil
}
func (p Packet) Broadcast() bool { return p.Flags()[0] > 127 }
func (p Packet) SetBroadcast(broadcast bool) {
if p.Broadcast() != broadcast {
p.Flags()[0] ^= 128
}
}
func (p Packet) SetOpCode(c OpCode) { p[0] = byte(c) }
func (p Packet) SetCHAddr(a net.HardwareAddr) {
copy(p[28:44], a)
p[2] = byte(len(a))
}
func (p Packet) SetHType(hType byte) { p[1] = hType }
func (p Packet) SetCookie(cookie []byte) { copy(p.Cookie(), cookie) }
func (p Packet) SetHops(hops byte) { p[3] = hops }
func (p Packet) SetXId(xId []byte) { copy(p.XId(), xId) }
func (p Packet) SetSecs(secs []byte) { copy(p.Secs(), secs) }
func (p Packet) SetFlags(flags []byte) { copy(p.Flags(), flags) }
func (p Packet) SetCIAddr(ip net.IP) { copy(p.CIAddr(), ip.To4()) }
func (p Packet) SetYIAddr(ip net.IP) { copy(p.YIAddr(), ip.To4()) }
func (p Packet) SetSIAddr(ip net.IP) { copy(p.SIAddr(), ip.To4()) }
func (p Packet) SetGIAddr(ip net.IP) { copy(p.GIAddr(), ip.To4()) }
// Parses the packet's options into an Options map
func (p Packet) ParseOptions() Options {
opts := p.Options()
options := make(Options, 10)
for len(opts) >= 2 && OptionCode(opts[0]) != End {
if OptionCode(opts[0]) == Pad {
opts = opts[1:]
continue
}
size := int(opts[1])
if len(opts) < 2+size {
break
}
options[OptionCode(opts[0])] = opts[2 : 2+size]
opts = opts[2+size:]
}
return options
}
func NewPacket(opCode OpCode) Packet {
p := make(Packet, 241)
p.SetOpCode(opCode)
p.SetHType(1) // Ethernet
p.SetCookie([]byte{99, 130, 83, 99})
p[240] = byte(End)
return p
}
// Appends a DHCP option to the end of a packet
func (p *Packet) AddOption(o OptionCode, value []byte) {
*p = append((*p)[:len(*p)-1], []byte{byte(o), byte(len(value))}...) // Strip off End, Add OptionCode and Length
*p = append(*p, value...) // Add Option Value
*p = append(*p, byte(End)) // Add on new End
}
// Removes all options from packet.
func (p *Packet) StripOptions() {
*p = append((*p)[:240], byte(End))
}
// Creates a request packet that a Client would send to a server.
func RequestPacket(mt MessageType, chAddr net.HardwareAddr, cIAddr net.IP, xId []byte, broadcast bool, options []Option) Packet {
p := NewPacket(BootRequest)
p.SetCHAddr(chAddr)
p.SetXId(xId)
if cIAddr != nil {
p.SetCIAddr(cIAddr)
}
p.SetBroadcast(broadcast)
p.AddOption(OptionDHCPMessageType, []byte{byte(mt)})
for _, o := range options {
p.AddOption(o.Code, o.Value)
}
p.PadToMinSize()
return p
}
// ReplyPacket creates a reply packet that a Server would send to a client.
// It uses the req Packet param to copy across common/necessary fields to
// associate the reply the request.
func ReplyPacket(req Packet, mt MessageType, serverId, yIAddr net.IP, leaseDuration time.Duration, options []Option) Packet {
p := NewPacket(BootReply)
p.SetXId(req.XId())
p.SetFlags(req.Flags())
p.SetYIAddr(yIAddr)
p.SetGIAddr(req.GIAddr())
p.SetCHAddr(req.CHAddr())
p.AddOption(OptionDHCPMessageType, []byte{byte(mt)})
p.AddOption(OptionServerIdentifier, []byte(serverId))
if leaseDuration > 0 {
p.AddOption(OptionIPAddressLeaseTime, OptionsLeaseTime(leaseDuration))
}
for _, o := range options {
p.AddOption(o.Code, o.Value)
}
p.PadToMinSize()
return p
}
// PadToMinSize pads a packet so that when sent over UDP, the entire packet,
// is 300 bytes (BOOTP min), to be compatible with really old devices.
var padder [272]byte
func (p *Packet) PadToMinSize() {
if n := len(*p); n < 272 {
*p = append(*p, padder[:272-n]...)
}
}

View File

@@ -1,36 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"client.go",
"generatexid.go",
"inetsock.go",
"pktsock_linux.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/d2g/dhcp4client",
importpath = "github.com/d2g/dhcp4client",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/d2g/dhcp4:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:linux": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"//conditions:default": [],
}),
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,354 +0,0 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributors Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. “Incompatible With Secondary Licenses”
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of version
1.1 or earlier of the License, but not also under the terms of a
Secondary License.
1.6. “Executable Form”
means any form of the work other than Source Code Form.
1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate
file or files, that is not Covered Software.
1.8. “License”
means this document.
1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the
time of the initial grant or subsequently, any and all of the rights conveyed by
this License.
1.10. “Modifications”
means any of the following:
a. any file in Source Code Form that results from an addition to, deletion
from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process,
and apparatus claims, in any patent Licensable by such Contributor that
would be infringed, but for the grant of the License, by the making,
using, selling, offering for sale, having made, import, or transfer of
either its Contributions or its Contributor Version.
1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. “Source Code Form”
means the form of the work preferred for making modifications.
1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this
License. For legal entities, “You” includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, “control” means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or as
part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its Contributions
or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution become
effective for each Contribution on the date the Contributor first distributes
such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under this
License. No additional rights or licenses will be implied from the distribution
or licensing of Covered Software under this License. Notwithstanding Section
2.1(b) above, no patent license is granted by a Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third partys
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of its
Contributions.
This License does not grant any rights in the trademarks, service marks, or
logos of any Contributor (except as may be necessary to comply with the
notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this License
(see Section 10.2) or under the terms of a Secondary License (if permitted
under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its Contributions
are its original creation(s) or it has sufficient rights to grant the
rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under applicable
copyright doctrines of fair use, fair dealing, or other equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under the
terms of this License. You must inform recipients that the Source Code Form
of the Covered Software is governed by the terms of this License, and how
they can obtain a copy of this License. You may not attempt to alter or
restrict the recipients rights in the Source Code Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this License,
or sublicense it under different terms, provided that the license for
the Executable Form does not attempt to limit or alter the recipients
rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for the
Covered Software. If the Larger Work is a combination of Covered Software
with a work governed by one or more Secondary Licenses, and the Covered
Software is not Incompatible With Secondary Licenses, this License permits
You to additionally distribute such Covered Software under the terms of
such Secondary License(s), so that the recipient of the Larger Work may, at
their option, further distribute the Covered Software under the terms of
either this License or such Secondary License(s).
3.4. Notices
You may not remove or alter the substance of any license notices (including
copyright notices, patent notices, disclaimers of warranty, or limitations
of liability) contained within the Source Code Form of the Covered
Software, except that You may alter any license notices to the extent
required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on behalf
of any Contributor. You must make it absolutely clear that any such
warranty, support, indemnity, or liability obligation is offered by You
alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute, judicial
order, or regulation then You must: (a) comply with the terms of this License
to the maximum extent possible; and (b) describe the limitations and the code
they affect. Such description must be placed in a text file included with all
distributions of the Covered Software under this License. Except to the
extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to
understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
if such Contributor fails to notify You of the non-compliance by some
reasonable means prior to 60 days after You have come back into compliance.
Moreover, Your grants from a particular Contributor are reinstated on an
ongoing basis if such Contributor notifies You of the non-compliance by
some reasonable means, this is the first time You have received notice of
non-compliance with this License from such Contributor, and You become
compliant prior to 30 days after Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions, counter-claims,
and cross-claims) alleging that a Contributor Version directly or
indirectly infringes any patent, then the rights granted to You by any and
all Contributors for the Covered Software under Section 2.1 of this License
shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an “as is” basis, without
warranty of any kind, either expressed, implied, or statutory, including,
without limitation, warranties that the Covered Software is free of defects,
merchantable, fit for a particular purpose or non-infringing. The entire
risk as to the quality and performance of the Covered Software is with You.
Should any Covered Software prove defective in any respect, You (not any
Contributor) assume the cost of any necessary servicing, repair, or
correction. This disclaimer of warranty constitutes an essential part of this
License. No use of any Covered Software is authorized under this License
except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from such
partys negligence to the extent applicable law prohibits such limitation.
Some jurisdictions do not allow the exclusion or limitation of incidental or
consequential damages, so this exclusion and limitation may not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts of
a jurisdiction where the defendant maintains its principal place of business
and such litigation shall be governed by laws of that jurisdiction, without
reference to its conflict-of-law provisions. Nothing in this Section shall
prevent a partys ability to bring cross-claims or counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject matter
hereof. If any provision of this License is held to be unenforceable, such
provision shall be reformed only to the extent necessary to make it
enforceable. Any law or regulation which provides that the language of a
contract shall be construed against the drafter shall not be used to construe
this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version of
the License under which You originally received the Covered Software, or
under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a modified
version of this License if you rename the license and remove any
references to the name of the license steward (except to note that such
modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a relevant
directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - “Incompatible With Secondary Licenses” Notice
This Source Code Form is “Incompatible
With Secondary Licenses”, as defined by
the Mozilla Public License, v. 2.0.

View File

@@ -1,8 +0,0 @@
dhcp4client [![GoDoc](https://godoc.org/github.com/d2g/dhcp4client?status.svg)](http://godoc.org/github.com/d2g/dhcp4client) [![Coverage Status](https://coveralls.io/repos/d2g/dhcp4client/badge.svg?branch=HEAD)](https://coveralls.io/r/d2g/dhcp4client?branch=HEAD) [![Codeship Status for d2g/dhcp4client](https://codeship.com/projects/d75d9860-b364-0132-bc79-7e1d8cf367b9/status?branch=master)](https://codeship.com/projects/70187)
===========
DHCP Client
###### Thanks to:
@eyakubovich For AF_PACKET support.

View File

@@ -1,364 +0,0 @@
package dhcp4client
import (
"bytes"
"net"
"time"
"github.com/d2g/dhcp4"
)
const (
MaxDHCPLen = 576
)
type Client struct {
hardwareAddr net.HardwareAddr //The HardwareAddr to send in the request.
ignoreServers []net.IP //List of Servers to Ignore requests from.
timeout time.Duration //Time before we timeout.
broadcast bool //Set the Bcast flag in BOOTP Flags
connection connection //The Connection Method to use
generateXID func([]byte) //Function Used to Generate a XID
}
//Abstracts the type of underlying socket used
type connection interface {
Close() error
Write(packet []byte) error
ReadFrom() ([]byte, net.IP, error)
SetReadTimeout(t time.Duration) error
}
func New(options ...func(*Client) error) (*Client, error) {
c := Client{
timeout: time.Second * 10,
broadcast: true,
generateXID: CryptoGenerateXID,
}
err := c.SetOption(options...)
if err != nil {
return nil, err
}
//if connection hasn't been set as an option create the default.
if c.connection == nil {
conn, err := NewInetSock()
if err != nil {
return nil, err
}
c.connection = conn
}
return &c, nil
}
func (c *Client) SetOption(options ...func(*Client) error) error {
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
func Timeout(t time.Duration) func(*Client) error {
return func(c *Client) error {
c.timeout = t
return nil
}
}
func IgnoreServers(s []net.IP) func(*Client) error {
return func(c *Client) error {
c.ignoreServers = s
return nil
}
}
func HardwareAddr(h net.HardwareAddr) func(*Client) error {
return func(c *Client) error {
c.hardwareAddr = h
return nil
}
}
func Broadcast(b bool) func(*Client) error {
return func(c *Client) error {
c.broadcast = b
return nil
}
}
func Connection(conn connection) func(*Client) error {
return func(c *Client) error {
c.connection = conn
return nil
}
}
func GenerateXID(g func([]byte)) func(*Client) error {
return func(c *Client) error {
c.generateXID = g
return nil
}
}
//Close Connections
func (c *Client) Close() error {
if c.connection != nil {
return c.connection.Close()
}
return nil
}
//Send the Discovery Packet to the Broadcast Channel
func (c *Client) SendDiscoverPacket() (dhcp4.Packet, error) {
discoveryPacket := c.DiscoverPacket()
discoveryPacket.PadToMinSize()
return discoveryPacket, c.SendPacket(discoveryPacket)
}
//Retreive Offer...
//Wait for the offer for a specific Discovery Packet.
func (c *Client) GetOffer(discoverPacket *dhcp4.Packet) (dhcp4.Packet, error) {
for {
c.connection.SetReadTimeout(c.timeout)
readBuffer, source, err := c.connection.ReadFrom()
if err != nil {
return dhcp4.Packet{}, err
}
offerPacket := dhcp4.Packet(readBuffer)
offerPacketOptions := offerPacket.ParseOptions()
// Ignore Servers in my Ignore list
for _, ignoreServer := range c.ignoreServers {
if source.Equal(ignoreServer) {
continue
}
if offerPacket.SIAddr().Equal(ignoreServer) {
continue
}
}
if len(offerPacketOptions[dhcp4.OptionDHCPMessageType]) < 1 || dhcp4.MessageType(offerPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.Offer || !bytes.Equal(discoverPacket.XId(), offerPacket.XId()) {
continue
}
return offerPacket, nil
}
}
//Send Request Based On the offer Received.
func (c *Client) SendRequest(offerPacket *dhcp4.Packet) (dhcp4.Packet, error) {
requestPacket := c.RequestPacket(offerPacket)
requestPacket.PadToMinSize()
return requestPacket, c.SendPacket(requestPacket)
}
//Retreive Acknowledgement
//Wait for the offer for a specific Request Packet.
func (c *Client) GetAcknowledgement(requestPacket *dhcp4.Packet) (dhcp4.Packet, error) {
for {
c.connection.SetReadTimeout(c.timeout)
readBuffer, source, err := c.connection.ReadFrom()
if err != nil {
return dhcp4.Packet{}, err
}
acknowledgementPacket := dhcp4.Packet(readBuffer)
acknowledgementPacketOptions := acknowledgementPacket.ParseOptions()
// Ignore Servers in my Ignore list
for _, ignoreServer := range c.ignoreServers {
if source.Equal(ignoreServer) {
continue
}
if acknowledgementPacket.SIAddr().Equal(ignoreServer) {
continue
}
}
if !bytes.Equal(requestPacket.XId(), acknowledgementPacket.XId()) || len(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType]) < 1 || (dhcp4.MessageType(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK && dhcp4.MessageType(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.NAK) {
continue
}
return acknowledgementPacket, nil
}
}
//Send Decline to the received acknowledgement.
func (c *Client) SendDecline(acknowledgementPacket *dhcp4.Packet) (dhcp4.Packet, error) {
declinePacket := c.DeclinePacket(acknowledgementPacket)
declinePacket.PadToMinSize()
return declinePacket, c.SendPacket(declinePacket)
}
//Send a DHCP Packet.
func (c *Client) SendPacket(packet dhcp4.Packet) error {
return c.connection.Write(packet)
}
//Create Discover Packet
func (c *Client) DiscoverPacket() dhcp4.Packet {
messageid := make([]byte, 4)
c.generateXID(messageid)
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(c.hardwareAddr)
packet.SetXId(messageid)
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Discover)})
//packet.PadToMinSize()
return packet
}
//Create Request Packet
func (c *Client) RequestPacket(offerPacket *dhcp4.Packet) dhcp4.Packet {
offerOptions := offerPacket.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(c.hardwareAddr)
packet.SetXId(offerPacket.XId())
packet.SetCIAddr(offerPacket.CIAddr())
packet.SetSIAddr(offerPacket.SIAddr())
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Request)})
packet.AddOption(dhcp4.OptionRequestedIPAddress, (offerPacket.YIAddr()).To4())
packet.AddOption(dhcp4.OptionServerIdentifier, offerOptions[dhcp4.OptionServerIdentifier])
return packet
}
//Create Request Packet For a Renew
func (c *Client) RenewalRequestPacket(acknowledgement *dhcp4.Packet) dhcp4.Packet {
messageid := make([]byte, 4)
c.generateXID(messageid)
acknowledgementOptions := acknowledgement.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(acknowledgement.CHAddr())
packet.SetXId(messageid)
packet.SetCIAddr(acknowledgement.YIAddr())
packet.SetSIAddr(acknowledgement.SIAddr())
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Request)})
packet.AddOption(dhcp4.OptionRequestedIPAddress, (acknowledgement.YIAddr()).To4())
packet.AddOption(dhcp4.OptionServerIdentifier, acknowledgementOptions[dhcp4.OptionServerIdentifier])
return packet
}
//Create Release Packet For a Release
func (c *Client) ReleasePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet {
messageid := make([]byte, 4)
c.generateXID(messageid)
acknowledgementOptions := acknowledgement.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(acknowledgement.CHAddr())
packet.SetXId(messageid)
packet.SetCIAddr(acknowledgement.YIAddr())
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Release)})
packet.AddOption(dhcp4.OptionServerIdentifier, acknowledgementOptions[dhcp4.OptionServerIdentifier])
return packet
}
//Create Decline Packet
func (c *Client) DeclinePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet {
messageid := make([]byte, 4)
c.generateXID(messageid)
acknowledgementOptions := acknowledgement.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(acknowledgement.CHAddr())
packet.SetXId(messageid)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Decline)})
packet.AddOption(dhcp4.OptionRequestedIPAddress, (acknowledgement.YIAddr()).To4())
packet.AddOption(dhcp4.OptionServerIdentifier, acknowledgementOptions[dhcp4.OptionServerIdentifier])
return packet
}
//Lets do a Full DHCP Request.
func (c *Client) Request() (bool, dhcp4.Packet, error) {
discoveryPacket, err := c.SendDiscoverPacket()
if err != nil {
return false, discoveryPacket, err
}
offerPacket, err := c.GetOffer(&discoveryPacket)
if err != nil {
return false, offerPacket, err
}
requestPacket, err := c.SendRequest(&offerPacket)
if err != nil {
return false, requestPacket, err
}
acknowledgement, err := c.GetAcknowledgement(&requestPacket)
if err != nil {
return false, acknowledgement, err
}
acknowledgementOptions := acknowledgement.ParseOptions()
if dhcp4.MessageType(acknowledgementOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK {
return false, acknowledgement, nil
}
return true, acknowledgement, nil
}
//Renew a lease backed on the Acknowledgement Packet.
//Returns Sucessfull, The AcknoledgementPacket, Any Errors
func (c *Client) Renew(acknowledgement dhcp4.Packet) (bool, dhcp4.Packet, error) {
renewRequest := c.RenewalRequestPacket(&acknowledgement)
renewRequest.PadToMinSize()
err := c.SendPacket(renewRequest)
if err != nil {
return false, renewRequest, err
}
newAcknowledgement, err := c.GetAcknowledgement(&renewRequest)
if err != nil {
return false, newAcknowledgement, err
}
newAcknowledgementOptions := newAcknowledgement.ParseOptions()
if dhcp4.MessageType(newAcknowledgementOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK {
return false, newAcknowledgement, nil
}
return true, newAcknowledgement, nil
}
//Release a lease backed on the Acknowledgement Packet.
//Returns Any Errors
func (c *Client) Release(acknowledgement dhcp4.Packet) error {
release := c.ReleasePacket(&acknowledgement)
release.PadToMinSize()
return c.SendPacket(release)
}

View File

@@ -1,18 +0,0 @@
package dhcp4client
import (
cryptorand "crypto/rand"
mathrand "math/rand"
)
func CryptoGenerateXID(b []byte) {
if _, err := cryptorand.Read(b); err != nil {
panic(err)
}
}
func MathGenerateXID(b []byte) {
if _, err := mathrand.Read(b); err != nil {
panic(err)
}
}

View File

@@ -1,75 +0,0 @@
package dhcp4client
import (
"net"
"time"
)
type inetSock struct {
*net.UDPConn
laddr net.UDPAddr
raddr net.UDPAddr
}
func NewInetSock(options ...func(*inetSock) error) (*inetSock, error) {
c := &inetSock{
laddr: net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 68},
raddr: net.UDPAddr{IP: net.IPv4bcast, Port: 67},
}
err := c.setOption(options...)
if err != nil {
return nil, err
}
conn, err := net.ListenUDP("udp4", &c.laddr)
if err != nil {
return nil, err
}
c.UDPConn = conn
return c, err
}
func (c *inetSock) setOption(options ...func(*inetSock) error) error {
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
func SetLocalAddr(l net.UDPAddr) func(*inetSock) error {
return func(c *inetSock) error {
c.laddr = l
return nil
}
}
func SetRemoteAddr(r net.UDPAddr) func(*inetSock) error {
return func(c *inetSock) error {
c.raddr = r
return nil
}
}
func (c *inetSock) Write(packet []byte) error {
_, err := c.WriteToUDP(packet, &c.raddr)
return err
}
func (c *inetSock) ReadFrom() ([]byte, net.IP, error) {
readBuffer := make([]byte, MaxDHCPLen)
n, source, err := c.ReadFromUDP(readBuffer)
if source != nil {
return readBuffer[:n], source.IP, err
} else {
return readBuffer[:n], net.IP{}, err
}
}
func (c *inetSock) SetReadTimeout(t time.Duration) error {
return c.SetReadDeadline(time.Now().Add(t))
}

View File

@@ -1,147 +0,0 @@
package dhcp4client
import (
"crypto/rand"
"encoding/binary"
"net"
"time"
"golang.org/x/sys/unix"
)
const (
minIPHdrLen = 20
maxIPHdrLen = 60
udpHdrLen = 8
ip4Ver = 0x40
ttl = 16
srcPort = 68
dstPort = 67
)
var (
bcastMAC = []byte{255, 255, 255, 255, 255, 255}
)
// abstracts AF_PACKET
type packetSock struct {
fd int
ifindex int
}
func NewPacketSock(ifindex int) (*packetSock, error) {
fd, err := unix.Socket(unix.AF_PACKET, unix.SOCK_DGRAM, int(swap16(unix.ETH_P_IP)))
if err != nil {
return nil, err
}
addr := unix.SockaddrLinklayer{
Ifindex: ifindex,
Protocol: swap16(unix.ETH_P_IP),
}
if err = unix.Bind(fd, &addr); err != nil {
return nil, err
}
return &packetSock{
fd: fd,
ifindex: ifindex,
}, nil
}
func (pc *packetSock) Close() error {
return unix.Close(pc.fd)
}
func (pc *packetSock) Write(packet []byte) error {
lladdr := unix.SockaddrLinklayer{
Ifindex: pc.ifindex,
Protocol: swap16(unix.ETH_P_IP),
Halen: uint8(len(bcastMAC)),
}
copy(lladdr.Addr[:], bcastMAC)
pkt := make([]byte, minIPHdrLen+udpHdrLen+len(packet))
fillIPHdr(pkt[0:minIPHdrLen], udpHdrLen+uint16(len(packet)))
fillUDPHdr(pkt[minIPHdrLen:minIPHdrLen+udpHdrLen], uint16(len(packet)))
// payload
copy(pkt[minIPHdrLen+udpHdrLen:len(pkt)], packet)
return unix.Sendto(pc.fd, pkt, 0, &lladdr)
}
func (pc *packetSock) ReadFrom() ([]byte, net.IP, error) {
pkt := make([]byte, maxIPHdrLen+udpHdrLen+MaxDHCPLen)
n, _, err := unix.Recvfrom(pc.fd, pkt, 0)
if err != nil {
return nil, nil, err
}
// IP hdr len
ihl := int(pkt[0]&0x0F) * 4
// Source IP address
src := net.IP(pkt[12:16])
return pkt[ihl+udpHdrLen : n], src, nil
}
func (pc *packetSock) SetReadTimeout(t time.Duration) error {
tv := unix.NsecToTimeval(t.Nanoseconds())
return unix.SetsockoptTimeval(pc.fd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv)
}
// compute's 1's complement checksum
func chksum(p []byte, csum []byte) {
cklen := len(p)
s := uint32(0)
for i := 0; i < (cklen - 1); i += 2 {
s += uint32(p[i+1])<<8 | uint32(p[i])
}
if cklen&1 == 1 {
s += uint32(p[cklen-1])
}
s = (s >> 16) + (s & 0xffff)
s = s + (s >> 16)
s = ^s
csum[0] = uint8(s & 0xff)
csum[1] = uint8(s >> 8)
}
func fillIPHdr(hdr []byte, payloadLen uint16) {
// version + IHL
hdr[0] = ip4Ver | (minIPHdrLen / 4)
// total length
binary.BigEndian.PutUint16(hdr[2:4], uint16(len(hdr))+payloadLen)
// identification
if _, err := rand.Read(hdr[4:5]); err != nil {
panic(err)
}
// TTL
hdr[8] = 16
// Protocol
hdr[9] = unix.IPPROTO_UDP
// dst IP
copy(hdr[16:20], net.IPv4bcast.To4())
// compute IP hdr checksum
chksum(hdr[0:len(hdr)], hdr[10:12])
}
func fillUDPHdr(hdr []byte, payloadLen uint16) {
// src port
binary.BigEndian.PutUint16(hdr[0:2], srcPort)
// dest port
binary.BigEndian.PutUint16(hdr[2:4], dstPort)
// length
binary.BigEndian.PutUint16(hdr[4:6], udpHdrLen+payloadLen)
}
func swap16(x uint16) uint16 {
var b [2]byte
binary.BigEndian.PutUint16(b[:], x)
return binary.LittleEndian.Uint16(b[:])
}

View File

@@ -1,74 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,26 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"sspi.go",
"sspi_unsupported.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/vmware/photon-controller-go-sdk/SSPI",
importpath = "github.com/vmware/photon-controller-go-sdk/SSPI",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,27 +0,0 @@
Copyright (c) 2012 The Go Authors. 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.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
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
OWNER 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.

View File

@@ -1,3 +0,0 @@
SSPI implementation in this directory is taken from https://github.com/WillHipschman/sspi-prototype (git commit: 4feee8f2e75857bb51345fdfc8e3c091edc959b4)
Implementation is modified to make sure that it only compiles on Windows.
For non-Windows platforms, please look at sspi_unspported.go

View File

@@ -1,276 +0,0 @@
// +build windows
package SSPI
import (
"fmt"
"strings"
"syscall"
"unsafe"
)
var (
secur32_dll = syscall.NewLazyDLL("secur32.dll")
initSecurityInterface = secur32_dll.NewProc("InitSecurityInterfaceW")
sec_fn *SecurityFunctionTable
)
func init() {
ptr, _, _ := initSecurityInterface.Call()
sec_fn = (*SecurityFunctionTable)(unsafe.Pointer(ptr))
}
const (
SEC_E_OK = 0
SECPKG_CRED_OUTBOUND = 2
SEC_WINNT_AUTH_IDENTITY_UNICODE = 2
ISC_REQ_DELEGATE = 0x00000001
ISC_REQ_REPLAY_DETECT = 0x00000004
ISC_REQ_SEQUENCE_DETECT = 0x00000008
ISC_REQ_CONFIDENTIALITY = 0x00000010
ISC_REQ_CONNECTION = 0x00000800
SECURITY_NETWORK_DREP = 0
SEC_I_CONTINUE_NEEDED = 0x00090312
SEC_I_COMPLETE_NEEDED = 0x00090313
SEC_I_COMPLETE_AND_CONTINUE = 0x00090314
SECBUFFER_VERSION = 0
SECBUFFER_TOKEN = 2
NTLMBUF_LEN = 12000
)
const ISC_REQ = ISC_REQ_CONFIDENTIALITY |
ISC_REQ_REPLAY_DETECT |
ISC_REQ_SEQUENCE_DETECT |
ISC_REQ_CONNECTION |
ISC_REQ_DELEGATE
type SecurityFunctionTable struct {
dwVersion uint32
EnumerateSecurityPackages uintptr
QueryCredentialsAttributes uintptr
AcquireCredentialsHandle uintptr
FreeCredentialsHandle uintptr
Reserved2 uintptr
InitializeSecurityContext uintptr
AcceptSecurityContext uintptr
CompleteAuthToken uintptr
DeleteSecurityContext uintptr
ApplyControlToken uintptr
QueryContextAttributes uintptr
ImpersonateSecurityContext uintptr
RevertSecurityContext uintptr
MakeSignature uintptr
VerifySignature uintptr
FreeContextBuffer uintptr
QuerySecurityPackageInfo uintptr
Reserved3 uintptr
Reserved4 uintptr
Reserved5 uintptr
Reserved6 uintptr
Reserved7 uintptr
Reserved8 uintptr
QuerySecurityContextToken uintptr
EncryptMessage uintptr
DecryptMessage uintptr
}
type SEC_WINNT_AUTH_IDENTITY struct {
User *uint16
UserLength uint32
Domain *uint16
DomainLength uint32
Password *uint16
PasswordLength uint32
Flags uint32
}
type TimeStamp struct {
LowPart uint32
HighPart int32
}
type SecHandle struct {
dwLower uintptr
dwUpper uintptr
}
type SecBuffer struct {
cbBuffer uint32
BufferType uint32
pvBuffer *byte
}
type SecBufferDesc struct {
ulVersion uint32
cBuffers uint32
pBuffers *SecBuffer
}
type SSPIAuth struct {
Domain string
UserName string
Password string
Service string
cred SecHandle
ctxt SecHandle
}
type Auth interface {
InitialBytes() ([]byte, error)
NextBytes([]byte) ([]byte, error)
Free()
}
// GetAuth returns SSPI auth object initialized with given params and true for success
// In case of error, it will return nil SSPI object and false for failure
func GetAuth(user, password, service, workstation string) (Auth, bool) {
if user == "" {
return &SSPIAuth{Service: service}, true
}
if !strings.ContainsRune(user, '\\') {
return nil, false
}
domain_user := strings.SplitN(user, "\\", 2)
return &SSPIAuth{
Domain: domain_user[0],
UserName: domain_user[1],
Password: password,
Service: service,
}, true
}
func (auth *SSPIAuth) InitialBytes() ([]byte, error) {
var identity *SEC_WINNT_AUTH_IDENTITY
if auth.UserName != "" {
identity = &SEC_WINNT_AUTH_IDENTITY{
Flags: SEC_WINNT_AUTH_IDENTITY_UNICODE,
Password: syscall.StringToUTF16Ptr(auth.Password),
PasswordLength: uint32(len(auth.Password)),
Domain: syscall.StringToUTF16Ptr(auth.Domain),
DomainLength: uint32(len(auth.Domain)),
User: syscall.StringToUTF16Ptr(auth.UserName),
UserLength: uint32(len(auth.UserName)),
}
}
var ts TimeStamp
sec_ok, _, _ := syscall.Syscall9(sec_fn.AcquireCredentialsHandle,
9,
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("Negotiate"))),
SECPKG_CRED_OUTBOUND,
0,
uintptr(unsafe.Pointer(identity)),
0,
0,
uintptr(unsafe.Pointer(&auth.cred)),
uintptr(unsafe.Pointer(&ts)))
if sec_ok != SEC_E_OK {
return nil, fmt.Errorf("AcquireCredentialsHandle failed %x", sec_ok)
}
var buf SecBuffer
var desc SecBufferDesc
desc.ulVersion = SECBUFFER_VERSION
desc.cBuffers = 1
desc.pBuffers = &buf
outbuf := make([]byte, NTLMBUF_LEN)
buf.cbBuffer = NTLMBUF_LEN
buf.BufferType = SECBUFFER_TOKEN
buf.pvBuffer = &outbuf[0]
var attrs uint32
sec_ok, _, _ = syscall.Syscall12(sec_fn.InitializeSecurityContext,
12,
uintptr(unsafe.Pointer(&auth.cred)),
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(auth.Service))),
ISC_REQ,
0,
SECURITY_NETWORK_DREP,
0,
0,
uintptr(unsafe.Pointer(&auth.ctxt)),
uintptr(unsafe.Pointer(&desc)),
uintptr(unsafe.Pointer(&attrs)),
uintptr(unsafe.Pointer(&ts)))
if sec_ok == SEC_I_COMPLETE_AND_CONTINUE ||
sec_ok == SEC_I_COMPLETE_NEEDED {
syscall.Syscall6(sec_fn.CompleteAuthToken,
2,
uintptr(unsafe.Pointer(&auth.ctxt)),
uintptr(unsafe.Pointer(&desc)),
0, 0, 0, 0)
} else if sec_ok != SEC_E_OK &&
sec_ok != SEC_I_CONTINUE_NEEDED {
syscall.Syscall6(sec_fn.FreeCredentialsHandle,
1,
uintptr(unsafe.Pointer(&auth.cred)),
0, 0, 0, 0, 0)
return nil, fmt.Errorf("InitialBytes InitializeSecurityContext failed %x", sec_ok)
}
return outbuf[:buf.cbBuffer], nil
}
func (auth *SSPIAuth) NextBytes(bytes []byte) ([]byte, error) {
var in_buf, out_buf SecBuffer
var in_desc, out_desc SecBufferDesc
in_desc.ulVersion = SECBUFFER_VERSION
in_desc.cBuffers = 1
in_desc.pBuffers = &in_buf
out_desc.ulVersion = SECBUFFER_VERSION
out_desc.cBuffers = 1
out_desc.pBuffers = &out_buf
in_buf.BufferType = SECBUFFER_TOKEN
in_buf.pvBuffer = &bytes[0]
in_buf.cbBuffer = uint32(len(bytes))
outbuf := make([]byte, NTLMBUF_LEN)
out_buf.BufferType = SECBUFFER_TOKEN
out_buf.pvBuffer = &outbuf[0]
out_buf.cbBuffer = NTLMBUF_LEN
var attrs uint32
var ts TimeStamp
sec_ok, _, _ := syscall.Syscall12(sec_fn.InitializeSecurityContext,
12,
uintptr(unsafe.Pointer(&auth.cred)),
uintptr(unsafe.Pointer(&auth.ctxt)),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(auth.Service))),
ISC_REQ,
0,
SECURITY_NETWORK_DREP,
uintptr(unsafe.Pointer(&in_desc)),
0,
uintptr(unsafe.Pointer(&auth.ctxt)),
uintptr(unsafe.Pointer(&out_desc)),
uintptr(unsafe.Pointer(&attrs)),
uintptr(unsafe.Pointer(&ts)))
if sec_ok == SEC_I_COMPLETE_AND_CONTINUE ||
sec_ok == SEC_I_COMPLETE_NEEDED {
syscall.Syscall6(sec_fn.CompleteAuthToken,
2,
uintptr(unsafe.Pointer(&auth.ctxt)),
uintptr(unsafe.Pointer(&out_desc)),
0, 0, 0, 0)
} else if sec_ok != SEC_E_OK &&
sec_ok != SEC_I_CONTINUE_NEEDED {
return nil, fmt.Errorf("NextBytes InitializeSecurityContext failed %x", sec_ok)
}
return outbuf[:out_buf.cbBuffer], nil
}
func (auth *SSPIAuth) Free() {
syscall.Syscall6(sec_fn.DeleteSecurityContext,
1,
uintptr(unsafe.Pointer(&auth.ctxt)),
0, 0, 0, 0, 0)
syscall.Syscall6(sec_fn.FreeCredentialsHandle,
1,
uintptr(unsafe.Pointer(&auth.cred)),
0, 0, 0, 0, 0)
}

View File

@@ -1,12 +0,0 @@
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
// +build !windows
package SSPI

View File

@@ -1,51 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"apitypes.go",
"auth.go",
"availabilityzones.go",
"client.go",
"deployments.go",
"disks.go",
"flavors.go",
"hosts.go",
"images.go",
"info.go",
"networks.go",
"projects.go",
"resourcetickets.go",
"restclient.go",
"routers.go",
"services.go",
"status.go",
"subnets.go",
"tasks.go",
"tenants.go",
"util.go",
"virtualnetworks.go",
"vms.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/vmware/photon-controller-go-sdk/photon",
importpath = "github.com/vmware/photon-controller-go-sdk/photon",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/vmware/photon-controller-go-sdk/photon/lightwave:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//vendor/github.com/vmware/photon-controller-go-sdk/photon/lightwave:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,802 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"fmt"
)
type Entity struct {
ID string `json:"id"`
Kind string `json:"kind"`
}
// Implement a generic sdk error
type SdkError struct {
Message string
}
func (e SdkError) Error() string {
return fmt.Sprintf("photon: %v", e.Message)
}
// Represents an error from the Photon API.
type ApiError struct {
Code string `json:"code"`
Data map[string]interface{} `json:"data"`
Message string `json:"message"`
HttpStatusCode int `json:"-"` // Not part of API contract
}
// Implement Go error interface for ApiError
func (e ApiError) Error() string {
return fmt.Sprintf(
"photon: { HTTP status: '%v', code: '%v', message: '%v', data: '%v' }",
e.HttpStatusCode,
e.Code,
e.Message,
e.Data)
}
// Used to represent a generic HTTP error, i.e. an unexpected HTTP 500.
type HttpError struct {
StatusCode int
Message string
}
// Implementation of error interface for HttpError
func (e HttpError) Error() string {
return fmt.Sprintf("photon: HTTP %d: %v", e.StatusCode, e.Message)
}
// Represents an Photon task that has entered into an error state.
// Photon task errors can be caught and type-checked against with
// the usual Go idiom.
type TaskError struct {
ID string `json:"id"`
Step Step `json:"step,omitempty"`
}
// Implement Go error interface for TaskError.
func (e TaskError) Error() string {
return fmt.Sprintf("photon: Task '%s' is in error state: {@step==%s}", e.ID, GetStep(e.Step))
}
// An error representing a timeout while waiting for a task to complete.
type TaskTimeoutError struct {
ID string
}
// Implement Go error interface for TaskTimeoutError.
func (e TaskTimeoutError) Error() string {
return fmt.Sprintf("photon: Timed out waiting for task '%s'. "+
"Task may not be in error state, examine task for full details.", e.ID)
}
// Represents an operation (Step) within a Task.
type Step struct {
ID string `json:"id"`
Operation string `json:"operation,omitempty"`
State string `json:"state"`
StartedTime int64 `json:"startedTime"`
EndTime int64 `json:"endTime,omitempty"`
QueuedTime int64 `json:"queuedTime"`
Sequence int `json:"sequence,omitempty"`
ResourceProperties map[string]interface{} `json:"resourceProperties,omitempty"`
Errors []ApiError `json:"errors,omitempty"`
Warnings []ApiError `json:"warnings,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
// Implement Go error interface for Step.
func GetStep(s Step) string {
return fmt.Sprintf("{\"sequence\"=>\"%d\",\"state\"=>\"%s\",\"errors\"=>%s,\"warnings\"=>%s,\"operation\"=>\"%s\","+
"\"startedTime\"=>\"%d\",\"queuedTime\"=>\"%d\",\"endTime\"=>\"%d\",\"options\"=>%s}",
s.Sequence, s.State, s.Errors, s.Warnings, s.Operation, s.StartedTime, s.QueuedTime,
s.EndTime, s.Options)
}
// Represents an asynchronous task.
type Task struct {
ID string `json:"id"`
Operation string `json:"operation,omitempty"`
State string `json:"state"`
StartedTime int64 `json:"startedTime"`
EndTime int64 `json:"endTime,omitempty"`
QueuedTime int64 `json:"queuedTime"`
Entity Entity `json:"entity,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
Steps []Step `json:"steps,omitempty"`
ResourceProperties interface{} `json:"resourceProperties,omitempty"`
}
// Represents multiple tasks returned by the API.
type TaskList struct {
Items []Task `json:"items"`
}
// Options for GetTasks API.
type TaskGetOptions struct {
State string `urlParam:"state"`
Kind string `urlParam:"kind"`
EntityID string `urlParam:"entityId"`
EntityKind string `urlParam:"entityKind"`
}
type BaseCompact struct {
Name string `json:"name"`
ID string `json:"id"`
}
type QuotaLineItem struct {
Unit string `json:"unit"`
Value float64 `json:"value"`
Key string `json:"key"`
}
// Creation spec for locality.
type LocalitySpec struct {
Kind string `json:"kind"`
ID string `json:"id"`
}
// Creation spec for disks.
type DiskCreateSpec struct {
Flavor string `json:"flavor"`
Kind string `json:"kind"`
CapacityGB int `json:"capacityGb"`
Affinities []LocalitySpec `json:"affinities,omitempty"`
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
}
// Represents a persistent disk.
type PersistentDisk struct {
Flavor string `json:"flavor"`
Cost []QuotaLineItem `json:"cost"`
Kind string `json:"kind"`
Datastore string `json:"datastore,omitempty"`
CapacityGB int `json:"capacityGb,omitempty"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id"`
VMs []string `json:"vms"`
Tags []string `json:"tags,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
// Represents multiple persistent disks returned by the API.
type DiskList struct {
Items []PersistentDisk `json:"items"`
}
// Creation spec for projects.
type ProjectCreateSpec struct {
ResourceTicket ResourceTicketReservation `json:"resourceTicket"`
Name string `json:"name"`
SecurityGroups []string `json:"securityGroups,omitempty"`
}
// Represents multiple projects returned by the API.
type ProjectList struct {
Items []ProjectCompact `json:"items"`
}
// Compact representation of projects.
type ProjectCompact struct {
Kind string `json:"kind"`
ResourceTicket ProjectTicket `json:"resourceTicket"`
Name string `json:"name"`
ID string `json:"id"`
Tags []string `json:"tags"`
SelfLink string `json:"selfLink"`
SecurityGroups []SecurityGroup `json:"securityGroups"`
}
type ProjectTicket struct {
TenantTicketID string `json:"tenantTicketId"`
Usage []QuotaLineItem `json:"usage"`
TenantTicketName string `json:"tenantTicketName"`
Limits []QuotaLineItem `json:"limits"`
}
// Represents an image.
type Image struct {
Size int64 `json:"size"`
Kind string `json:"kind"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id"`
Tags []string `json:"tags"`
SelfLink string `json:"selfLink"`
Settings []ImageSetting `json:"settings"`
ReplicationType string `json:"replicationType"`
ReplicationProgress string `json:"replicationProgress"`
SeedingProgress string `json:"seedingProgress"`
}
// Represents an image setting
type ImageSetting struct {
Name string `json:"name"`
DefaultValue string `json:"defaultValue"`
}
// Creation spec for images.
type ImageCreateOptions struct {
ReplicationType string
}
// Represents multiple images returned by the API.
type Images struct {
Items []Image `json:"items"`
}
// Represents a component with status.
type Component struct {
Component string
Message string
Status string
}
// Represents status of the photon system.
type Status struct {
Status string
Components []Component
}
// Represents a single tenant.
type Tenant struct {
Projects []BaseCompact `json:"projects"`
ResourceTickets []BaseCompact `json:"resourceTickets"`
Kind string `json:"kind"`
Name string `json:"name"`
ID string `json:"id"`
SelfLink string `json:"selfLink"`
Tags []string `json:"tags"`
SecurityGroups []SecurityGroup `json:"securityGroups"`
}
// Represents multiple tenants returned by the API.
type Tenants struct {
Items []Tenant `json:"items"`
}
// Creation spec for tenants.
type TenantCreateSpec struct {
Name string `json:"name"`
SecurityGroups []string `json:"securityGroups,omitempty"`
}
// Creation spec for resource tickets.
type ResourceTicketCreateSpec struct {
Name string `json:"name"`
Limits []QuotaLineItem `json:"limits"`
}
// Represents a single resource ticket.
type ResourceTicket struct {
Kind string `json:"kind"`
Usage []QuotaLineItem `json:"usage"`
TenantId string `json:"tenantId"`
Name string `json:"name"`
ID string `json:"id"`
Limits []QuotaLineItem `json:"limits"`
Tags []string `json:"tags"`
SelfLink string `json:"selfLink"`
}
// Represents multiple resource tickets returned by the API.
type ResourceList struct {
Items []ResourceTicket `json:"items"`
}
// Represents a resource reservation on a resource ticket.
type ResourceTicketReservation struct {
Name string `json:"name"`
Limits []QuotaLineItem `json:"limits"`
}
// Creation spec for VMs.
type VmCreateSpec struct {
Flavor string `json:"flavor"`
SourceImageID string `json:"sourceImageId"`
AttachedDisks []AttachedDisk `json:"attachedDisks"`
Affinities []LocalitySpec `json:"affinities,omitempty"`
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
Subnets []string `json:"subnets,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
}
// Represents possible operations for VMs. Valid values include:
// START_VM, STOP_VM, RESTART_VM, SUSPEND_VM, RESUME_VM
type VmOperation struct {
Operation string `json:"operation"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
// Represents metadata that can be set on a VM.
type VmMetadata struct {
Metadata map[string]string `json:"metadata"`
}
// Represents tags that can be set on a VM.
type VmTag struct {
Tag string `json:"value"`
}
// Represents a single attached disk.
type AttachedDisk struct {
Flavor string `json:"flavor"`
Kind string `json:"kind"`
CapacityGB int `json:"capacityGb,omitempty"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id,omitempty"`
BootDisk bool `json:"bootDisk"`
}
// Represents a single VM.
type VM struct {
SourceImageID string `json:"sourceImageId,omitempty"`
Cost []QuotaLineItem `json:"cost"`
Kind string `json:"kind"`
AttachedDisks []AttachedDisk `json:"attachedDisks"`
Datastore string `json:"datastore,omitempty"`
AttachedISOs []ISO `json:"attachedIsos,omitempty"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
Flavor string `json:"flavor"`
Host string `json:"host,omitempty"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id"`
FloatingIp string `json:"floatingIp"`
}
// Represents multiple VMs returned by the API.
type VMs struct {
Items []VM `json:"items"`
}
// Represents an ISO.
type ISO struct {
Size int64 `json:"size,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name"`
ID string `json:"id"`
}
// Represents operations for disks.
type VmDiskOperation struct {
DiskID string `json:"diskId"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
// Represents a floating IP operation related to a VM.
type VmFloatingIpSpec struct {
NetworkId string `json:"networkId"`
}
// Creation spec for flavors.
type FlavorCreateSpec struct {
Cost []QuotaLineItem `json:"cost"`
Kind string `json:"kind"`
Name string `json:"name"`
}
// Represents a single flavor.
type Flavor struct {
Cost []QuotaLineItem `json:"cost"`
Kind string `json:"kind"`
Name string `json:"name"`
ID string `json:"id"`
Tags []string `json:"tags"`
SelfLink string `json:"selfLink"`
State string `json:"state"`
}
// Represents multiple flavors returned by the API.
type FlavorList struct {
Items []Flavor `json:"items"`
}
// Creation spec for hosts.
type HostCreateSpec struct {
Username string `json:"username"`
Password string `json:"password"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Address string `json:"address"`
Tags []string `json:"usageTags"`
}
// Represents a host
type Host struct {
Username string `json:"username"`
Password string `json:"password"`
Address string `json:"address"`
Kind string `json:"kind"`
ID string `json:"id"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
Tags []string `json:"usageTags"`
Metadata map[string]string `json:"metadata,omitempty"`
SelfLink string `json:"selfLink"`
State string `json:"state"`
EsxVersion string `json:"esxVersion"`
}
// Represents multiple hosts returned by the API.
type Hosts struct {
Items []Host `json:"items"`
}
// Creation spec for deployments.
type DeploymentCreateSpec struct {
NTPEndpoint interface{} `json:"ntpEndpoint"`
UseImageDatastoreForVms bool `json:"useImageDatastoreForVms"`
SyslogEndpoint interface{} `json:"syslogEndpoint"`
Stats *StatsInfo `json:"stats"`
ImageDatastores []string `json:"imageDatastores"`
Auth *AuthInfo `json:"auth"`
NetworkConfiguration *NetworkConfigurationCreateSpec `json:"networkConfiguration"`
LoadBalancerEnabled bool `json:"loadBalancerEnabled"`
}
// Deployment deploy config.
type DeploymentDeployOperation struct {
DesiredState string `json:"desiredState"`
}
type MigrationStatus struct {
CompletedDataMigrationCycles int `json:"completedDataMigrationCycles"`
DataMigrationCycleProgress int `json:"dataMigrationCycleProgress"`
DataMigrationCycleSize int `json:"dataMigrationCycleSize"`
VibsUploaded int `json:"vibsUploaded"`
VibsUploading int `json:"vibsUploading"`
}
// Represents a deployment
type Deployment struct {
NTPEndpoint string `json:"ntpEndpoint,omitempty"`
UseImageDatastoreForVms bool `json:"useImageDatastoreForVms,omitempty"`
Auth *AuthInfo `json:"auth"`
NetworkConfiguration *NetworkConfiguration `json:"networkConfiguration"`
Kind string `json:"kind"`
SyslogEndpoint string `json:"syslogEndpoint,omitempty"`
Stats *StatsInfo `json:"stats,omitempty"`
State string `json:"state"`
ID string `json:"id"`
ImageDatastores []string `json:"imageDatastores"`
SelfLink string `json:"selfLink"`
Migration *MigrationStatus `json:"migrationStatus,omitempty"`
ServiceConfigurations []ServiceConfiguration `json:"serviceConfigurations,omitempty"`
LoadBalancerEnabled bool `json:"loadBalancerEnabled"`
LoadBalancerAddress string `json:"loadBalancerAddress"`
}
// Represents multiple deployments returned by the API.
type Deployments struct {
Items []Deployment `json:"items"`
}
// Represents source load balacer address to migrate deployment
type InitializeMigrationOperation struct {
SourceNodeGroupReference string `json:"sourceNodeGroupReference"`
}
// Represents source load balacer address to finish migration of deployment
type FinalizeMigrationOperation struct {
SourceNodeGroupReference string `json:"sourceNodeGroupReference"`
}
// Represents stats information
type StatsInfo struct {
Enabled bool `json:"enabled,omitempty"`
StoreEndpoint string `json:"storeEndpoint,omitempty"`
StorePort int `json:"storePort,omitempty"`
}
// Represents authentication information
type AuthInfo struct {
Password string `json:"password,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Tenant string `json:"tenant,omitempty"`
Port int `json:"port,omitempty"`
SecurityGroups []string `json:"securityGroups,omitempty"`
Username string `json:"username,omitempty"`
}
// Represents ip range
type IpRange struct {
Start string `json:"start,omitempty"`
End string `json:"end,omitempty"`
}
// Represents creation spec for network configuration.
type NetworkConfigurationCreateSpec struct {
Enabled bool `json:"sdnEnabled,omitempty"`
Address string `json:"networkManagerAddress,omitempty"`
Username string `json:"networkManagerUsername,omitempty"`
Password string `json:"networkManagerPassword,omitempty"`
NetworkZoneId string `json:"networkZoneId,omitempty"`
TopRouterId string `json:"networkTopRouterId,omitempty"`
EdgeIpPoolId string `json:"networkEdgeIpPoolId,omitempty"`
HostUplinkPnic string `json:"networkHostUplinkPnic,omitempty"`
IpRange string `json:"ipRange,omitempty"`
ExternalIpRange *IpRange `json:"externalIpRange,omitempty"`
DhcpServers []string `json:"dhcpServers,omitempty"`
}
// Represents network configuration.
type NetworkConfiguration struct {
Enabled bool `json:"sdnEnabled,omitempty"`
Address string `json:"networkManagerAddress,omitempty"`
Username string `json:"networkManagerUsername,omitempty"`
Password string `json:"networkManagerPassword,omitempty"`
NetworkZoneId string `json:"networkZoneId,omitempty"`
TopRouterId string `json:"networkTopRouterId,omitempty"`
EdgeIpPoolId string `json:"networkEdgeIpPoolId,omitempty"`
HostUplinkPnic string `json:"networkHostUplinkPnic,omitempty"`
IpRange string `json:"ipRange,omitempty"`
FloatingIpRange *IpRange `json:"floatingIpRange,omitempty"`
SnatIp string `json:"snatIp,omitempty"`
DhcpServers []string `json:"dhcpServers,omitempty"`
}
// Creation spec for networks.
type NetworkCreateSpec struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
PortGroups []string `json:"portGroups"`
}
// Represents a subnet
type Network struct {
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
State string `json:"state"`
ID string `json:"id"`
PortGroups []string `json:"portGroups"`
Tags []string `json:"tags,omitempty"`
SelfLink string `json:"selfLink"`
IsDefault bool `json:"isDefault"`
}
// Represents multiple subnets returned by the API
type Networks struct {
Items []Network `json:"items"`
}
// Create spec for virtual subnet
type VirtualSubnetCreateSpec struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
RoutingType string `json:"routingType"`
Size int `json:"size"`
ReservedStaticIpSize int `json:"reservedStaticIpSize,omitempty"`
}
// Represents a virtual network
type VirtualSubnet struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
State string `json:"state"`
RoutingType string `json:"routingType"`
IsDefault bool `json:"isDefault"`
Cidr string `json:"cidr,omitempty"`
LowIpDynamic string `json:"lowIpDynamic,omitempty"`
HighIpDynamic string `json:"highIpDynamic,omitempty"`
LowIpStatic string `json:"lowIpStatic,omitempty"`
HighIpStatic string `json:"highIpStatic,omitempty"`
ReservedIpList []string `json:"reservedIpList"`
SelfLink string `json:"selfLink"`
}
// Represents multiple virtual subnets returned
type VirtualSubnets struct {
Items []VirtualSubnet `json:"items"`
}
// Represents a router
type Router struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
PrivateIpCidr string `json:"privateIpCidr"`
}
// Represents multiple routers returned by the API.
type Routers struct {
Items []Router `json:"items"`
}
type RouterCreateSpec struct {
Name string `json:"name"`
PrivateIpCidr string `json:"privateIpCidr"`
}
// Represents name that can be set for router
type RouterUpdateSpec struct {
RouterName string `json:"name"`
}
// Creation spec for Service Configuration.
type ServiceConfigurationSpec struct {
Type string `json:"type"`
ImageID string `json:"imageId"`
}
// Represnts a Service configuration.
type ServiceConfiguration struct {
Kind string `json:"kind"`
Type string `json:"type"`
ImageID string `json:"imageId"`
}
// Creation spec for services.
type ServiceCreateSpec struct {
Name string `json:"name"`
Type string `json:"type"`
VMFlavor string `json:"vmFlavor,omitempty"`
MasterVmFlavor string `json:"masterVmFlavor,omitempty"`
WorkerVmFlavor string `json:"workerVmFlavor,omitempty"`
DiskFlavor string `json:"diskFlavor,omitempty"`
NetworkID string `json:"vmNetworkId,omitempty"`
ImageID string `json:"imageId,omitempty"`
WorkerCount int `json:"workerCount"`
BatchSizeWorker int `json:"workerBatchExpansionSize,omitempty"`
ExtendedProperties map[string]string `json:"extendedProperties"`
}
// Represents a service
type Service struct {
Kind string `json:"kind"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id"`
Type string `json:"type"`
ProjectID string `json:"projectID,omitempty"`
WorkerCount int `json:"workerCount"`
SelfLink string `json:"selfLink,omitempty"`
ErrorReason string `json:"errorReason,omitempty"`
ExtendedProperties map[string]string `json:"extendedProperties"`
}
// Represents multiple services returned by the API
type Services struct {
Items []Service `json:"items"`
}
// Represents service size that can be resized for service
type ServiceResizeOperation struct {
NewWorkerCount int `json:"newWorkerCount"`
}
// Represents service imageId that can be updated during change version
type ServiceChangeVersionOperation struct {
NewImageID string `json:"newImageId"`
}
// Represents a security group
type SecurityGroup struct {
Name string `json:"name"`
Inherited bool `json:"inherited"`
}
// Represents set_security_groups spec
type SecurityGroupsSpec struct {
Items []string `json:"items"`
}
// Represents single availability zone.
type AvailabilityZone struct {
Kind string `json:"kind"`
Name string `json:"name"`
State string `json:"state"`
ID string `json:"id"`
SelfLink string `json:"selfLink"`
}
// Represents multiple availability zones returned by the API.
type AvailabilityZones struct {
Items []AvailabilityZone `json:"items"`
}
// Creation spec for availability zones.
type AvailabilityZoneCreateSpec struct {
Name string `json:"name"`
}
// Represents availability zone that can be set for host
type HostSetAvailabilityZoneOperation struct {
AvailabilityZoneId string `json:"availabilityZoneId"`
}
// Represents the list of image datastores.
type ImageDatastores struct {
Items []string `json:"items"`
}
// Image creation spec.
type ImageCreateSpec struct {
Name string `json:"name"`
ReplicationType string `json:"replicationType"`
}
// Represents deployment info
type Info struct {
BaseVersion string `json:"baseVersion"`
FullVersion string `json:"fullVersion"`
GitCommitHash string `json:"gitCommitHash"`
NetworkType string `json:"networkType"`
}
// NSX configuration spec
type NsxConfigurationSpec struct {
NsxAddress string `json:"nsxAddress"`
NsxUsername string `json:"nsxUsername"`
NsxPassword string `json:"nsxPassword"`
DhcpServerAddresses map[string]string `json:"dhcpServerAddresses"`
PrivateIpRootCidr string `json:"privateIpRootCidr"`
FloatingIpRootRange IpRange `json:"floatingIpRootRange"`
T0RouterId string `json:"t0RouterId"`
EdgeClusterId string `json:"edgeClusterId"`
OverlayTransportZoneId string `json:"overlayTransportZoneId"`
TunnelIpPoolId string `json:"tunnelIpPoolId"`
HostUplinkPnic string `json:"hostUplinkPnic"`
HostUplinkVlanId int `json:"hostUplinkVlanId"`
}
// Represents a subnet
type Subnet struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
PrivateIpCidr string `json:"privateIpCidr"`
ReservedIps map[string]string `json:"reservedIps"`
State string `json:"state"`
}
// Represents multiple subnets returned by the API.
type Subnets struct {
Items []Subnet `json:"items"`
}
// Creation spec for subnets.
type SubnetCreateSpec struct {
Name string `json:"name"`
Description string `json:"description"`
PrivateIpCidr string `json:"privateIpCidr"`
}
// Represents name that can be set for subnet
type SubnetUpdateSpec struct {
SubnetName string `json:"name"`
}
// Identity and Access Management (IAM)
// IAM Policy entry
type PolicyEntry struct {
Principal string `json:"principal"`
Roles []string `json:"roles"`
}
type PolicyDelta struct {
Principal string `json:"principal"`
Action string `json:"action"`
Role string `json:"role"`
}

View File

@@ -1,143 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
"fmt"
"github.com/vmware/photon-controller-go-sdk/photon/lightwave"
)
// Contains functionality for auth API.
type AuthAPI struct {
client *Client
}
const authUrl string = rootUrl + "/auth"
// Gets authentication info.
func (api *AuthAPI) Get() (info *AuthInfo, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+authUrl, nil)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
info = &AuthInfo{}
err = json.NewDecoder(res.Body).Decode(info)
return
}
// Gets Tokens from username/password.
func (api *AuthAPI) GetTokensByPassword(username string, password string) (tokenOptions *TokenOptions, err error) {
oidcClient, err := api.buildOIDCClient()
if err != nil {
return
}
tokenResponse, err := oidcClient.GetTokenByPasswordGrant(username, password)
if err != nil {
return
}
return api.toTokenOptions(tokenResponse), nil
}
// GetTokensFromWindowsLogInContext gets tokens based on Windows logged in context
// In case of running on platform other than Windows, it returns error
func (api *AuthAPI) GetTokensFromWindowsLogInContext() (tokenOptions *TokenOptions, err error) {
oidcClient, err := api.buildOIDCClient()
if err != nil {
return
}
tokenResponse, err := oidcClient.GetTokensFromWindowsLogInContext()
if err != nil {
return
}
return api.toTokenOptions(tokenResponse), nil
}
// Gets tokens from refresh token.
func (api *AuthAPI) GetTokensByRefreshToken(refreshtoken string) (tokenOptions *TokenOptions, err error) {
oidcClient, err := api.buildOIDCClient()
if err != nil {
return
}
tokenResponse, err := oidcClient.GetTokenByRefreshTokenGrant(refreshtoken)
if err != nil {
return
}
return api.toTokenOptions(tokenResponse), nil
}
func (api *AuthAPI) getAuthEndpoint() (endpoint string, err error) {
authInfo, err := api.client.Auth.Get()
if err != nil {
return
}
if authInfo.Port == 0 {
authInfo.Port = 443
}
return fmt.Sprintf("https://%s:%d", authInfo.Endpoint, authInfo.Port), nil
}
func (api *AuthAPI) buildOIDCClient() (client *lightwave.OIDCClient, err error) {
authEndPoint, err := api.getAuthEndpoint()
if err != nil {
return
}
return lightwave.NewOIDCClient(
authEndPoint,
api.buildOIDCClientOptions(&api.client.options),
api.client.restClient.logger), nil
}
const tokenScope string = "openid offline_access rs_photon_platform at_groups"
func (api *AuthAPI) buildOIDCClientOptions(options *ClientOptions) *lightwave.OIDCClientOptions {
return &lightwave.OIDCClientOptions{
IgnoreCertificate: api.client.options.IgnoreCertificate,
RootCAs: api.client.options.RootCAs,
TokenScope: tokenScope,
}
}
func (api *AuthAPI) toTokenOptions(response *lightwave.OIDCTokenResponse) *TokenOptions {
return &TokenOptions{
AccessToken: response.AccessToken,
ExpiresIn: response.ExpiresIn,
RefreshToken: response.RefreshToken,
IdToken: response.IdToken,
TokenType: response.TokenType,
}
}
// Parse the given token details.
func (api *AuthAPI) parseTokenDetails(token string) (jwtToken *lightwave.JWTToken, err error) {
jwtToken = lightwave.ParseTokenDetails(token)
return jwtToken, nil
}
// Parse the given token raw details.
func (api *AuthAPI) parseRawTokenDetails(token string) (jwtToken []string, err error) {
jwtToken, err = lightwave.ParseRawTokenDetails(token)
return jwtToken, err
}

View File

@@ -1,102 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for availability zones API.
type AvailabilityZonesAPI struct {
client *Client
}
var availabilityzoneUrl string = rootUrl + "/availabilityzones"
// Creates availability zone.
func (api *AvailabilityZonesAPI) Create(availabilityzoneSpec *AvailabilityZoneCreateSpec) (task *Task, err error) {
body, err := json.Marshal(availabilityzoneSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+availabilityzoneUrl,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets availability zone with the specified ID.
func (api *AvailabilityZonesAPI) Get(id string) (availabilityzone *AvailabilityZone, err error) {
res, err := api.client.restClient.Get(api.getEntityUrl(id), api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
availabilityzone = &AvailabilityZone{}
err = json.NewDecoder(res.Body).Decode(availabilityzone)
return
}
// Returns all availability zones on an photon instance.
func (api *AvailabilityZonesAPI) GetAll() (result *AvailabilityZones, err error) {
uri := api.client.Endpoint + availabilityzoneUrl
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &AvailabilityZones{}
err = json.Unmarshal(res, result)
return
}
// Deletes the availability zone with specified ID.
func (api *AvailabilityZonesAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+availabilityzoneUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified availability zone ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *AvailabilityZonesAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + availabilityzoneUrl + "/" + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
func (api *AvailabilityZonesAPI) getEntityUrl(id string) (url string) {
return api.client.Endpoint + availabilityzoneUrl + "/" + id
}

View File

@@ -1,193 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"log"
"net/http"
"strings"
"time"
)
// Represents stateless context needed to call photon APIs.
type Client struct {
options ClientOptions
restClient *restClient
logger *log.Logger
Endpoint string
Status *StatusAPI
Tenants *TenantsAPI
Tasks *TasksAPI
Projects *ProjectsAPI
Flavors *FlavorsAPI
Images *ImagesAPI
Disks *DisksAPI
VMs *VmAPI
Hosts *HostsAPI
Deployments *DeploymentsAPI
ResourceTickets *ResourceTicketsAPI
Networks *NetworksAPI
VirtualSubnets *VirtualSubnetsAPI
Services *ServicesAPI
Auth *AuthAPI
AvailabilityZones *AvailabilityZonesAPI
Info *InfoAPI
Routers *RoutersAPI
Subnets *SubnetsAPI
}
// Represents Tokens
type TokenOptions struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token,omitempty"`
IdToken string `json:"id_token"`
TokenType string `json:"token_type"`
}
type TokenCallback func(string)
// Options for Client
type ClientOptions struct {
// When using the Tasks.Wait APIs, defines the duration of how long
// the SDK should continue to poll the server. Default is 30 minutes.
// TasksAPI.WaitTimeout() can be used to specify timeout on
// individual calls.
TaskPollTimeout time.Duration
// Whether or not to ignore any TLS errors when talking to photon,
// false by default.
IgnoreCertificate bool
// List of root CA's to use for server validation
// nil by default.
RootCAs *x509.CertPool
// For tasks APIs, defines the delay between each polling attempt.
// Default is 100 milliseconds.
TaskPollDelay time.Duration
// For tasks APIs, defines the number of retries to make in the event
// of an error. Default is 3.
TaskRetryCount int
// Tokens for user authentication. Default is empty.
TokenOptions *TokenOptions
// A function to be called if the access token was refreshed
// The client can save the new access token for future API
// calls so that it doesn't need to be refreshed again.
UpdateAccessTokenCallback TokenCallback
}
// Creates a new photon client with specified options. If options
// is nil, default options will be used.
func NewClient(endpoint string, options *ClientOptions, logger *log.Logger) (c *Client) {
defaultOptions := &ClientOptions{
TaskPollTimeout: 30 * time.Minute,
TaskPollDelay: 100 * time.Millisecond,
TaskRetryCount: 3,
TokenOptions: &TokenOptions{},
IgnoreCertificate: false,
RootCAs: nil,
}
if options != nil {
if options.TaskPollTimeout != 0 {
defaultOptions.TaskPollTimeout = options.TaskPollTimeout
}
if options.TaskPollDelay != 0 {
defaultOptions.TaskPollDelay = options.TaskPollDelay
}
if options.TaskRetryCount != 0 {
defaultOptions.TaskRetryCount = options.TaskRetryCount
}
if options.TokenOptions != nil {
defaultOptions.TokenOptions = options.TokenOptions
}
if options.RootCAs != nil {
defaultOptions.RootCAs = options.RootCAs
}
defaultOptions.IgnoreCertificate = options.IgnoreCertificate
defaultOptions.UpdateAccessTokenCallback = options.UpdateAccessTokenCallback
}
if logger == nil {
logger = createPassThroughLogger()
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: defaultOptions.IgnoreCertificate,
RootCAs: defaultOptions.RootCAs},
}
endpoint = strings.TrimRight(endpoint, "/")
tokenCallback := func(newToken string) {
c.options.TokenOptions.AccessToken = newToken
if c.options.UpdateAccessTokenCallback != nil {
c.options.UpdateAccessTokenCallback(newToken)
}
}
restClient := &restClient{
httpClient: &http.Client{Transport: tr},
logger: logger,
UpdateAccessTokenCallback: tokenCallback,
}
c = &Client{Endpoint: endpoint, restClient: restClient, logger: logger}
// Ensure a copy of options is made, rather than using a pointer
// which may change out from underneath if misused by the caller.
c.options = *defaultOptions
c.Status = &StatusAPI{c}
c.Tenants = &TenantsAPI{c}
c.Tasks = &TasksAPI{c}
c.Projects = &ProjectsAPI{c}
c.Flavors = &FlavorsAPI{c}
c.Images = &ImagesAPI{c}
c.Disks = &DisksAPI{c}
c.VMs = &VmAPI{c}
c.Hosts = &HostsAPI{c}
c.Deployments = &DeploymentsAPI{c}
c.ResourceTickets = &ResourceTicketsAPI{c}
c.Networks = &NetworksAPI{c}
c.VirtualSubnets = &VirtualSubnetsAPI{c}
c.Services = &ServicesAPI{c}
c.Auth = &AuthAPI{c}
c.AvailabilityZones = &AvailabilityZonesAPI{c}
c.Info = &InfoAPI{c}
c.Routers = &RoutersAPI{c}
c.Subnets = &SubnetsAPI{c}
// Tell the restClient about the Auth API so it can request new
// acces tokens when they expire
restClient.Auth = c.Auth
return
}
// Creates a new photon client with specified options and http.Client.
// Useful for functional testing where http calls must be mocked out.
// If options is nil, default options will be used.
func NewTestClient(endpoint string, options *ClientOptions, httpClient *http.Client) (c *Client) {
c = NewClient(endpoint, options, nil)
c.restClient.httpClient = httpClient
return
}
func createPassThroughLogger() (l *log.Logger) {
// ioutil.Discard makes all logging operation be a no-op.
return log.New(ioutil.Discard, "", log.LstdFlags)
}

View File

@@ -1,337 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for deployments API.
type DeploymentsAPI struct {
client *Client
}
var deploymentUrl string = rootUrl + "/deployments"
// Creates a deployment
func (api *DeploymentsAPI) Create(deploymentSpec *DeploymentCreateSpec) (task *Task, err error) {
body, err := json.Marshal(deploymentSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+deploymentUrl,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deletes a deployment with specified ID.
func (api *DeploymentsAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.getEntityUrl(id), api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deploys a deployment with specified ID.
func (api *DeploymentsAPI) Deploy(id string, config *DeploymentDeployOperation) (task *Task, err error) {
body, err := json.Marshal(config)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/deploy",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Destroys a deployment with specified ID.
func (api *DeploymentsAPI) Destroy(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/destroy",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Returns all deployments.
func (api *DeploymentsAPI) GetAll() (result *Deployments, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+deploymentUrl, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
result = &Deployments{}
err = json.NewDecoder(res.Body).Decode(result)
return
}
// Gets a deployment with the specified ID.
func (api *DeploymentsAPI) Get(id string) (deployment *Deployment, err error) {
res, err := api.client.restClient.Get(api.getEntityUrl(id), api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Deployment
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Gets all hosts with the specified deployment ID.
func (api *DeploymentsAPI) GetHosts(id string) (result *Hosts, err error) {
uri := api.getEntityUrl(id) + "/hosts"
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &Hosts{}
err = json.Unmarshal(res, result)
return
}
// Gets all the vms with the specified deployment ID.
func (api *DeploymentsAPI) GetVms(id string) (result *VMs, err error) {
uri := api.getEntityUrl(id) + "/vms"
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &VMs{}
err = json.Unmarshal(res, result)
return
}
// Initialize deployment migration from source to destination
func (api *DeploymentsAPI) InitializeDeploymentMigration(sourceAddress *InitializeMigrationOperation, id string) (task *Task, err error) {
body, err := json.Marshal(sourceAddress)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/initialize_migration",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Finalize deployment migration from source to destination
func (api *DeploymentsAPI) FinalizeDeploymentMigration(sourceAddress *FinalizeMigrationOperation, id string) (task *Task, err error) {
body, err := json.Marshal(sourceAddress)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/finalize_migration",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *DeploymentsAPI) SetSecurityGroups(id string, securityGroups *SecurityGroupsSpec) (*Task, error) {
return setSecurityGroups(api.client, api.getEntityUrl(id), securityGroups)
}
// Update image datastores of a deployment.
func (api *DeploymentsAPI) SetImageDatastores(id string, imageDatastores *ImageDatastores) (task *Task, err error) {
body, err := json.Marshal(imageDatastores)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/set_image_datastores",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Synchronizes hosts configurations
func (api *DeploymentsAPI) SyncHostsConfig(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/sync_hosts_config",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Pause system with specified deployment ID.
func (api *DeploymentsAPI) PauseSystem(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/pause_system",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Pause background tasks of system with specified deployment ID.
func (api *DeploymentsAPI) PauseBackgroundTasks(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/pause_background_tasks",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Pause background tasks of system with specified deployment ID.
func (api *DeploymentsAPI) ResumeSystem(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/resume_system",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Enable service type with specified deployment ID.
func (api *DeploymentsAPI) EnableServiceType(id string, serviceConfigSpec *ServiceConfigurationSpec) (task *Task, err error) {
body, err := json.Marshal(serviceConfigSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/enable_service_type",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Disable service type with specified deployment ID.
func (api *DeploymentsAPI) DisableServiceType(id string, serviceConfigSpec *ServiceConfigurationSpec) (task *Task, err error) {
body, err := json.Marshal(serviceConfigSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/disable_service_type",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Configure NSX.
func (api *DeploymentsAPI) ConfigureNsx(id string, nsxConfigSpec *NsxConfigurationSpec) (task *Task, err error) {
body, err := json.Marshal(nsxConfigSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.getEntityUrl(id)+"/configure_nsx",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *DeploymentsAPI) getEntityUrl(id string) (url string) {
return api.client.Endpoint + deploymentUrl + "/" + id
}

View File

@@ -1,65 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
)
// Contains functionality for disks API.
type DisksAPI struct {
client *Client
}
var diskUrl string = rootUrl + "/disks/"
// Gets a PersistentDisk for the disk with specified ID.
func (api *DisksAPI) Get(diskID string) (disk *PersistentDisk, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+diskUrl+diskID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
disk = &PersistentDisk{}
err = json.NewDecoder(res.Body).Decode(disk)
return
}
// Deletes a disk with the specified ID.
func (api *DisksAPI) Delete(diskID string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+diskUrl+diskID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified disk ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *DisksAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + diskUrl + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}

View File

@@ -1,108 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for flavors API.
type FlavorsAPI struct {
client *Client
}
// Options used for find/get APIs
type FlavorGetOptions struct {
Name string `urlParam:"name"`
Kind string `urlParam:"kind"`
}
var flavorUrl string = rootUrl + "/flavors"
// Creates a flavor.
func (api *FlavorsAPI) Create(spec *FlavorCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+flavorUrl,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets details of flavor with specified ID.
func (api *FlavorsAPI) Get(flavorID string) (flavor *Flavor, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+flavorUrl+"/"+flavorID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
flavor = &Flavor{}
err = json.NewDecoder(res.Body).Decode(flavor)
return
}
// Gets flavors using options to filter results. Returns all flavors if options is nil.
func (api *FlavorsAPI) GetAll(options *FlavorGetOptions) (flavors *FlavorList, err error) {
uri := api.client.Endpoint + flavorUrl
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
flavors = &FlavorList{}
err = json.Unmarshal(res, flavors)
return
}
// Deletes flavor with specified ID.
func (api *FlavorsAPI) Delete(flavorID string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+flavorUrl+"/"+flavorID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified flavor ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *FlavorsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + flavorUrl + "/" + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}

View File

@@ -1,219 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for hosts API.
type HostsAPI struct {
client *Client
}
var hostUrl string = rootUrl + "/hosts"
// Creates a host.
func (api *HostsAPI) Create(hostSpec *HostCreateSpec, deploymentId string) (task *Task, err error) {
body, err := json.Marshal(hostSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+deploymentUrl+"/"+deploymentId+"/hosts",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deletes a host with specified ID.
func (api *HostsAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+hostUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Returns all hosts
func (api *HostsAPI) GetAll() (result *Hosts, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+hostUrl, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
result = &Hosts{}
err = json.NewDecoder(res.Body).Decode(result)
return
}
// Gets a host with the specified ID.
func (api *HostsAPI) Get(id string) (host *Host, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+hostUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Host
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Sets host's availability zone.
func (api *HostsAPI) SetAvailabilityZone(id string, availabilityZone *HostSetAvailabilityZoneOperation) (task *Task, err error) {
body, err := json.Marshal(availabilityZone)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/set_availability_zone",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified host ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *HostsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + hostUrl + "/" + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Gets all the vms with the specified host ID.
func (api *HostsAPI) GetVMs(id string) (result *VMs, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+hostUrl+"/"+id+"/vms", api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
result = &VMs{}
err = json.NewDecoder(res.Body).Decode(result)
return
}
// provision the host with the specified id
func (api *HostsAPI) Provision(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/provision",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Suspend the host with the specified id
func (api *HostsAPI) Suspend(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/suspend",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Resume the host with the specified id
func (api *HostsAPI) Resume(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/resume",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Host with the specified id enter maintenance mode
func (api *HostsAPI) EnterMaintenanceMode(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/enter_maintenance",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Host with the specified id exit maintenance mode
func (api *HostsAPI) ExitMaintenanceMode(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+hostUrl+"/"+id+"/exit_maintenance",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,182 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
"io"
)
// Contains functionality for images API.
type ImagesAPI struct {
client *Client
}
// Options for GetImage API.
type ImageGetOptions struct {
Name string `urlParam:"name"`
}
var imageUrl string = rootUrl + "/images"
// Uploads a new image, reading from the specified image path.
// If options is nil, default options are used.
func (api *ImagesAPI) CreateFromFile(imagePath string, options *ImageCreateOptions) (task *Task, err error) {
params := imageCreateOptionsToMap(options)
res, err := api.client.restClient.MultipartUploadFile(api.client.Endpoint+imageUrl, imagePath, params, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
result, err := getTask(getError(res))
return result, err
}
// Uploads a new image, reading from the specified io.Reader.
// Name is a descriptive name of the image, it is used in the filename field of the Content-Disposition header,
// and does not need to be unique.
// If options is nil, default options are used.
func (api *ImagesAPI) Create(reader io.ReadSeeker, name string, options *ImageCreateOptions) (task *Task, err error) {
params := imageCreateOptionsToMap(options)
res, err := api.client.restClient.MultipartUpload(api.client.Endpoint+imageUrl, reader, name, params, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
result, err := getTask(getError(res))
return result, err
}
// Gets all images on this photon instance.
func (api *ImagesAPI) GetAll(options *ImageGetOptions) (images *Images, err error) {
uri := api.client.Endpoint + imageUrl
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
images = &Images{}
err = json.Unmarshal(res, images)
return
}
// Gets details of image with the specified ID.
func (api *ImagesAPI) Get(imageID string) (image *Image, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+imageUrl+"/"+imageID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Image
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Deletes image with the specified ID.
func (api *ImagesAPI) Delete(imageID string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+imageUrl+"/"+imageID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
result, err := getTask(getError(res))
return result, err
}
// Gets all tasks with the specified image ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *ImagesAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + imageUrl + "/" + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Gets IAM Policy of an image.
func (api *ImagesAPI) GetIam(imageID string) (policy *[]PolicyEntry, err error) {
res, err := api.client.restClient.Get(
api.client.Endpoint+imageUrl+"/"+imageID+"/iam",
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result []PolicyEntry
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Sets IAM Policy on an image.
func (api *ImagesAPI) SetIam(imageID string, policy *[]PolicyEntry) (task *Task, err error) {
body, err := json.Marshal(policy)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+imageUrl+"/"+imageID+"/iam",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Modifies IAM Policy on an image.
func (api *ImagesAPI) ModifyIam(imageID string, policyDelta *PolicyDelta) (task *Task, err error) {
body, err := json.Marshal(policyDelta)
if err != nil {
return
}
res, err := api.client.restClient.Put(
api.client.Endpoint+imageUrl+"/"+imageID+"/iam",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func imageCreateOptionsToMap(opts *ImageCreateOptions) map[string]string {
if opts == nil {
return nil
}
return map[string]string{
"ImageReplication": opts.ReplicationType,
}
}

View File

@@ -1,39 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
)
type InfoAPI struct {
client *Client
}
var infoUrl = rootUrl + "/info"
// Get info
func (api *InfoAPI) Get() (info *Info, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+infoUrl, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
info = new(Info)
err = json.NewDecoder(res.Body).Decode(info)
return
}

View File

@@ -1,34 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"jwttoken.go",
"oidcclient.go",
"oidcclient_sspi.go",
"oidcclient_sspi_unsupported.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/vmware/photon-controller-go-sdk/photon/lightwave",
importpath = "github.com/vmware/photon-controller-go-sdk/photon/lightwave",
visibility = ["//visibility:public"],
deps = select({
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/github.com/vmware/photon-controller-go-sdk/SSPI:go_default_library",
],
"//conditions:default": [],
}),
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,59 +0,0 @@
package lightwave
import (
"encoding/base64"
"encoding/json"
"strings"
)
type JWTToken struct {
TokenId string `json:"jti"`
Algorithm string `json:"alg"`
Subject string `json:"sub"`
Audience []string `json:"aud"`
Groups []string `json:"groups"`
Issuer string `json:"iss"`
IssuedAt int64 `json:"iat"`
Expires int64 `json:"exp"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
TokenClass string `json:"token_class"`
Tenant string `json:"tenant"`
// It's possible to have more fields depending on how Lightwave defines the token.
// This covers all the fields we currently have.
}
// A JSON web token is a set of Base64 encoded strings separated by a period (.)
// When decoded, it will either be JSON text or a signature
// Here we decode the strings into a single token structure. We do not parse the signature.
func ParseTokenDetails(token string) (jwtToken *JWTToken) {
jwtToken = &JWTToken{}
chunks := strings.Split(token, ".")
for _, chunk := range chunks {
json_string, err := base64.RawURLEncoding.DecodeString(chunk)
if err == nil {
// Ignore errors. We expect that the signature is not JSON,
// so unmarshalling it will fail. That's fine. We'll extract
// all the data we can.
_ = json.Unmarshal(json_string, &jwtToken)
}
}
return jwtToken
}
// A JSON web token is a set of Base64 encoded strings separated by a period (.)
// When decoded, it will either be JSON text or a signature
// Here we parse the full JSON text. We do not parse the signature.
func ParseRawTokenDetails(token string) (jwtToken []string, err error) {
chunks := strings.Split(token, ".")
for _, chunk := range chunks {
jsonString, err := base64.RawURLEncoding.DecodeString(chunk)
if err == nil {
jwtToken = append(jwtToken, string(jsonString))
}
}
return jwtToken, err
}

View File

@@ -1,238 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package lightwave
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
)
const tokenScope string = "openid offline_access"
type OIDCClient struct {
httpClient *http.Client
logger *log.Logger
Endpoint string
Options *OIDCClientOptions
}
type OIDCClientOptions struct {
// Whether or not to ignore any TLS errors when talking to photon,
// false by default.
IgnoreCertificate bool
// List of root CA's to use for server validation
// nil by default.
RootCAs *x509.CertPool
// The scope values to use when requesting tokens
TokenScope string
}
func NewOIDCClient(endpoint string, options *OIDCClientOptions, logger *log.Logger) (c *OIDCClient) {
if logger == nil {
logger = log.New(ioutil.Discard, "", log.LstdFlags)
}
options = buildOptions(options)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: options.IgnoreCertificate,
RootCAs: options.RootCAs},
}
c = &OIDCClient{
httpClient: &http.Client{Transport: tr},
logger: logger,
Endpoint: strings.TrimRight(endpoint, "/"),
Options: options,
}
return
}
func buildOptions(options *OIDCClientOptions) (result *OIDCClientOptions) {
result = &OIDCClientOptions{
TokenScope: tokenScope,
}
if options == nil {
return
}
result.IgnoreCertificate = options.IgnoreCertificate
if options.RootCAs != nil {
result.RootCAs = options.RootCAs
}
if options.TokenScope != "" {
result.TokenScope = options.TokenScope
}
return
}
func (client *OIDCClient) buildUrl(path string) (url string) {
return fmt.Sprintf("%s%s", client.Endpoint, path)
}
// Cert download helper
const certDownloadPath string = "/afd/vecs/ssl"
type lightWaveCert struct {
Value string `json:"encoded"`
}
func (client *OIDCClient) GetRootCerts() (certList []*x509.Certificate, err error) {
// turn TLS verification off for
originalTr := client.httpClient.Transport
defer client.setTransport(originalTr)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client.setTransport(tr)
// get the certs
resp, err := client.httpClient.Get(client.buildUrl(certDownloadPath))
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("Unexpected error retrieving auth server certs: %v %s", resp.StatusCode, resp.Status)
return
}
// parse the certs
certsData := &[]lightWaveCert{}
err = json.NewDecoder(resp.Body).Decode(certsData)
if err != nil {
return
}
certList = make([]*x509.Certificate, len(*certsData))
for idx, cert := range *certsData {
block, _ := pem.Decode([]byte(cert.Value))
if block == nil {
err = fmt.Errorf("Unexpected response format: %v", certsData)
return nil, err
}
decodedCert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
}
certList[idx] = decodedCert
}
return
}
func (client *OIDCClient) setTransport(tr http.RoundTripper) {
client.httpClient.Transport = tr
}
// Toke request helpers
const tokenPath string = "/openidconnect/token"
const passwordGrantFormatString = "grant_type=password&username=%s&password=%s&scope=%s"
const refreshTokenGrantFormatString = "grant_type=refresh_token&refresh_token=%s"
type OIDCTokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token,omitempty"`
IdToken string `json:"id_token"`
TokenType string `json:"token_type"`
}
func (client *OIDCClient) GetTokenByPasswordGrant(username string, password string) (tokens *OIDCTokenResponse, err error) {
username = url.QueryEscape(username)
password = url.QueryEscape(password)
body := fmt.Sprintf(passwordGrantFormatString, username, password, client.Options.TokenScope)
return client.getToken(body)
}
func (client *OIDCClient) GetTokenByRefreshTokenGrant(refreshToken string) (tokens *OIDCTokenResponse, err error) {
body := fmt.Sprintf(refreshTokenGrantFormatString, refreshToken)
return client.getToken(body)
}
func (client *OIDCClient) getToken(body string) (tokens *OIDCTokenResponse, err error) {
request, err := http.NewRequest("POST", client.buildUrl(tokenPath), strings.NewReader(body))
if err != nil {
return nil, err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.httpClient.Do(request)
if err != nil {
return nil, err
}
defer resp.Body.Close()
err = client.checkResponse(resp)
if err != nil {
return nil, err
}
tokens = &OIDCTokenResponse{}
err = json.NewDecoder(resp.Body).Decode(tokens)
if err != nil {
return nil, err
}
return
}
type OIDCError struct {
Code string `json:"error"`
Message string `json:"error_description"`
}
func (e OIDCError) Error() string {
return fmt.Sprintf("%v: %v", e.Code, e.Message)
}
func (client *OIDCClient) checkResponse(response *http.Response) (err error) {
if response.StatusCode/100 == 2 {
return
}
respBody, readErr := ioutil.ReadAll(response.Body)
if err != nil {
return fmt.Errorf(
"Status: %v, Body: %v [%v]", response.Status, string(respBody[:]), readErr)
}
var oidcErr OIDCError
err = json.Unmarshal(respBody, &oidcErr)
if err != nil {
return fmt.Errorf(
"Status: %v, Body: %v [%v]", response.Status, string(respBody[:]), readErr)
}
return oidcErr
}

View File

@@ -1,131 +0,0 @@
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
// +build windows
package lightwave
import (
"encoding/base64"
"fmt"
"github.com/vmware/photon-controller-go-sdk/SSPI"
"math/rand"
"net"
"net/url"
"strings"
"time"
)
const gssTicketGrantFormatString = "grant_type=urn:vmware:grant_type:gss_ticket&gss_ticket=%s&context_id=%s&scope=%s"
// GetTokensFromWindowsLogInContext gets tokens based on Windows logged in context
// Here is how it works:
// 1. Get the SPN (Service Principal Name) in the format host/FQDN of lightwave. This is needed for SSPI/Kerberos protocol
// 2. Call Windows API AcquireCredentialsHandle() using SSPI library. This will give the current users credential handle
// 3. Using this handle call Windows API AcquireCredentialsHandle(). This will give you byte[]
// 4. Encode this byte[] and send it to OIDC server over HTTP (using POST)
// 5. OIDC server can send either of the following
// - Access tokens. In this case return access tokens to client
// - Error in the format: invalid_grant: gss_continue_needed:'context id':'token from server'
// 6. In case you get error, parse it and get the token from server
// 7. Feed this token to step 3 and repeat steps till you get the access tokens from server
func (client *OIDCClient) GetTokensFromWindowsLogInContext() (tokens *OIDCTokenResponse, err error) {
spn, err := client.buildSPN()
if err != nil {
return nil, err
}
auth, _ := SSPI.GetAuth("", "", spn, "")
userContext, err := auth.InitialBytes()
if err != nil {
return nil, err
}
// In case of multiple req/res between client and server (as explained in above comment),
// server needs to maintain the mapping of context id -> token
// So we need to generate random string as a context id
// If we use same context id for all the requests, results can be erroneous
contextId := client.generateRandomString()
body := fmt.Sprintf(gssTicketGrantFormatString, url.QueryEscape(base64.StdEncoding.EncodeToString(userContext)), contextId, client.Options.TokenScope)
tokens, err = client.getToken(body)
for {
if err == nil {
break
}
// In case of error the response will be in format: invalid_grant: gss_continue_needed:'context id':'token from server'
gssToken := client.validateAndExtractGSSResponse(err, contextId)
if gssToken == "" {
return nil, err
}
data, err := base64.StdEncoding.DecodeString(gssToken)
if err != nil {
return nil, err
}
userContext, err := auth.NextBytes(data)
body := fmt.Sprintf(gssTicketGrantFormatString, url.QueryEscape(base64.StdEncoding.EncodeToString(userContext)), contextId, client.Options.TokenScope)
tokens, err = client.getToken(body)
}
return tokens, err
}
// Gets the SPN (Service Principal Name) in the format host/FQDN of lightwave
func (client *OIDCClient) buildSPN() (spn string, err error) {
u, err := url.Parse(client.Endpoint)
if err != nil {
return "", err
}
host, _, err := net.SplitHostPort(u.Host)
if err != nil {
return "", err
}
addr, err := net.LookupAddr(host)
if err != nil {
return "", err
}
var s = strings.TrimSuffix(addr[0], ".")
return "host/" + s, nil
}
// validateAndExtractGSSResponse parse the error from server and returns token from server
// In case of error from the server, response will be in format: invalid_grant: gss_continue_needed:'context id':'token from server'
// So, we check for the above format in error and then return the token from server
// If error is not in above format, we return empty string
func (client *OIDCClient) validateAndExtractGSSResponse(err error, contextId string) string {
parts := strings.Split(err.Error(), ":")
if !(len(parts) == 4 && strings.TrimSpace(parts[1]) == "gss_continue_needed" && parts[2] == contextId) {
return ""
} else {
return parts[3]
}
}
func (client *OIDCClient) generateRandomString() string {
const length = 10
const asciiA = 65
const asciiZ = 90
rand.Seed(time.Now().UTC().UnixNano())
bytes := make([]byte, length)
for i := 0; i < length; i++ {
bytes[i] = byte(randInt(asciiA, asciiZ))
}
return string(bytes)
}
func randInt(min int, max int) int {
return min + rand.Intn(max-min)
}

View File

@@ -1,18 +0,0 @@
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
// +build !windows
package lightwave
import "errors"
func (client *OIDCClient) GetTokensFromWindowsLogInContext() (tokens *OIDCTokenResponse, err error) {
return nil, errors.New("Not supported on this OS")
}

View File

@@ -1,101 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for networks API.
type NetworksAPI struct {
client *Client
}
// Options used for GetAll API
type NetworkGetOptions struct {
Name string `urlParam:"name"`
}
var networkUrl string = rootUrl + "/subnets"
// Creates a network.
func (api *NetworksAPI) Create(networkSpec *NetworkCreateSpec) (task *Task, err error) {
body, err := json.Marshal(networkSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+networkUrl,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deletes a network with specified ID.
func (api *NetworksAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+networkUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets a network with the specified ID.
func (api *NetworksAPI) Get(id string) (network *Network, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+networkUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Network
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Returns all networks
func (api *NetworksAPI) GetAll(options *NetworkGetOptions) (result *Networks, err error) {
uri := api.client.Endpoint + networkUrl
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
result = &Networks{}
err = json.Unmarshal(res, result)
return
}
// Sets default network.
func (api *NetworksAPI) SetDefault(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.client.Endpoint+networkUrl+"/"+id+"/set_default",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,208 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for projects API.
type ProjectsAPI struct {
client *Client
}
// Options for GetDisks API.
type DiskGetOptions struct {
Name string `urlParam:"name"`
}
// Options for GetDisks API.
type VmGetOptions struct {
Name string `urlParam:"name"`
}
var projectUrl string = rootUrl + "/projects/"
// Deletes the project with specified ID. Any VMs, disks, etc., owned by the project must be deleted first.
func (api *ProjectsAPI) Delete(projectID string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+projectUrl+projectID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Creates a disk on the specified project.
func (api *ProjectsAPI) CreateDisk(projectID string, spec *DiskCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+projectUrl+projectID+"/disks",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets disks for project with the specified ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *ProjectsAPI) GetDisks(projectID string, options *DiskGetOptions) (result *DiskList, err error) {
uri := api.client.Endpoint + projectUrl + projectID + "/disks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &DiskList{}
err = json.Unmarshal(res, result)
return
}
// Creates a VM on the specified project.
func (api *ProjectsAPI) CreateVM(projectID string, spec *VmCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+projectUrl+projectID+"/vms",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified project ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *ProjectsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + projectUrl + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Gets vms for project with the specified ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *ProjectsAPI) GetVMs(projectID string, options *VmGetOptions) (result *VMs, err error) {
uri := api.client.Endpoint + projectUrl + projectID + "/vms"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &VMs{}
err = json.Unmarshal(res, result)
return
}
// Creates a service on the specified project.
func (api *ProjectsAPI) CreateService(projectID string, spec *ServiceCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+projectUrl+projectID+"/services",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets services for project with the specified ID
func (api *ProjectsAPI) GetServices(projectID string) (result *Services, err error) {
uri := api.client.Endpoint + projectUrl + projectID + "/services"
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &Services{}
err = json.Unmarshal(res, result)
return
}
// Gets the project with a specified ID.
func (api *ProjectsAPI) Get(id string) (project *ProjectCompact, err error) {
res, err := api.client.restClient.Get(api.getEntityUrl(id), api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
project = &ProjectCompact{}
err = json.NewDecoder(res.Body).Decode(project)
return
}
// Set security groups for this project, overwriting any existing ones.
func (api *ProjectsAPI) SetSecurityGroups(projectID string, securityGroups *SecurityGroupsSpec) (*Task, error) {
return setSecurityGroups(api.client, api.getEntityUrl(projectID), securityGroups)
}
func (api *ProjectsAPI) getEntityUrl(id string) string {
return api.client.Endpoint + projectUrl + id
}
// Creates a router on the specified project.
func (api *ProjectsAPI) CreateRouter(projectID string, spec *RouterCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+projectUrl+projectID+"/routers",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,55 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
)
// Contains functionality for hosts API.
type ResourceTicketsAPI struct {
client *Client
}
var resourceTicketUrl string = rootUrl + "/resource-tickets/"
// Gets all tasks with the specified resource ticket ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *ResourceTicketsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + resourceTicketUrl + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Gets the resource ticket with a specified ID.
func (api *ResourceTicketsAPI) Get(id string) (resourceTicket *ResourceTicket, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+resourceTicketUrl+"/"+id,
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
resourceTicket = &ResourceTicket{}
err = json.NewDecoder(res.Body).Decode(resourceTicket)
return
}

View File

@@ -1,326 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"crypto/rand"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"strings"
)
type restClient struct {
httpClient *http.Client
logger *log.Logger
Auth *AuthAPI
UpdateAccessTokenCallback TokenCallback
}
type request struct {
Method string
URL string
ContentType string
Body io.Reader
Tokens *TokenOptions
}
type page struct {
Items []interface{} `json:"items"`
NextPageLink string `json:"nextPageLink"`
PreviousPageLink string `json:"previousPageLink"`
}
type documentList struct {
Items []interface{}
}
type bodyRewinder func() io.Reader
const appJson string = "application/json"
// Root URL specifies the API version.
const rootUrl string = "/v1"
// From https://golang.org/src/mime/multipart/writer.go
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
func (client *restClient) AppendSlice(origSlice []interface{}, dataToAppend []interface{}) []interface{} {
origLen := len(origSlice)
newLen := origLen + len(dataToAppend)
if newLen > cap(origSlice) {
newSlice := make([]interface{}, (newLen+1)*2)
copy(newSlice, origSlice)
origSlice = newSlice
}
origSlice = origSlice[0:newLen]
copy(origSlice[origLen:newLen], dataToAppend)
return origSlice
}
func (client *restClient) Get(url string, tokens *TokenOptions) (res *http.Response, err error) {
req := request{"GET", url, "", nil, tokens}
res, err = client.SendRequest(&req, nil)
return
}
func (client *restClient) GetList(endpoint string, url string, tokens *TokenOptions) (result []byte, err error) {
req := request{"GET", url, "", nil, tokens}
res, err := client.SendRequest(&req, nil)
if err != nil {
return
}
res, err = getError(res)
if err != nil {
return
}
decoder := json.NewDecoder(res.Body)
decoder.UseNumber()
page := &page{}
err = decoder.Decode(page)
if err != nil {
return
}
documentList := &documentList{}
documentList.Items = client.AppendSlice(documentList.Items, page.Items)
for page.NextPageLink != "" {
req = request{"GET", endpoint + page.NextPageLink, "", nil, tokens}
res, err = client.SendRequest(&req, nil)
if err != nil {
return
}
res, err = getError(res)
if err != nil {
return
}
decoder = json.NewDecoder(res.Body)
decoder.UseNumber()
page.NextPageLink = ""
page.PreviousPageLink = ""
err = decoder.Decode(page)
if err != nil {
return
}
documentList.Items = client.AppendSlice(documentList.Items, page.Items)
}
result, err = json.Marshal(documentList)
return
}
func (client *restClient) Post(url string, contentType string, body io.ReadSeeker, tokens *TokenOptions) (res *http.Response, err error) {
if contentType == "" {
contentType = appJson
}
req := request{"POST", url, contentType, body, tokens}
rewinder := func() io.Reader {
body.Seek(0, 0)
return body
}
res, err = client.SendRequest(&req, rewinder)
return
}
func (client *restClient) Patch(url string, contentType string, body io.ReadSeeker, tokens *TokenOptions) (res *http.Response, err error) {
if contentType == "" {
contentType = appJson
}
req := request{"PATCH", url, contentType, body, tokens}
rewinder := func() io.Reader {
body.Seek(0, 0)
return body
}
res, err = client.SendRequest(&req, rewinder)
return
}
func (client *restClient) Put(url string, contentType string, body io.ReadSeeker, tokens *TokenOptions) (res *http.Response, err error) {
if contentType == "" {
contentType = appJson
}
req := request{"PUT", url, contentType, body, tokens}
rewinder := func() io.Reader {
body.Seek(0, 0)
return body
}
res, err = client.SendRequest(&req, rewinder)
return
}
func (client *restClient) Delete(url string, tokens *TokenOptions) (res *http.Response, err error) {
req := request{"DELETE", url, "", nil, tokens}
res, err = client.SendRequest(&req, nil)
return
}
func (client *restClient) SendRequest(req *request, bodyRewinder bodyRewinder) (res *http.Response, err error) {
res, err = client.sendRequestHelper(req)
// In most cases, we'll return immediately
// If the operation succeeded, but we got a 401 response and if we're using
// authentication, then we'll look into the body to see if the token expired
if err != nil {
return res, err
}
if res.StatusCode != 401 {
// It's not a 401, so the token didn't expire
return res, err
}
if req.Tokens == nil || req.Tokens.AccessToken == "" {
// We don't have a token, so we can't renew the token, no need to proceed
return res, err
}
// We're going to look in the body to see if it failed because the token expired
// This means we need to read the body, but the functions that call us also
// expect to read the body. So we read the body, then create a new reader
// so they can read the body as normal.
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return res, err
}
res.Body = ioutil.NopCloser(bytes.NewReader(body))
// Now see if we had an expired token or not
var apiError ApiError
err = json.Unmarshal(body, &apiError)
if err != nil {
return res, err
}
if apiError.Code != "ExpiredAuthToken" {
return res, nil
}
// We were told that the access token expired, so try to renew it.
// Note that this looks recursive because GetTokensByRefreshToken() will
// call the /auth API, and therefore SendRequest(). However, it calls
// without a token, so we avoid having a loop
newTokens, err := client.Auth.GetTokensByRefreshToken(req.Tokens.RefreshToken)
if err != nil {
return res, err
}
req.Tokens.AccessToken = newTokens.AccessToken
if client.UpdateAccessTokenCallback != nil {
client.UpdateAccessTokenCallback(newTokens.AccessToken)
}
if req.Body != nil && bodyRewinder != nil {
req.Body = bodyRewinder()
}
res, err = client.sendRequestHelper(req)
return res, nil
}
func (client *restClient) sendRequestHelper(req *request) (res *http.Response, err error) {
r, err := http.NewRequest(req.Method, req.URL, req.Body)
if err != nil {
client.logger.Printf("An error occured creating request %s on %s. Error: %s", req.Method, req.URL, err)
return
}
if req.ContentType != "" {
r.Header.Add("Content-Type", req.ContentType)
}
if req.Tokens != nil && req.Tokens.AccessToken != "" {
r.Header.Add("Authorization", "Bearer "+req.Tokens.AccessToken)
}
res, err = client.httpClient.Do(r)
if err != nil {
client.logger.Printf("An error occured when calling %s on %s. Error: %s", req.Method, req.URL, err)
return
}
client.logger.Printf("[%s] %s - %s %s", res.Header.Get("request-id"), res.Status, req.Method, req.URL)
return
}
func (client *restClient) MultipartUploadFile(url, filePath string, params map[string]string, tokens *TokenOptions) (res *http.Response, err error) {
file, err := os.Open(filePath)
if err != nil {
return
}
defer file.Close()
return client.MultipartUpload(url, file, filepath.Base(filePath), params, tokens)
}
func (client *restClient) MultipartUpload(url string, reader io.ReadSeeker, filename string, params map[string]string, tokens *TokenOptions) (res *http.Response, err error) {
boundary := client.randomBoundary()
multiReader, contentType := client.createMultiReader(reader, filename, params, boundary)
rewinder := func() io.Reader {
reader.Seek(0, 0)
multiReader, _ := client.createMultiReader(reader, filename, params, boundary)
return multiReader
}
res, err = client.SendRequest(&request{"POST", url, contentType, multiReader, tokens}, rewinder)
return
}
func (client *restClient) createMultiReader(reader io.ReadSeeker, filename string, params map[string]string, boundary string) (io.Reader, string) {
// The mime/multipart package does not support streaming multipart data from disk,
// at least not without complicated, problematic goroutines that simultaneously read/write into a buffer.
// A much easier approach is to just construct the multipart request by hand, using io.MultiPart to
// concatenate the parts of the request together into a single io.Reader.
parts := []io.Reader{}
// Create a part for each key, val pair in params
for k, v := range params {
parts = append(parts, client.createFieldPart(k, v, boundary))
}
start := fmt.Sprintf("\r\n--%s\r\n", boundary)
start += fmt.Sprintf("Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n", quoteEscaper.Replace(filename))
start += fmt.Sprintf("Content-Type: application/octet-stream\r\n\r\n")
end := fmt.Sprintf("\r\n--%s--", boundary)
// The request will consist of a reader to begin the request, a reader which points
// to the file data on disk, and a reader containing the closing boundary of the request.
parts = append(parts, strings.NewReader(start), reader, strings.NewReader(end))
contentType := fmt.Sprintf("multipart/form-data; boundary=%s", boundary)
return io.MultiReader(parts...), contentType
}
// From https://golang.org/src/mime/multipart/writer.go
func (client *restClient) randomBoundary() string {
var buf [30]byte
_, err := io.ReadFull(rand.Reader, buf[:])
if err != nil {
panic(err)
}
return fmt.Sprintf("%x", buf[:])
}
// Creates a reader that encapsulates a single multipart form part
func (client *restClient) createFieldPart(fieldname, value, boundary string) io.Reader {
str := fmt.Sprintf("\r\n--%s\r\n", boundary)
str += fmt.Sprintf("Content-Disposition: form-data; name=\"%s\"\r\n\r\n", quoteEscaper.Replace(fieldname))
str += value
return strings.NewReader(str)
}

View File

@@ -1,90 +0,0 @@
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for routers API.
type RoutersAPI struct {
client *Client
}
var routerUrl string = rootUrl + "/routers/"
// Gets a router with the specified ID.
func (api *RoutersAPI) Get(id string) (router *Router, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+routerUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Router
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Updates router's attributes.
func (api *RoutersAPI) UpdateRouter(id string, routerSpec *RouterUpdateSpec) (task *Task, err error) {
body, err := json.Marshal(routerSpec)
if err != nil {
return
}
res, err := api.client.restClient.Put(
api.client.Endpoint+routerUrl+id,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deletes a router with specified ID.
func (api *RoutersAPI) Delete(routerID string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+routerUrl+routerID, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Creates a subnet on the specified router.
func (api *RoutersAPI) CreateSubnet(routerID string, spec *SubnetCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+routerUrl+routerID+"/subnets",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,139 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for services API.
type ServicesAPI struct {
client *Client
}
var serviceUrl = rootUrl + "/services/"
// Extended Properties
const (
ExtendedPropertyDNS = "dns"
ExtendedPropertyGateway = "gateway"
ExtendedPropertyNetMask = "netmask"
ExtendedPropertyLoadBalancerIP = "load_balancer_ip"
ExtendedPropertyNumberOfMasters = "number_of_masters"
ExtendedPropertyMasterIPs = "master_ips"
ExtendedPropertyMasterIP = "master_ip"
ExtendedPropertyMasterIP2 = "master_ip2"
ExtendedPropertyContainerNetwork = "container_network"
ExtendedPropertyZookeeperIP1 = "zookeeper_ip1"
ExtendedPropertyZookeeperIP2 = "zookeeper_ip2"
ExtendedPropertyZookeeperIP3 = "zookeeper_ip3"
ExtendedPropertyNumberOfETCDs = "number_of_etcds"
ExtendedPropertyETCDIP1 = "etcd_ip1"
ExtendedPropertyETCDIP2 = "etcd_ip2"
ExtendedPropertyETCDIP3 = "etcd_ip3"
ExtendedPropertySSHKey = "ssh_key"
ExtendedPropertyRegistryCACert = "registry_ca_cert"
ExtendedPropertyAdminPassword = "admin_password"
)
// Deletes a service with specified ID.
func (api *ServicesAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+serviceUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets a service with the specified ID.
func (api *ServicesAPI) Get(id string) (service *Service, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+serviceUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Service
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Gets vms for service with the specified ID.
func (api *ServicesAPI) GetVMs(id string) (result *VMs, err error) {
uri := api.client.Endpoint + serviceUrl + id + "/vms"
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &VMs{}
err = json.Unmarshal(res, result)
return
}
// Resize a service to specified count.
func (api *ServicesAPI) Resize(id string, resize *ServiceResizeOperation) (task *Task, err error) {
body, err := json.Marshal(resize)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+serviceUrl+id+"/resize",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Start a background process to recreate failed VMs in a service with the specified ID.
func (api *ServicesAPI) TriggerMaintenance(id string) (task *Task, err error) {
body := []byte{}
res, err := api.client.restClient.Post(
api.client.Endpoint+serviceUrl+id+"/trigger_maintenance",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Change a service version to the specified image by destroying and recreating the VMs.
func (api *ServicesAPI) ChangeVersion(id string, changeVersion *ServiceChangeVersionOperation) (task *Task, err error) {
body, err := json.Marshal(changeVersion)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+serviceUrl+id+"/change_version",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,37 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
)
// Contains functionality for status API.
type StatusAPI struct {
client *Client
}
var statusUrl string = rootUrl + "/status"
// Returns the status of an photon endpoint.
func (api *StatusAPI) Get() (status *Status, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+statusUrl, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
status = &Status{}
err = json.NewDecoder(res.Body).Decode(status)
return
}

View File

@@ -1,72 +0,0 @@
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains functionality for subnets API.
type SubnetsAPI struct {
client *Client
}
var subnetUrl string = "/temp-subnets/"
// Deletes a subnet with the specified ID.
func (api *SubnetsAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+subnetUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets a subnet with the specified ID.
func (api *SubnetsAPI) Get(id string) (subnet *Subnet, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+subnetUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
var result Subnet
err = json.NewDecoder(res.Body).Decode(&result)
return &result, nil
}
// Updates subnet's attributes.
func (api *SubnetsAPI) Update(id string, subnetSpec *SubnetUpdateSpec) (task *Task, err error) {
body, err := json.Marshal(subnetSpec)
if err != nil {
return
}
res, err := api.client.restClient.Put(
api.client.Endpoint+subnetUrl+id,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,108 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"encoding/json"
"time"
)
// Contains functionality for tasks API.
type TasksAPI struct {
client *Client
}
var taskUrl string = rootUrl + "/tasks"
// Gets a task by ID.
func (api *TasksAPI) Get(id string) (task *Task, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+taskUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
result, err := getTask(getError(res))
return result, err
}
// Gets all tasks, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *TasksAPI) GetAll(options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + taskUrl
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Waits for a task to complete by polling the tasks API until a task returns with
// the state COMPLETED or ERROR. Will wait no longer than the duration specified by timeout.
func (api *TasksAPI) WaitTimeout(id string, timeout time.Duration) (task *Task, err error) {
start := time.Now()
numErrors := 0
maxErrors := api.client.options.TaskRetryCount
for time.Since(start) < timeout {
task, err = api.Get(id)
if err != nil {
switch err.(type) {
// If an ApiError comes back, something is wrong, return the error to the caller
case ApiError:
return
// For other errors, retry before giving up
default:
numErrors++
if numErrors > maxErrors {
return
}
}
} else {
// Reset the error count any time a successful call is made
numErrors = 0
if task.State == "COMPLETED" {
return
}
if task.State == "ERROR" {
err = TaskError{task.ID, getFailedStep(task)}
return
}
}
time.Sleep(api.client.options.TaskPollDelay)
}
err = TaskTimeoutError{id}
return
}
// Waits for a task to complete by polling the tasks API until a task returns with
// the state COMPLETED or ERROR.
func (api *TasksAPI) Wait(id string) (task *Task, err error) {
return api.WaitTimeout(id, api.client.options.TaskPollTimeout)
}
// Gets the failed step in the task to get error details for failed task.
func getFailedStep(task *Task) (step Step) {
var errorStep Step
for _, s := range task.Steps {
if s.State == "ERROR" {
errorStep = s
break
}
}
return errorStep
}

View File

@@ -1,213 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
"fmt"
)
// Contains functionality for tenants API.
type TenantsAPI struct {
client *Client
}
// Options for GetResourceTickets API.
type ResourceTicketGetOptions struct {
Name string `urlParam:"name"`
}
// Options for GetProjects API.
type ProjectGetOptions struct {
Name string `urlParam:"name"`
}
var tenantUrl string = rootUrl + "/tenants"
// Returns all tenants on an photon instance.
func (api *TenantsAPI) GetAll() (result *Tenants, err error) {
uri := api.client.Endpoint + tenantUrl
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &Tenants{}
err = json.Unmarshal(res, result)
return
}
// Creates a tenant.
func (api *TenantsAPI) Create(tenantSpec *TenantCreateSpec) (task *Task, err error) {
body, err := json.Marshal(tenantSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+tenantUrl,
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Deletes the tenant with specified ID. Any projects, VMs, disks, etc., owned by the tenant must be deleted first.
func (api *TenantsAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+tenantUrl+"/"+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Creates a resource ticket on the specified tenant.
func (api *TenantsAPI) CreateResourceTicket(tenantId string, spec *ResourceTicketCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+tenantUrl+"/"+tenantId+"/resource-tickets",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets resource tickets for tenant with the specified ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *TenantsAPI) GetResourceTickets(tenantId string, options *ResourceTicketGetOptions) (tickets *ResourceList, err error) {
uri := api.client.Endpoint + tenantUrl + "/" + tenantId + "/resource-tickets"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
tickets = &ResourceList{}
err = json.Unmarshal(res, tickets)
return
}
// Creates a project on the specified tenant.
func (api *TenantsAPI) CreateProject(tenantId string, spec *ProjectCreateSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+tenantUrl+"/"+tenantId+"/projects",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets the projects for tenant with the specified ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *TenantsAPI) GetProjects(tenantId string, options *ProjectGetOptions) (result *ProjectList, err error) {
uri := api.client.Endpoint + tenantUrl + "/" + tenantId + "/projects"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &(ProjectList{})
err = json.Unmarshal(res, result)
return
}
// Gets all tasks with the specified tenant ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *TenantsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + tenantUrl + "/" + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
// Gets a tenant with the specified ID or name
func (api *TenantsAPI) Get(identity string) (tenant *Tenant, err error) {
res, err := api.client.restClient.Get(api.getEntityUrl(identity), api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
tenant = &Tenant{}
if res != nil {
err = json.NewDecoder(res.Body).Decode(tenant)
// ID corresponds to the tenant ID found, return tenant
if err == nil {
return
}
}
// Find by Name
uri := api.client.Endpoint + tenantUrl + "?name=" + identity
res2, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
tenants := &Tenants{}
err = json.Unmarshal(res2, tenants)
if err != nil {
return
}
if len(tenants.Items) < 1 {
err = fmt.Errorf("Cannot find a tenant with id or name match %s", identity)
return
}
tenant = &(tenants.Items[0])
return
}
// Set security groups for this tenant, overwriting any existing ones.
func (api *TenantsAPI) SetSecurityGroups(id string, securityGroups *SecurityGroupsSpec) (*Task, error) {
return setSecurityGroups(api.client, api.getEntityUrl(id), securityGroups)
}
func (api *TenantsAPI) getEntityUrl(id string) (url string) {
return api.client.Endpoint + tenantUrl + "/" + id
}

View File

@@ -1,110 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"reflect"
)
// Reads an error out of the HTTP response, or does nothing if
// no error occured.
func getError(res *http.Response) (*http.Response, error) {
// Do nothing if the response is a successful 2xx
if res.StatusCode/100 == 2 {
return res, nil
}
var apiError ApiError
// ReadAll is usually a bad practice, but here we need to read the response all
// at once because we may attempt to use the data twice. It's preferable to use
// methods that take io.Reader, e.g. json.NewDecoder
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(body, &apiError)
if err != nil {
// If deserializing into ApiError fails, return a generic HttpError instead
return nil, HttpError{res.StatusCode, string(body[:])}
}
apiError.HttpStatusCode = res.StatusCode
return nil, apiError
}
// Reads a task object out of the HTTP response. Takes an error argument
// so that GetTask can easily wrap GetError. This function will do nothing
// if e is not nil.
// e.g. res, err := getTask(getError(someApi.Get()))
func getTask(res *http.Response, e error) (*Task, error) {
if e != nil {
return nil, e
}
var task Task
err := json.NewDecoder(res.Body).Decode(&task)
if err != nil {
return nil, err
}
if task.State == "ERROR" {
// Critical: return task as well, so that it can be examined
// for error details.
return &task, TaskError{task.ID, getFailedStep(&task)}
}
return &task, nil
}
// Converts an options struct into a query string.
// E.g. type Foo struct {A int; B int} might return "?a=5&b=10".
// Will return an empty string if no options are set.
func getQueryString(options interface{}) string {
buffer := bytes.Buffer{}
buffer.WriteString("?")
strct := reflect.ValueOf(options).Elem()
typ := strct.Type()
for i := 0; i < strct.NumField(); i++ {
field := strct.Field(i)
value := fmt.Sprint(field.Interface())
if value != "" {
buffer.WriteString(typ.Field(i).Tag.Get("urlParam") + "=" + url.QueryEscape(value))
if i < strct.NumField()-1 {
buffer.WriteString("&")
}
}
}
uri := buffer.String()
if uri == "?" {
return ""
}
return uri
}
// Sets security groups for a given entity (deployment/tenant/project)
func setSecurityGroups(client *Client, entityUrl string, securityGroups *SecurityGroupsSpec) (task *Task, err error) {
body, err := json.Marshal(securityGroups)
if err != nil {
return
}
url := entityUrl + "/set_security_groups"
res, err := client.restClient.Post(
url,
"application/json",
bytes.NewReader(body),
client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,122 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
)
// Contains pointer to api client.
type VirtualSubnetsAPI struct {
client *Client
}
// Options used for GetAll API
type VirtualSubnetGetOptions struct {
Name string `urlParam:"name"`
}
var subnetsUrl = rootUrl + "/subnets"
var projectsUrl = rootUrl + "/projects"
// Create a virtual network
func (api *VirtualSubnetsAPI) Create(projectId string,
virtualNetworkSpec *VirtualSubnetCreateSpec) (task *Task, err error) {
body, err := json.Marshal(virtualNetworkSpec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+projectsUrl+"/"+projectId+"/subnets",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Delete a virtual network with the specified ID.
func (api *VirtualSubnetsAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+subnetsUrl+"/"+id,
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Get the virtual subnet with the specified id
func (api *VirtualSubnetsAPI) Get(id string) (subnet *VirtualSubnet, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+subnetsUrl+"/"+id,
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
subnet = new(VirtualSubnet)
err = json.NewDecoder(res.Body).Decode(subnet)
return
}
// Return all virtual networks
func (api *VirtualSubnetsAPI) GetAll(projectId string,
options *VirtualSubnetGetOptions) (subnets *VirtualSubnets, err error) {
uri := api.client.Endpoint + projectsUrl + "/" + projectId + "/subnets"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
subnets = &VirtualSubnets{}
err = json.Unmarshal(res, subnets)
return
}
func (api *VirtualSubnetsAPI) SetDefault(id string) (task *Task, err error) {
res, err := api.client.restClient.Post(
api.client.Endpoint+subnetsUrl+"/"+id+"/set_default",
"application/json",
bytes.NewReader([]byte("")),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,327 +0,0 @@
// Copyright (c) 2016 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.
package photon
import (
"bytes"
"encoding/json"
"io"
)
// Contains functionality for VMs API.
type VmAPI struct {
client *Client
}
var vmUrl string = rootUrl + "/vms/"
func (api *VmAPI) Get(id string) (vm *VM, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+vmUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
res, err = getError(res)
if err != nil {
return
}
vm = &VM{}
err = json.NewDecoder(res.Body).Decode(vm)
return
}
func (api *VmAPI) Delete(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(api.client.Endpoint+vmUrl+id, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) AttachDisk(id string, op *VmDiskOperation) (task *Task, err error) {
body, err := json.Marshal(op)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/attach_disk",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) DetachDisk(id string, op *VmDiskOperation) (task *Task, err error) {
body, err := json.Marshal(op)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/detach_disk",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) AttachISO(id string, reader io.ReadSeeker, name string) (task *Task, err error) {
res, err := api.client.restClient.MultipartUpload(
api.client.Endpoint+vmUrl+id+"/attach_iso", reader, name, nil, api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
result, err := getTask(getError(res))
return result, err
}
func (api *VmAPI) DetachISO(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/detach_iso",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) Start(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/start",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) Stop(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/stop",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) Restart(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/restart",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) Resume(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/resume",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) Suspend(id string) (task *Task, err error) {
body := []byte{}
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/suspend",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) SetMetadata(id string, metadata *VmMetadata) (task *Task, err error) {
body, err := json.Marshal(metadata)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/set_metadata",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
// Gets all tasks with the specified vm ID, using options to filter the results.
// If options is nil, no filtering will occur.
func (api *VmAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
uri := api.client.Endpoint + vmUrl + id + "/tasks"
if options != nil {
uri += getQueryString(options)
}
res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
if err != nil {
return
}
result = &TaskList{}
err = json.Unmarshal(res, result)
return
}
func (api *VmAPI) GetNetworks(id string) (task *Task, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+vmUrl+id+"/subnets", api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) AcquireFloatingIp(id string, spec *VmFloatingIpSpec) (task *Task, err error) {
body, err := json.Marshal(spec)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/acquire_floating_ip",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) ReleaseFloatingIp(id string) (task *Task, err error) {
res, err := api.client.restClient.Delete(
api.client.Endpoint+vmUrl+id+"/release_floating_ip",
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) GetMKSTicket(id string) (task *Task, err error) {
res, err := api.client.restClient.Get(api.client.Endpoint+vmUrl+id+"/mks_ticket", api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) SetTag(id string, tag *VmTag) (task *Task, err error) {
body, err := json.Marshal(tag)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/tags",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}
func (api *VmAPI) CreateImage(id string, options *ImageCreateSpec) (task *Task, err error) {
body, err := json.Marshal(options)
if err != nil {
return
}
res, err := api.client.restClient.Post(
api.client.Endpoint+vmUrl+id+"/create_image",
"application/json",
bytes.NewReader(body),
api.client.options.TokenOptions)
if err != nil {
return
}
defer res.Body.Close()
task, err = getTask(getError(res))
return
}

View File

@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,96 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
)
type ListApisParams struct {
p map[string]interface{}
}
func (p *ListApisParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
return u
}
func (p *ListApisParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
// You should always use this function to get a new ListApisParams instance,
// as then you are sure you have configured all required params
func (s *APIDiscoveryService) NewListApisParams() *ListApisParams {
p := &ListApisParams{}
p.p = make(map[string]interface{})
return p
}
// lists all available apis on the server, provided by the Api Discovery plugin
func (s *APIDiscoveryService) ListApis(p *ListApisParams) (*ListApisResponse, error) {
resp, err := s.cs.newRequest("listApis", p.toURLValues())
if err != nil {
return nil, err
}
var r ListApisResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListApisResponse struct {
Count int `json:"count"`
Apis []*Api `json:"api"`
}
type Api struct {
Description string `json:"description,omitempty"`
Isasync bool `json:"isasync,omitempty"`
Name string `json:"name,omitempty"`
Params []struct {
Description string `json:"description,omitempty"`
Length int `json:"length,omitempty"`
Name string `json:"name,omitempty"`
Related string `json:"related,omitempty"`
Required bool `json:"required,omitempty"`
Since string `json:"since,omitempty"`
Type string `json:"type,omitempty"`
} `json:"params,omitempty"`
Related string `json:"related,omitempty"`
Response []struct {
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Response []string `json:"response,omitempty"`
Type string `json:"type,omitempty"`
} `json:"response,omitempty"`
Since string `json:"since,omitempty"`
Type string `json:"type,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,811 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type AssociateIpAddressParams struct {
p map[string]interface{}
}
func (p *AssociateIpAddressParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["isportable"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isportable", vv)
}
if v, found := p.p["networkid"]; found {
u.Set("networkid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["regionid"]; found {
vv := strconv.Itoa(v.(int))
u.Set("regionid", vv)
}
if v, found := p.p["vpcid"]; found {
u.Set("vpcid", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *AssociateIpAddressParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *AssociateIpAddressParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *AssociateIpAddressParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *AssociateIpAddressParams) SetIsportable(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isportable"] = v
return
}
func (p *AssociateIpAddressParams) SetNetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkid"] = v
return
}
func (p *AssociateIpAddressParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *AssociateIpAddressParams) SetRegionid(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["regionid"] = v
return
}
func (p *AssociateIpAddressParams) SetVpcid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vpcid"] = v
return
}
func (p *AssociateIpAddressParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new AssociateIpAddressParams instance,
// as then you are sure you have configured all required params
func (s *AddressService) NewAssociateIpAddressParams() *AssociateIpAddressParams {
p := &AssociateIpAddressParams{}
p.p = make(map[string]interface{})
return p
}
// Acquires and associates a public IP to an account.
func (s *AddressService) AssociateIpAddress(p *AssociateIpAddressParams) (*AssociateIpAddressResponse, error) {
resp, err := s.cs.newRequest("associateIpAddress", p.toURLValues())
if err != nil {
return nil, err
}
var r AssociateIpAddressResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AssociateIpAddressResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Allocated string `json:"allocated,omitempty"`
Associatednetworkid string `json:"associatednetworkid,omitempty"`
Associatednetworkname string `json:"associatednetworkname,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Fordisplay bool `json:"fordisplay,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isportable bool `json:"isportable,omitempty"`
Issourcenat bool `json:"issourcenat,omitempty"`
Isstaticnat bool `json:"isstaticnat,omitempty"`
Issystem bool `json:"issystem,omitempty"`
Networkid string `json:"networkid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Purpose string `json:"purpose,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
Virtualmachinename string `json:"virtualmachinename,omitempty"`
Vlanid string `json:"vlanid,omitempty"`
Vlanname string `json:"vlanname,omitempty"`
Vmipaddress string `json:"vmipaddress,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type DisassociateIpAddressParams struct {
p map[string]interface{}
}
func (p *DisassociateIpAddressParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DisassociateIpAddressParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DisassociateIpAddressParams instance,
// as then you are sure you have configured all required params
func (s *AddressService) NewDisassociateIpAddressParams(id string) *DisassociateIpAddressParams {
p := &DisassociateIpAddressParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Disassociates an IP address from the account.
func (s *AddressService) DisassociateIpAddress(p *DisassociateIpAddressParams) (*DisassociateIpAddressResponse, error) {
resp, err := s.cs.newRequest("disassociateIpAddress", p.toURLValues())
if err != nil {
return nil, err
}
var r DisassociateIpAddressResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DisassociateIpAddressResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListPublicIpAddressesParams struct {
p map[string]interface{}
}
func (p *ListPublicIpAddressesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["allocatedonly"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("allocatedonly", vv)
}
if v, found := p.p["associatednetworkid"]; found {
u.Set("associatednetworkid", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["forloadbalancing"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forloadbalancing", vv)
}
if v, found := p.p["forvirtualnetwork"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forvirtualnetwork", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["ipaddress"]; found {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["issourcenat"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("issourcenat", vv)
}
if v, found := p.p["isstaticnat"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isstaticnat", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["state"]; found {
u.Set("state", v.(string))
}
if v, found := p.p["tags"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("tags[%d].key", i), k)
u.Set(fmt.Sprintf("tags[%d].value", i), vv)
i++
}
}
if v, found := p.p["vlanid"]; found {
u.Set("vlanid", v.(string))
}
if v, found := p.p["vpcid"]; found {
u.Set("vpcid", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListPublicIpAddressesParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListPublicIpAddressesParams) SetAllocatedonly(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["allocatedonly"] = v
return
}
func (p *ListPublicIpAddressesParams) SetAssociatednetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["associatednetworkid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *ListPublicIpAddressesParams) SetForloadbalancing(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forloadbalancing"] = v
return
}
func (p *ListPublicIpAddressesParams) SetForvirtualnetwork(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forvirtualnetwork"] = v
return
}
func (p *ListPublicIpAddressesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListPublicIpAddressesParams) SetIpaddress(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddress"] = v
return
}
func (p *ListPublicIpAddressesParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListPublicIpAddressesParams) SetIssourcenat(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["issourcenat"] = v
return
}
func (p *ListPublicIpAddressesParams) SetIsstaticnat(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isstaticnat"] = v
return
}
func (p *ListPublicIpAddressesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListPublicIpAddressesParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListPublicIpAddressesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListPublicIpAddressesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListPublicIpAddressesParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetState(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["state"] = v
return
}
func (p *ListPublicIpAddressesParams) SetTags(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
func (p *ListPublicIpAddressesParams) SetVlanid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vlanid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetVpcid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vpcid"] = v
return
}
func (p *ListPublicIpAddressesParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListPublicIpAddressesParams instance,
// as then you are sure you have configured all required params
func (s *AddressService) NewListPublicIpAddressesParams() *ListPublicIpAddressesParams {
p := &ListPublicIpAddressesParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AddressService) GetPublicIpAddressByID(id string, opts ...OptionFunc) (*PublicIpAddress, int, error) {
p := &ListPublicIpAddressesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListPublicIpAddresses(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.PublicIpAddresses[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for PublicIpAddress UUID: %s!", id)
}
// Lists all public ip addresses
func (s *AddressService) ListPublicIpAddresses(p *ListPublicIpAddressesParams) (*ListPublicIpAddressesResponse, error) {
resp, err := s.cs.newRequest("listPublicIpAddresses", p.toURLValues())
if err != nil {
return nil, err
}
var r ListPublicIpAddressesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListPublicIpAddressesResponse struct {
Count int `json:"count"`
PublicIpAddresses []*PublicIpAddress `json:"publicipaddress"`
}
type PublicIpAddress struct {
Account string `json:"account,omitempty"`
Allocated string `json:"allocated,omitempty"`
Associatednetworkid string `json:"associatednetworkid,omitempty"`
Associatednetworkname string `json:"associatednetworkname,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Fordisplay bool `json:"fordisplay,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isportable bool `json:"isportable,omitempty"`
Issourcenat bool `json:"issourcenat,omitempty"`
Isstaticnat bool `json:"isstaticnat,omitempty"`
Issystem bool `json:"issystem,omitempty"`
Networkid string `json:"networkid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Purpose string `json:"purpose,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
Virtualmachinename string `json:"virtualmachinename,omitempty"`
Vlanid string `json:"vlanid,omitempty"`
Vlanname string `json:"vlanname,omitempty"`
Vmipaddress string `json:"vmipaddress,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type UpdateIpAddressParams struct {
p map[string]interface{}
}
func (p *UpdateIpAddressParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["customid"]; found {
u.Set("customid", v.(string))
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *UpdateIpAddressParams) SetCustomid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["customid"] = v
return
}
func (p *UpdateIpAddressParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *UpdateIpAddressParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new UpdateIpAddressParams instance,
// as then you are sure you have configured all required params
func (s *AddressService) NewUpdateIpAddressParams(id string) *UpdateIpAddressParams {
p := &UpdateIpAddressParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates an IP address
func (s *AddressService) UpdateIpAddress(p *UpdateIpAddressParams) (*UpdateIpAddressResponse, error) {
resp, err := s.cs.newRequest("updateIpAddress", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateIpAddressResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type UpdateIpAddressResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Allocated string `json:"allocated,omitempty"`
Associatednetworkid string `json:"associatednetworkid,omitempty"`
Associatednetworkname string `json:"associatednetworkname,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Fordisplay bool `json:"fordisplay,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isportable bool `json:"isportable,omitempty"`
Issourcenat bool `json:"issourcenat,omitempty"`
Isstaticnat bool `json:"isstaticnat,omitempty"`
Issystem bool `json:"issystem,omitempty"`
Networkid string `json:"networkid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Purpose string `json:"purpose,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
Virtualmachinename string `json:"virtualmachinename,omitempty"`
Vlanid string `json:"vlanid,omitempty"`
Vlanname string `json:"vlanname,omitempty"`
Vmipaddress string `json:"vmipaddress,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}

View File

@@ -1,887 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreateAffinityGroupParams struct {
p map[string]interface{}
}
func (p *CreateAffinityGroupParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["description"]; found {
u.Set("description", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *CreateAffinityGroupParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *CreateAffinityGroupParams) SetDescription(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["description"] = v
return
}
func (p *CreateAffinityGroupParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *CreateAffinityGroupParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateAffinityGroupParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *CreateAffinityGroupParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["affinityGroupType"] = v
return
}
// You should always use this function to get a new CreateAffinityGroupParams instance,
// as then you are sure you have configured all required params
func (s *AffinityGroupService) NewCreateAffinityGroupParams(name string, affinityGroupType string) *CreateAffinityGroupParams {
p := &CreateAffinityGroupParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
p.p["affinityGroupType"] = affinityGroupType
return p
}
// Creates an affinity/anti-affinity group
func (s *AffinityGroupService) CreateAffinityGroup(p *CreateAffinityGroupParams) (*CreateAffinityGroupResponse, error) {
resp, err := s.cs.newRequest("createAffinityGroup", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateAffinityGroupResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type CreateAffinityGroupResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Type string `json:"type,omitempty"`
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
}
type DeleteAffinityGroupParams struct {
p map[string]interface{}
}
func (p *DeleteAffinityGroupParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
return u
}
func (p *DeleteAffinityGroupParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *DeleteAffinityGroupParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *DeleteAffinityGroupParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *DeleteAffinityGroupParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *DeleteAffinityGroupParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
// You should always use this function to get a new DeleteAffinityGroupParams instance,
// as then you are sure you have configured all required params
func (s *AffinityGroupService) NewDeleteAffinityGroupParams() *DeleteAffinityGroupParams {
p := &DeleteAffinityGroupParams{}
p.p = make(map[string]interface{})
return p
}
// Deletes affinity group
func (s *AffinityGroupService) DeleteAffinityGroup(p *DeleteAffinityGroupParams) (*DeleteAffinityGroupResponse, error) {
resp, err := s.cs.newRequest("deleteAffinityGroup", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteAffinityGroupResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteAffinityGroupResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListAffinityGroupsParams struct {
p map[string]interface{}
}
func (p *ListAffinityGroupsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
if v, found := p.p["virtualmachineid"]; found {
u.Set("virtualmachineid", v.(string))
}
return u
}
func (p *ListAffinityGroupsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListAffinityGroupsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListAffinityGroupsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListAffinityGroupsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListAffinityGroupsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListAffinityGroupsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListAffinityGroupsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListAffinityGroupsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListAffinityGroupsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListAffinityGroupsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListAffinityGroupsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["affinityGroupType"] = v
return
}
func (p *ListAffinityGroupsParams) SetVirtualmachineid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["virtualmachineid"] = v
return
}
// You should always use this function to get a new ListAffinityGroupsParams instance,
// as then you are sure you have configured all required params
func (s *AffinityGroupService) NewListAffinityGroupsParams() *ListAffinityGroupsParams {
p := &ListAffinityGroupsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AffinityGroupService) GetAffinityGroupID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListAffinityGroupsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListAffinityGroups(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.AffinityGroups[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.AffinityGroups {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AffinityGroupService) GetAffinityGroupByName(name string, opts ...OptionFunc) (*AffinityGroup, int, error) {
id, count, err := s.GetAffinityGroupID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetAffinityGroupByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AffinityGroupService) GetAffinityGroupByID(id string, opts ...OptionFunc) (*AffinityGroup, int, error) {
p := &ListAffinityGroupsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListAffinityGroups(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.AffinityGroups[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for AffinityGroup UUID: %s!", id)
}
// Lists affinity groups
func (s *AffinityGroupService) ListAffinityGroups(p *ListAffinityGroupsParams) (*ListAffinityGroupsResponse, error) {
resp, err := s.cs.newRequest("listAffinityGroups", p.toURLValues())
if err != nil {
return nil, err
}
var r ListAffinityGroupsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListAffinityGroupsResponse struct {
Count int `json:"count"`
AffinityGroups []*AffinityGroup `json:"affinitygroup"`
}
type AffinityGroup struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Type string `json:"type,omitempty"`
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
}
type UpdateVMAffinityGroupParams struct {
p map[string]interface{}
}
func (p *UpdateVMAffinityGroupParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["affinitygroupids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("affinitygroupids", vv)
}
if v, found := p.p["affinitygroupnames"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("affinitygroupnames", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *UpdateVMAffinityGroupParams) SetAffinitygroupids(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["affinitygroupids"] = v
return
}
func (p *UpdateVMAffinityGroupParams) SetAffinitygroupnames(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["affinitygroupnames"] = v
return
}
func (p *UpdateVMAffinityGroupParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new UpdateVMAffinityGroupParams instance,
// as then you are sure you have configured all required params
func (s *AffinityGroupService) NewUpdateVMAffinityGroupParams(id string) *UpdateVMAffinityGroupParams {
p := &UpdateVMAffinityGroupParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates the affinity/anti-affinity group associations of a virtual machine. The VM has to be stopped and restarted for the new properties to take effect.
func (s *AffinityGroupService) UpdateVMAffinityGroup(p *UpdateVMAffinityGroupParams) (*UpdateVMAffinityGroupResponse, error) {
resp, err := s.cs.newRequest("updateVMAffinityGroup", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateVMAffinityGroupResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type UpdateVMAffinityGroupResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Affinitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Type string `json:"type,omitempty"`
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
} `json:"affinitygroup,omitempty"`
Cpunumber int `json:"cpunumber,omitempty"`
Cpuspeed int `json:"cpuspeed,omitempty"`
Cpuused string `json:"cpuused,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Diskioread int64 `json:"diskioread,omitempty"`
Diskiowrite int64 `json:"diskiowrite,omitempty"`
Diskkbsread int64 `json:"diskkbsread,omitempty"`
Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
Diskofferingid string `json:"diskofferingid,omitempty"`
Diskofferingname string `json:"diskofferingname,omitempty"`
Displayname string `json:"displayname,omitempty"`
Displayvm bool `json:"displayvm,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Group string `json:"group,omitempty"`
Groupid string `json:"groupid,omitempty"`
Guestosid string `json:"guestosid,omitempty"`
Haenable bool `json:"haenable,omitempty"`
Hostid string `json:"hostid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Instancename string `json:"instancename,omitempty"`
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
Isodisplaytext string `json:"isodisplaytext,omitempty"`
Isoid string `json:"isoid,omitempty"`
Isoname string `json:"isoname,omitempty"`
Keypair string `json:"keypair,omitempty"`
Memory int `json:"memory,omitempty"`
Name string `json:"name,omitempty"`
Networkkbsread int64 `json:"networkkbsread,omitempty"`
Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
Nic []struct {
Broadcasturi string `json:"broadcasturi,omitempty"`
Deviceid string `json:"deviceid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Netmask string `json:"netmask,omitempty"`
Networkid string `json:"networkid,omitempty"`
Networkname string `json:"networkname,omitempty"`
Secondaryip []struct {
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
} `json:"secondaryip,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Type string `json:"type,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
} `json:"nic,omitempty"`
Ostypeid int64 `json:"ostypeid,omitempty"`
Password string `json:"password,omitempty"`
Passwordenabled bool `json:"passwordenabled,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Publicip string `json:"publicip,omitempty"`
Publicipid string `json:"publicipid,omitempty"`
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
Rootdevicetype string `json:"rootdevicetype,omitempty"`
Securitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Egressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"egressrule,omitempty"`
Id string `json:"id,omitempty"`
Ingressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"ingressrule,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinecount int `json:"virtualmachinecount,omitempty"`
Virtualmachineids []string `json:"virtualmachineids,omitempty"`
} `json:"securitygroup,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Servicestate string `json:"servicestate,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
Templateid string `json:"templateid,omitempty"`
Templatename string `json:"templatename,omitempty"`
Userid string `json:"userid,omitempty"`
Username string `json:"username,omitempty"`
Vgpu string `json:"vgpu,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type ListAffinityGroupTypesParams struct {
p map[string]interface{}
}
func (p *ListAffinityGroupTypesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListAffinityGroupTypesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListAffinityGroupTypesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListAffinityGroupTypesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListAffinityGroupTypesParams instance,
// as then you are sure you have configured all required params
func (s *AffinityGroupService) NewListAffinityGroupTypesParams() *ListAffinityGroupTypesParams {
p := &ListAffinityGroupTypesParams{}
p.p = make(map[string]interface{})
return p
}
// Lists affinity group types available
func (s *AffinityGroupService) ListAffinityGroupTypes(p *ListAffinityGroupTypesParams) (*ListAffinityGroupTypesResponse, error) {
resp, err := s.cs.newRequest("listAffinityGroupTypes", p.toURLValues())
if err != nil {
return nil, err
}
var r ListAffinityGroupTypesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListAffinityGroupTypesResponse struct {
Count int `json:"count"`
AffinityGroupTypes []*AffinityGroupType `json:"affinitygrouptype"`
}
type AffinityGroupType struct {
Type string `json:"type,omitempty"`
}

View File

@@ -1,505 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ListAlertsParams struct {
p map[string]interface{}
}
func (p *ListAlertsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *ListAlertsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListAlertsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListAlertsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListAlertsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListAlertsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListAlertsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["alertType"] = v
return
}
// You should always use this function to get a new ListAlertsParams instance,
// as then you are sure you have configured all required params
func (s *AlertService) NewListAlertsParams() *ListAlertsParams {
p := &ListAlertsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AlertService) GetAlertID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListAlertsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListAlerts(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.Alerts[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.Alerts {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AlertService) GetAlertByName(name string, opts ...OptionFunc) (*Alert, int, error) {
id, count, err := s.GetAlertID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetAlertByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *AlertService) GetAlertByID(id string, opts ...OptionFunc) (*Alert, int, error) {
p := &ListAlertsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListAlerts(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.Alerts[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for Alert UUID: %s!", id)
}
// Lists all alerts.
func (s *AlertService) ListAlerts(p *ListAlertsParams) (*ListAlertsResponse, error) {
resp, err := s.cs.newRequest("listAlerts", p.toURLValues())
if err != nil {
return nil, err
}
var r ListAlertsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListAlertsResponse struct {
Count int `json:"count"`
Alerts []*Alert `json:"alert"`
}
type Alert struct {
Description string `json:"description,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Sent string `json:"sent,omitempty"`
Type int `json:"type,omitempty"`
}
type ArchiveAlertsParams struct {
p map[string]interface{}
}
func (p *ArchiveAlertsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enddate"]; found {
u.Set("enddate", v.(string))
}
if v, found := p.p["ids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("ids", vv)
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *ArchiveAlertsParams) SetEnddate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enddate"] = v
return
}
func (p *ArchiveAlertsParams) SetIds(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ids"] = v
return
}
func (p *ArchiveAlertsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
func (p *ArchiveAlertsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["alertType"] = v
return
}
// You should always use this function to get a new ArchiveAlertsParams instance,
// as then you are sure you have configured all required params
func (s *AlertService) NewArchiveAlertsParams() *ArchiveAlertsParams {
p := &ArchiveAlertsParams{}
p.p = make(map[string]interface{})
return p
}
// Archive one or more alerts.
func (s *AlertService) ArchiveAlerts(p *ArchiveAlertsParams) (*ArchiveAlertsResponse, error) {
resp, err := s.cs.newRequest("archiveAlerts", p.toURLValues())
if err != nil {
return nil, err
}
var r ArchiveAlertsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ArchiveAlertsResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type DeleteAlertsParams struct {
p map[string]interface{}
}
func (p *DeleteAlertsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enddate"]; found {
u.Set("enddate", v.(string))
}
if v, found := p.p["ids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("ids", vv)
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *DeleteAlertsParams) SetEnddate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enddate"] = v
return
}
func (p *DeleteAlertsParams) SetIds(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ids"] = v
return
}
func (p *DeleteAlertsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
func (p *DeleteAlertsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["alertType"] = v
return
}
// You should always use this function to get a new DeleteAlertsParams instance,
// as then you are sure you have configured all required params
func (s *AlertService) NewDeleteAlertsParams() *DeleteAlertsParams {
p := &DeleteAlertsParams{}
p.p = make(map[string]interface{})
return p
}
// Delete one or more alerts.
func (s *AlertService) DeleteAlerts(p *DeleteAlertsParams) (*DeleteAlertsResponse, error) {
resp, err := s.cs.newRequest("deleteAlerts", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteAlertsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteAlertsResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type GenerateAlertParams struct {
p map[string]interface{}
}
func (p *GenerateAlertParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["description"]; found {
u.Set("description", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["type"]; found {
vv := strconv.Itoa(v.(int))
u.Set("type", vv)
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *GenerateAlertParams) SetDescription(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["description"] = v
return
}
func (p *GenerateAlertParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *GenerateAlertParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *GenerateAlertParams) SetType(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["alertType"] = v
return
}
func (p *GenerateAlertParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new GenerateAlertParams instance,
// as then you are sure you have configured all required params
func (s *AlertService) NewGenerateAlertParams(description string, name string, alertType int) *GenerateAlertParams {
p := &GenerateAlertParams{}
p.p = make(map[string]interface{})
p.p["description"] = description
p.p["name"] = name
p.p["alertType"] = alertType
return p
}
// Generates an alert
func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResponse, error) {
resp, err := s.cs.newRequest("generateAlert", p.toURLValues())
if err != nil {
return nil, err
}
var r GenerateAlertResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type GenerateAlertResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}

View File

@@ -1,239 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
"time"
)
type QueryAsyncJobResultParams struct {
p map[string]interface{}
}
func (p *QueryAsyncJobResultParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["jobid"]; found {
u.Set("jobid", v.(string))
}
return u
}
func (p *QueryAsyncJobResultParams) SetJobid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["jobid"] = v
return
}
// You should always use this function to get a new QueryAsyncJobResultParams instance,
// as then you are sure you have configured all required params
func (s *AsyncjobService) NewQueryAsyncJobResultParams(jobid string) *QueryAsyncJobResultParams {
p := &QueryAsyncJobResultParams{}
p.p = make(map[string]interface{})
p.p["jobid"] = jobid
return p
}
// Retrieves the current status of asynchronous job.
func (s *AsyncjobService) QueryAsyncJobResult(p *QueryAsyncJobResultParams) (*QueryAsyncJobResultResponse, error) {
var resp json.RawMessage
var err error
// We should be able to retry on failure as this call is idempotent
for i := 0; i < 3; i++ {
resp, err = s.cs.newRequest("queryAsyncJobResult", p.toURLValues())
if err == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
if err != nil {
return nil, err
}
var r QueryAsyncJobResultResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type QueryAsyncJobResultResponse struct {
Accountid string `json:"accountid,omitempty"`
Cmd string `json:"cmd,omitempty"`
Created string `json:"created,omitempty"`
Jobinstanceid string `json:"jobinstanceid,omitempty"`
Jobinstancetype string `json:"jobinstancetype,omitempty"`
Jobprocstatus int `json:"jobprocstatus,omitempty"`
Jobresult json.RawMessage `json:"jobresult,omitempty"`
Jobresultcode int `json:"jobresultcode,omitempty"`
Jobresulttype string `json:"jobresulttype,omitempty"`
Jobstatus int `json:"jobstatus,omitempty"`
Userid string `json:"userid,omitempty"`
}
type ListAsyncJobsParams struct {
p map[string]interface{}
}
func (p *ListAsyncJobsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
return u
}
func (p *ListAsyncJobsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListAsyncJobsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListAsyncJobsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListAsyncJobsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListAsyncJobsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListAsyncJobsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListAsyncJobsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListAsyncJobsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
// You should always use this function to get a new ListAsyncJobsParams instance,
// as then you are sure you have configured all required params
func (s *AsyncjobService) NewListAsyncJobsParams() *ListAsyncJobsParams {
p := &ListAsyncJobsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists all pending asynchronous jobs for the account.
func (s *AsyncjobService) ListAsyncJobs(p *ListAsyncJobsParams) (*ListAsyncJobsResponse, error) {
resp, err := s.cs.newRequest("listAsyncJobs", p.toURLValues())
if err != nil {
return nil, err
}
var r ListAsyncJobsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListAsyncJobsResponse struct {
Count int `json:"count"`
AsyncJobs []*AsyncJob `json:"asyncjobs"`
}
type AsyncJob struct {
Accountid string `json:"accountid,omitempty"`
Cmd string `json:"cmd,omitempty"`
Created string `json:"created,omitempty"`
Jobinstanceid string `json:"jobinstanceid,omitempty"`
Jobinstancetype string `json:"jobinstancetype,omitempty"`
Jobprocstatus int `json:"jobprocstatus,omitempty"`
Jobresult json.RawMessage `json:"jobresult,omitempty"`
Jobresultcode int `json:"jobresultcode,omitempty"`
Jobresulttype string `json:"jobresulttype,omitempty"`
Jobstatus int `json:"jobstatus,omitempty"`
Userid string `json:"userid,omitempty"`
}

View File

@@ -1,156 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type LoginParams struct {
p map[string]interface{}
}
func (p *LoginParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["domain"]; found {
u.Set("domain", v.(string))
}
if v, found := p.p["domainId"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("domainId", vv)
}
if v, found := p.p["password"]; found {
u.Set("password", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *LoginParams) SetDomain(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domain"] = v
return
}
func (p *LoginParams) SetDomainId(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainId"] = v
return
}
func (p *LoginParams) SetPassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["password"] = v
return
}
func (p *LoginParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new LoginParams instance,
// as then you are sure you have configured all required params
func (s *AuthenticationService) NewLoginParams(password string, username string) *LoginParams {
p := &LoginParams{}
p.p = make(map[string]interface{})
p.p["password"] = password
p.p["username"] = username
return p
}
// Logs a user into the CloudStack. A successful login attempt will generate a JSESSIONID cookie value that can be passed in subsequent Query command calls until the "logout" command has been issued or the session has expired.
func (s *AuthenticationService) Login(p *LoginParams) (*LoginResponse, error) {
resp, err := s.cs.newRequest("login", p.toURLValues())
if err != nil {
return nil, err
}
var r LoginResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type LoginResponse struct {
Account string `json:"account,omitempty"`
Domainid string `json:"domainid,omitempty"`
Firstname string `json:"firstname,omitempty"`
Lastname string `json:"lastname,omitempty"`
Registered string `json:"registered,omitempty"`
Sessionkey string `json:"sessionkey,omitempty"`
Timeout int `json:"timeout,omitempty"`
Timezone string `json:"timezone,omitempty"`
Type string `json:"type,omitempty"`
Userid string `json:"userid,omitempty"`
Username string `json:"username,omitempty"`
}
type LogoutParams struct {
p map[string]interface{}
}
func (p *LogoutParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
return u
}
// You should always use this function to get a new LogoutParams instance,
// as then you are sure you have configured all required params
func (s *AuthenticationService) NewLogoutParams() *LogoutParams {
p := &LogoutParams{}
p.p = make(map[string]interface{})
return p
}
// Logs out the user
func (s *AuthenticationService) Logout(p *LogoutParams) (*LogoutResponse, error) {
resp, err := s.cs.newRequest("logout", p.toURLValues())
if err != nil {
return nil, err
}
var r LogoutResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type LogoutResponse struct {
Description string `json:"description,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,88 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"APIDiscoveryService.go",
"AccountService.go",
"AddressService.go",
"AffinityGroupService.go",
"AlertService.go",
"AsyncjobService.go",
"AuthenticationService.go",
"AutoScaleService.go",
"BaremetalService.go",
"CertificateService.go",
"CloudIdentifierService.go",
"ClusterService.go",
"ConfigurationService.go",
"DiskOfferingService.go",
"DomainService.go",
"EventService.go",
"FirewallService.go",
"GuestOSService.go",
"HostService.go",
"HypervisorService.go",
"ISOService.go",
"ImageStoreService.go",
"InternalLBService.go",
"LDAPService.go",
"LimitService.go",
"LoadBalancerService.go",
"NATService.go",
"NetworkACLService.go",
"NetworkDeviceService.go",
"NetworkOfferingService.go",
"NetworkService.go",
"NicService.go",
"NiciraNVPService.go",
"OvsElementService.go",
"PodService.go",
"PoolService.go",
"PortableIPService.go",
"ProjectService.go",
"QuotaService.go",
"RegionService.go",
"ResourcemetadataService.go",
"ResourcetagsService.go",
"RouterService.go",
"SSHService.go",
"SecurityGroupService.go",
"ServiceOfferingService.go",
"SnapshotService.go",
"StoragePoolService.go",
"StratosphereSSPService.go",
"SwiftService.go",
"SystemCapacityService.go",
"SystemVMService.go",
"TemplateService.go",
"UCSService.go",
"UsageService.go",
"UserService.go",
"VLANService.go",
"VMGroupService.go",
"VPCService.go",
"VPNService.go",
"VirtualMachineService.go",
"VolumeService.go",
"ZoneService.go",
"cloudstack.go",
],
importmap = "k8s.io/kubernetes/vendor/github.com/xanzy/go-cloudstack/cloudstack",
importpath = "github.com/xanzy/go-cloudstack/cloudstack",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,918 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type AddBaremetalPxeKickStartServerParams struct {
p map[string]interface{}
}
func (p *AddBaremetalPxeKickStartServerParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["password"]; found {
u.Set("password", v.(string))
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["pxeservertype"]; found {
u.Set("pxeservertype", v.(string))
}
if v, found := p.p["tftpdir"]; found {
u.Set("tftpdir", v.(string))
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *AddBaremetalPxeKickStartServerParams) SetPassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["password"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetPxeservertype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pxeservertype"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetTftpdir(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tftpdir"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
return
}
func (p *AddBaremetalPxeKickStartServerParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new AddBaremetalPxeKickStartServerParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewAddBaremetalPxeKickStartServerParams(password string, physicalnetworkid string, pxeservertype string, tftpdir string, url string, username string) *AddBaremetalPxeKickStartServerParams {
p := &AddBaremetalPxeKickStartServerParams{}
p.p = make(map[string]interface{})
p.p["password"] = password
p.p["physicalnetworkid"] = physicalnetworkid
p.p["pxeservertype"] = pxeservertype
p.p["tftpdir"] = tftpdir
p.p["url"] = url
p.p["username"] = username
return p
}
// add a baremetal pxe server
func (s *BaremetalService) AddBaremetalPxeKickStartServer(p *AddBaremetalPxeKickStartServerParams) (*AddBaremetalPxeKickStartServerResponse, error) {
resp, err := s.cs.newRequest("addBaremetalPxeKickStartServer", p.toURLValues())
if err != nil {
return nil, err
}
var r AddBaremetalPxeKickStartServerResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddBaremetalPxeKickStartServerResponse struct {
JobID string `json:"jobid,omitempty"`
Tftpdir string `json:"tftpdir,omitempty"`
}
type AddBaremetalPxePingServerParams struct {
p map[string]interface{}
}
func (p *AddBaremetalPxePingServerParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["password"]; found {
u.Set("password", v.(string))
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
if v, found := p.p["pingcifspassword"]; found {
u.Set("pingcifspassword", v.(string))
}
if v, found := p.p["pingcifsusername"]; found {
u.Set("pingcifsusername", v.(string))
}
if v, found := p.p["pingdir"]; found {
u.Set("pingdir", v.(string))
}
if v, found := p.p["pingstorageserverip"]; found {
u.Set("pingstorageserverip", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["pxeservertype"]; found {
u.Set("pxeservertype", v.(string))
}
if v, found := p.p["tftpdir"]; found {
u.Set("tftpdir", v.(string))
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *AddBaremetalPxePingServerParams) SetPassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["password"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPingcifspassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pingcifspassword"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPingcifsusername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pingcifsusername"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPingdir(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pingdir"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPingstorageserverip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pingstorageserverip"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetPxeservertype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pxeservertype"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetTftpdir(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tftpdir"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
return
}
func (p *AddBaremetalPxePingServerParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new AddBaremetalPxePingServerParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewAddBaremetalPxePingServerParams(password string, physicalnetworkid string, pingdir string, pingstorageserverip string, pxeservertype string, tftpdir string, url string, username string) *AddBaremetalPxePingServerParams {
p := &AddBaremetalPxePingServerParams{}
p.p = make(map[string]interface{})
p.p["password"] = password
p.p["physicalnetworkid"] = physicalnetworkid
p.p["pingdir"] = pingdir
p.p["pingstorageserverip"] = pingstorageserverip
p.p["pxeservertype"] = pxeservertype
p.p["tftpdir"] = tftpdir
p.p["url"] = url
p.p["username"] = username
return p
}
// add a baremetal ping pxe server
func (s *BaremetalService) AddBaremetalPxePingServer(p *AddBaremetalPxePingServerParams) (*AddBaremetalPxePingServerResponse, error) {
resp, err := s.cs.newRequest("addBaremetalPxePingServer", p.toURLValues())
if err != nil {
return nil, err
}
var r AddBaremetalPxePingServerResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddBaremetalPxePingServerResponse struct {
JobID string `json:"jobid,omitempty"`
Pingdir string `json:"pingdir,omitempty"`
Pingstorageserverip string `json:"pingstorageserverip,omitempty"`
Tftpdir string `json:"tftpdir,omitempty"`
}
type AddBaremetalDhcpParams struct {
p map[string]interface{}
}
func (p *AddBaremetalDhcpParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["dhcpservertype"]; found {
u.Set("dhcpservertype", v.(string))
}
if v, found := p.p["password"]; found {
u.Set("password", v.(string))
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *AddBaremetalDhcpParams) SetDhcpservertype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["dhcpservertype"] = v
return
}
func (p *AddBaremetalDhcpParams) SetPassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["password"] = v
return
}
func (p *AddBaremetalDhcpParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
func (p *AddBaremetalDhcpParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
return
}
func (p *AddBaremetalDhcpParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new AddBaremetalDhcpParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewAddBaremetalDhcpParams(dhcpservertype string, password string, physicalnetworkid string, url string, username string) *AddBaremetalDhcpParams {
p := &AddBaremetalDhcpParams{}
p.p = make(map[string]interface{})
p.p["dhcpservertype"] = dhcpservertype
p.p["password"] = password
p.p["physicalnetworkid"] = physicalnetworkid
p.p["url"] = url
p.p["username"] = username
return p
}
// adds a baremetal dhcp server
func (s *BaremetalService) AddBaremetalDhcp(p *AddBaremetalDhcpParams) (*AddBaremetalDhcpResponse, error) {
resp, err := s.cs.newRequest("addBaremetalDhcp", p.toURLValues())
if err != nil {
return nil, err
}
var r AddBaremetalDhcpResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddBaremetalDhcpResponse struct {
JobID string `json:"jobid,omitempty"`
Dhcpservertype string `json:"dhcpservertype,omitempty"`
Id string `json:"id,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Provider string `json:"provider,omitempty"`
Url string `json:"url,omitempty"`
}
type ListBaremetalDhcpParams struct {
p map[string]interface{}
}
func (p *ListBaremetalDhcpParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["dhcpservertype"]; found {
u.Set("dhcpservertype", v.(string))
}
if v, found := p.p["id"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("id", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
return u
}
func (p *ListBaremetalDhcpParams) SetDhcpservertype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["dhcpservertype"] = v
return
}
func (p *ListBaremetalDhcpParams) SetId(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListBaremetalDhcpParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListBaremetalDhcpParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListBaremetalDhcpParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListBaremetalDhcpParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
// You should always use this function to get a new ListBaremetalDhcpParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewListBaremetalDhcpParams(physicalnetworkid string) *ListBaremetalDhcpParams {
p := &ListBaremetalDhcpParams{}
p.p = make(map[string]interface{})
p.p["physicalnetworkid"] = physicalnetworkid
return p
}
// list baremetal dhcp servers
func (s *BaremetalService) ListBaremetalDhcp(p *ListBaremetalDhcpParams) (*ListBaremetalDhcpResponse, error) {
resp, err := s.cs.newRequest("listBaremetalDhcp", p.toURLValues())
if err != nil {
return nil, err
}
var r ListBaremetalDhcpResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListBaremetalDhcpResponse struct {
Count int `json:"count"`
BaremetalDhcp []*BaremetalDhcp `json:"baremetaldhcp"`
}
type BaremetalDhcp struct {
Dhcpservertype string `json:"dhcpservertype,omitempty"`
Id string `json:"id,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Provider string `json:"provider,omitempty"`
Url string `json:"url,omitempty"`
}
type ListBaremetalPxeServersParams struct {
p map[string]interface{}
}
func (p *ListBaremetalPxeServersParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("id", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
return u
}
func (p *ListBaremetalPxeServersParams) SetId(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListBaremetalPxeServersParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListBaremetalPxeServersParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListBaremetalPxeServersParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListBaremetalPxeServersParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
// You should always use this function to get a new ListBaremetalPxeServersParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewListBaremetalPxeServersParams(physicalnetworkid string) *ListBaremetalPxeServersParams {
p := &ListBaremetalPxeServersParams{}
p.p = make(map[string]interface{})
p.p["physicalnetworkid"] = physicalnetworkid
return p
}
// list baremetal pxe server
func (s *BaremetalService) ListBaremetalPxeServers(p *ListBaremetalPxeServersParams) (*ListBaremetalPxeServersResponse, error) {
resp, err := s.cs.newRequest("listBaremetalPxeServers", p.toURLValues())
if err != nil {
return nil, err
}
var r ListBaremetalPxeServersResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListBaremetalPxeServersResponse struct {
Count int `json:"count"`
BaremetalPxeServers []*BaremetalPxeServer `json:"baremetalpxeserver"`
}
type BaremetalPxeServer struct {
Id string `json:"id,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Provider string `json:"provider,omitempty"`
Url string `json:"url,omitempty"`
}
type AddBaremetalRctParams struct {
p map[string]interface{}
}
func (p *AddBaremetalRctParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["baremetalrcturl"]; found {
u.Set("baremetalrcturl", v.(string))
}
return u
}
func (p *AddBaremetalRctParams) SetBaremetalrcturl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["baremetalrcturl"] = v
return
}
// You should always use this function to get a new AddBaremetalRctParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewAddBaremetalRctParams(baremetalrcturl string) *AddBaremetalRctParams {
p := &AddBaremetalRctParams{}
p.p = make(map[string]interface{})
p.p["baremetalrcturl"] = baremetalrcturl
return p
}
// adds baremetal rack configuration text
func (s *BaremetalService) AddBaremetalRct(p *AddBaremetalRctParams) (*AddBaremetalRctResponse, error) {
resp, err := s.cs.newRequest("addBaremetalRct", p.toURLValues())
if err != nil {
return nil, err
}
var r AddBaremetalRctResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddBaremetalRctResponse struct {
JobID string `json:"jobid,omitempty"`
Id string `json:"id,omitempty"`
Url string `json:"url,omitempty"`
}
type DeleteBaremetalRctParams struct {
p map[string]interface{}
}
func (p *DeleteBaremetalRctParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteBaremetalRctParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteBaremetalRctParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewDeleteBaremetalRctParams(id string) *DeleteBaremetalRctParams {
p := &DeleteBaremetalRctParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// deletes baremetal rack configuration text
func (s *BaremetalService) DeleteBaremetalRct(p *DeleteBaremetalRctParams) (*DeleteBaremetalRctResponse, error) {
resp, err := s.cs.newRequest("deleteBaremetalRct", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteBaremetalRctResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteBaremetalRctResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListBaremetalRctParams struct {
p map[string]interface{}
}
func (p *ListBaremetalRctParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListBaremetalRctParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListBaremetalRctParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListBaremetalRctParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListBaremetalRctParams instance,
// as then you are sure you have configured all required params
func (s *BaremetalService) NewListBaremetalRctParams() *ListBaremetalRctParams {
p := &ListBaremetalRctParams{}
p.p = make(map[string]interface{})
return p
}
// list baremetal rack configuration
func (s *BaremetalService) ListBaremetalRct(p *ListBaremetalRctParams) (*ListBaremetalRctResponse, error) {
resp, err := s.cs.newRequest("listBaremetalRct", p.toURLValues())
if err != nil {
return nil, err
}
var r ListBaremetalRctResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListBaremetalRctResponse struct {
Count int `json:"count"`
BaremetalRct []*BaremetalRct `json:"baremetalrct"`
}
type BaremetalRct struct {
Id string `json:"id,omitempty"`
Url string `json:"url,omitempty"`
}

View File

@@ -1,140 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type UploadCustomCertificateParams struct {
p map[string]interface{}
}
func (p *UploadCustomCertificateParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["certificate"]; found {
u.Set("certificate", v.(string))
}
if v, found := p.p["domainsuffix"]; found {
u.Set("domainsuffix", v.(string))
}
if v, found := p.p["id"]; found {
vv := strconv.Itoa(v.(int))
u.Set("id", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["privatekey"]; found {
u.Set("privatekey", v.(string))
}
return u
}
func (p *UploadCustomCertificateParams) SetCertificate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["certificate"] = v
return
}
func (p *UploadCustomCertificateParams) SetDomainsuffix(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainsuffix"] = v
return
}
func (p *UploadCustomCertificateParams) SetId(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UploadCustomCertificateParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UploadCustomCertificateParams) SetPrivatekey(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["privatekey"] = v
return
}
// You should always use this function to get a new UploadCustomCertificateParams instance,
// as then you are sure you have configured all required params
func (s *CertificateService) NewUploadCustomCertificateParams(certificate string, domainsuffix string) *UploadCustomCertificateParams {
p := &UploadCustomCertificateParams{}
p.p = make(map[string]interface{})
p.p["certificate"] = certificate
p.p["domainsuffix"] = domainsuffix
return p
}
// Uploads a custom certificate for the console proxy VMs to use for SSL. Can be used to upload a single certificate signed by a known CA. Can also be used, through multiple calls, to upload a chain of certificates from CA to the custom certificate itself.
func (s *CertificateService) UploadCustomCertificate(p *UploadCustomCertificateParams) (*UploadCustomCertificateResponse, error) {
resp, err := s.cs.newRequest("uploadCustomCertificate", p.toURLValues())
if err != nil {
return nil, err
}
var r UploadCustomCertificateResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type UploadCustomCertificateResponse struct {
JobID string `json:"jobid,omitempty"`
Message string `json:"message,omitempty"`
}

View File

@@ -1,74 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
)
type GetCloudIdentifierParams struct {
p map[string]interface{}
}
func (p *GetCloudIdentifierParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["userid"]; found {
u.Set("userid", v.(string))
}
return u
}
func (p *GetCloudIdentifierParams) SetUserid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["userid"] = v
return
}
// You should always use this function to get a new GetCloudIdentifierParams instance,
// as then you are sure you have configured all required params
func (s *CloudIdentifierService) NewGetCloudIdentifierParams(userid string) *GetCloudIdentifierParams {
p := &GetCloudIdentifierParams{}
p.p = make(map[string]interface{})
p.p["userid"] = userid
return p
}
// Retrieves a cloud identifier.
func (s *CloudIdentifierService) GetCloudIdentifier(p *GetCloudIdentifierParams) (*GetCloudIdentifierResponse, error) {
resp, err := s.cs.newRequest("getCloudIdentifier", p.toURLValues())
if err != nil {
return nil, err
}
var r GetCloudIdentifierResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type GetCloudIdentifierResponse struct {
Cloudidentifier string `json:"cloudidentifier,omitempty"`
Signature string `json:"signature,omitempty"`
Userid string `json:"userid,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,633 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type UpdateConfigurationParams struct {
p map[string]interface{}
}
func (p *UpdateConfigurationParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["accountid"]; found {
u.Set("accountid", v.(string))
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["value"]; found {
u.Set("value", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *UpdateConfigurationParams) SetAccountid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accountid"] = v
return
}
func (p *UpdateConfigurationParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
return
}
func (p *UpdateConfigurationParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UpdateConfigurationParams) SetStorageid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["storageid"] = v
return
}
func (p *UpdateConfigurationParams) SetValue(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["value"] = v
return
}
func (p *UpdateConfigurationParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new UpdateConfigurationParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams {
p := &UpdateConfigurationParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
return p
}
// Updates a configuration.
func (s *ConfigurationService) UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) {
resp, err := s.cs.newRequest("updateConfiguration", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateConfigurationResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateConfigurationResponse struct {
Category string `json:"category,omitempty"`
Description string `json:"description,omitempty"`
Id int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Scope string `json:"scope,omitempty"`
Value string `json:"value,omitempty"`
}
type ListConfigurationsParams struct {
p map[string]interface{}
}
func (p *ListConfigurationsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["accountid"]; found {
u.Set("accountid", v.(string))
}
if v, found := p.p["category"]; found {
u.Set("category", v.(string))
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListConfigurationsParams) SetAccountid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accountid"] = v
return
}
func (p *ListConfigurationsParams) SetCategory(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["category"] = v
return
}
func (p *ListConfigurationsParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
return
}
func (p *ListConfigurationsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListConfigurationsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListConfigurationsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListConfigurationsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListConfigurationsParams) SetStorageid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["storageid"] = v
return
}
func (p *ListConfigurationsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListConfigurationsParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewListConfigurationsParams() *ListConfigurationsParams {
p := &ListConfigurationsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists all configurations.
func (s *ConfigurationService) ListConfigurations(p *ListConfigurationsParams) (*ListConfigurationsResponse, error) {
resp, err := s.cs.newRequest("listConfigurations", p.toURLValues())
if err != nil {
return nil, err
}
var r ListConfigurationsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListConfigurationsResponse struct {
Count int `json:"count"`
Configurations []*Configuration `json:"configuration"`
}
type Configuration struct {
Category string `json:"category,omitempty"`
Description string `json:"description,omitempty"`
Id int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Scope string `json:"scope,omitempty"`
Value string `json:"value,omitempty"`
}
type ListCapabilitiesParams struct {
p map[string]interface{}
}
func (p *ListCapabilitiesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
return u
}
// You should always use this function to get a new ListCapabilitiesParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewListCapabilitiesParams() *ListCapabilitiesParams {
p := &ListCapabilitiesParams{}
p.p = make(map[string]interface{})
return p
}
// Lists capabilities
func (s *ConfigurationService) ListCapabilities(p *ListCapabilitiesParams) (*ListCapabilitiesResponse, error) {
resp, err := s.cs.newRequest("listCapabilities", p.toURLValues())
if err != nil {
return nil, err
}
var r ListCapabilitiesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListCapabilitiesResponse struct {
Count int `json:"count"`
Capabilities []*Capability `json:"capability"`
}
type Capability struct {
Allowusercreateprojects bool `json:"allowusercreateprojects,omitempty"`
Allowuserexpungerecovervm bool `json:"allowuserexpungerecovervm,omitempty"`
Allowuserviewdestroyedvm bool `json:"allowuserviewdestroyedvm,omitempty"`
Apilimitinterval int `json:"apilimitinterval,omitempty"`
Apilimitmax int `json:"apilimitmax,omitempty"`
Cloudstackversion string `json:"cloudstackversion,omitempty"`
Customdiskofferingmaxsize int64 `json:"customdiskofferingmaxsize,omitempty"`
Customdiskofferingminsize int64 `json:"customdiskofferingminsize,omitempty"`
Kvmsnapshotenabled bool `json:"kvmsnapshotenabled,omitempty"`
Projectinviterequired bool `json:"projectinviterequired,omitempty"`
Regionsecondaryenabled bool `json:"regionsecondaryenabled,omitempty"`
Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"`
SupportELB string `json:"supportELB,omitempty"`
Userpublictemplateenabled bool `json:"userpublictemplateenabled,omitempty"`
}
type ListDeploymentPlannersParams struct {
p map[string]interface{}
}
func (p *ListDeploymentPlannersParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListDeploymentPlannersParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListDeploymentPlannersParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListDeploymentPlannersParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListDeploymentPlannersParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewListDeploymentPlannersParams() *ListDeploymentPlannersParams {
p := &ListDeploymentPlannersParams{}
p.p = make(map[string]interface{})
return p
}
// Lists all DeploymentPlanners available.
func (s *ConfigurationService) ListDeploymentPlanners(p *ListDeploymentPlannersParams) (*ListDeploymentPlannersResponse, error) {
resp, err := s.cs.newRequest("listDeploymentPlanners", p.toURLValues())
if err != nil {
return nil, err
}
var r ListDeploymentPlannersResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListDeploymentPlannersResponse struct {
Count int `json:"count"`
DeploymentPlanners []*DeploymentPlanner `json:"deploymentplanner"`
}
type DeploymentPlanner struct {
Name string `json:"name,omitempty"`
}
type ListLdapConfigurationsParams struct {
p map[string]interface{}
}
func (p *ListLdapConfigurationsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hostname"]; found {
u.Set("hostname", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["port"]; found {
vv := strconv.Itoa(v.(int))
u.Set("port", vv)
}
return u
}
func (p *ListLdapConfigurationsParams) SetHostname(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostname"] = v
return
}
func (p *ListLdapConfigurationsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListLdapConfigurationsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListLdapConfigurationsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListLdapConfigurationsParams) SetPort(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["port"] = v
return
}
// You should always use this function to get a new ListLdapConfigurationsParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewListLdapConfigurationsParams() *ListLdapConfigurationsParams {
p := &ListLdapConfigurationsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists all LDAP configurations
func (s *ConfigurationService) ListLdapConfigurations(p *ListLdapConfigurationsParams) (*ListLdapConfigurationsResponse, error) {
resp, err := s.cs.newRequest("listLdapConfigurations", p.toURLValues())
if err != nil {
return nil, err
}
var r ListLdapConfigurationsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListLdapConfigurationsResponse struct {
Count int `json:"count"`
LdapConfigurations []*LdapConfiguration `json:"ldapconfiguration"`
}
type LdapConfiguration struct {
Hostname string `json:"hostname,omitempty"`
Port int `json:"port,omitempty"`
}
type AddLdapConfigurationParams struct {
p map[string]interface{}
}
func (p *AddLdapConfigurationParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hostname"]; found {
u.Set("hostname", v.(string))
}
if v, found := p.p["port"]; found {
vv := strconv.Itoa(v.(int))
u.Set("port", vv)
}
return u
}
func (p *AddLdapConfigurationParams) SetHostname(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostname"] = v
return
}
func (p *AddLdapConfigurationParams) SetPort(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["port"] = v
return
}
// You should always use this function to get a new AddLdapConfigurationParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewAddLdapConfigurationParams(hostname string, port int) *AddLdapConfigurationParams {
p := &AddLdapConfigurationParams{}
p.p = make(map[string]interface{})
p.p["hostname"] = hostname
p.p["port"] = port
return p
}
// Add a new Ldap Configuration
func (s *ConfigurationService) AddLdapConfiguration(p *AddLdapConfigurationParams) (*AddLdapConfigurationResponse, error) {
resp, err := s.cs.newRequest("addLdapConfiguration", p.toURLValues())
if err != nil {
return nil, err
}
var r AddLdapConfigurationResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type AddLdapConfigurationResponse struct {
Hostname string `json:"hostname,omitempty"`
Port int `json:"port,omitempty"`
}
type DeleteLdapConfigurationParams struct {
p map[string]interface{}
}
func (p *DeleteLdapConfigurationParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hostname"]; found {
u.Set("hostname", v.(string))
}
return u
}
func (p *DeleteLdapConfigurationParams) SetHostname(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostname"] = v
return
}
// You should always use this function to get a new DeleteLdapConfigurationParams instance,
// as then you are sure you have configured all required params
func (s *ConfigurationService) NewDeleteLdapConfigurationParams(hostname string) *DeleteLdapConfigurationParams {
p := &DeleteLdapConfigurationParams{}
p.p = make(map[string]interface{})
p.p["hostname"] = hostname
return p
}
// Remove an Ldap Configuration
func (s *ConfigurationService) DeleteLdapConfiguration(p *DeleteLdapConfigurationParams) (*DeleteLdapConfigurationResponse, error) {
resp, err := s.cs.newRequest("deleteLdapConfiguration", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteLdapConfigurationResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteLdapConfigurationResponse struct {
Hostname string `json:"hostname,omitempty"`
Port int `json:"port,omitempty"`
}

View File

@@ -1,688 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreateDiskOfferingParams struct {
p map[string]interface{}
}
func (p *CreateDiskOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["bytesreadrate"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("bytesreadrate", vv)
}
if v, found := p.p["byteswriterate"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("byteswriterate", vv)
}
if v, found := p.p["customized"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("customized", vv)
}
if v, found := p.p["customizediops"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("customizediops", vv)
}
if v, found := p.p["disksize"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("disksize", vv)
}
if v, found := p.p["displayoffering"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("displayoffering", vv)
}
if v, found := p.p["displaytext"]; found {
u.Set("displaytext", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["hypervisorsnapshotreserve"]; found {
vv := strconv.Itoa(v.(int))
u.Set("hypervisorsnapshotreserve", vv)
}
if v, found := p.p["iopsreadrate"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("iopsreadrate", vv)
}
if v, found := p.p["iopswriterate"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("iopswriterate", vv)
}
if v, found := p.p["maxiops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("maxiops", vv)
}
if v, found := p.p["miniops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("miniops", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["provisioningtype"]; found {
u.Set("provisioningtype", v.(string))
}
if v, found := p.p["storagetype"]; found {
u.Set("storagetype", v.(string))
}
if v, found := p.p["tags"]; found {
u.Set("tags", v.(string))
}
return u
}
func (p *CreateDiskOfferingParams) SetBytesreadrate(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["bytesreadrate"] = v
return
}
func (p *CreateDiskOfferingParams) SetByteswriterate(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["byteswriterate"] = v
return
}
func (p *CreateDiskOfferingParams) SetCustomized(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["customized"] = v
return
}
func (p *CreateDiskOfferingParams) SetCustomizediops(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["customizediops"] = v
return
}
func (p *CreateDiskOfferingParams) SetDisksize(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["disksize"] = v
return
}
func (p *CreateDiskOfferingParams) SetDisplayoffering(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displayoffering"] = v
return
}
func (p *CreateDiskOfferingParams) SetDisplaytext(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displaytext"] = v
return
}
func (p *CreateDiskOfferingParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *CreateDiskOfferingParams) SetHypervisorsnapshotreserve(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hypervisorsnapshotreserve"] = v
return
}
func (p *CreateDiskOfferingParams) SetIopsreadrate(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["iopsreadrate"] = v
return
}
func (p *CreateDiskOfferingParams) SetIopswriterate(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["iopswriterate"] = v
return
}
func (p *CreateDiskOfferingParams) SetMaxiops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["maxiops"] = v
return
}
func (p *CreateDiskOfferingParams) SetMiniops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["miniops"] = v
return
}
func (p *CreateDiskOfferingParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateDiskOfferingParams) SetProvisioningtype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["provisioningtype"] = v
return
}
func (p *CreateDiskOfferingParams) SetStoragetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["storagetype"] = v
return
}
func (p *CreateDiskOfferingParams) SetTags(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
// You should always use this function to get a new CreateDiskOfferingParams instance,
// as then you are sure you have configured all required params
func (s *DiskOfferingService) NewCreateDiskOfferingParams(displaytext string, name string) *CreateDiskOfferingParams {
p := &CreateDiskOfferingParams{}
p.p = make(map[string]interface{})
p.p["displaytext"] = displaytext
p.p["name"] = name
return p
}
// Creates a disk offering.
func (s *DiskOfferingService) CreateDiskOffering(p *CreateDiskOfferingParams) (*CreateDiskOfferingResponse, error) {
resp, err := s.cs.newRequest("createDiskOffering", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateDiskOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateDiskOfferingResponse struct {
CacheMode string `json:"cacheMode,omitempty"`
Created string `json:"created,omitempty"`
DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
Disksize int64 `json:"disksize,omitempty"`
Displayoffering bool `json:"displayoffering,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
Id string `json:"id,omitempty"`
Iscustomized bool `json:"iscustomized,omitempty"`
Iscustomizediops bool `json:"iscustomizediops,omitempty"`
Maxiops int64 `json:"maxiops,omitempty"`
Miniops int64 `json:"miniops,omitempty"`
Name string `json:"name,omitempty"`
Provisioningtype string `json:"provisioningtype,omitempty"`
Storagetype string `json:"storagetype,omitempty"`
Tags string `json:"tags,omitempty"`
}
type UpdateDiskOfferingParams struct {
p map[string]interface{}
}
func (p *UpdateDiskOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["displayoffering"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("displayoffering", vv)
}
if v, found := p.p["displaytext"]; found {
u.Set("displaytext", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["sortkey"]; found {
vv := strconv.Itoa(v.(int))
u.Set("sortkey", vv)
}
return u
}
func (p *UpdateDiskOfferingParams) SetDisplayoffering(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displayoffering"] = v
return
}
func (p *UpdateDiskOfferingParams) SetDisplaytext(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displaytext"] = v
return
}
func (p *UpdateDiskOfferingParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateDiskOfferingParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UpdateDiskOfferingParams) SetSortkey(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["sortkey"] = v
return
}
// You should always use this function to get a new UpdateDiskOfferingParams instance,
// as then you are sure you have configured all required params
func (s *DiskOfferingService) NewUpdateDiskOfferingParams(id string) *UpdateDiskOfferingParams {
p := &UpdateDiskOfferingParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a disk offering.
func (s *DiskOfferingService) UpdateDiskOffering(p *UpdateDiskOfferingParams) (*UpdateDiskOfferingResponse, error) {
resp, err := s.cs.newRequest("updateDiskOffering", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateDiskOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateDiskOfferingResponse struct {
CacheMode string `json:"cacheMode,omitempty"`
Created string `json:"created,omitempty"`
DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
Disksize int64 `json:"disksize,omitempty"`
Displayoffering bool `json:"displayoffering,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
Id string `json:"id,omitempty"`
Iscustomized bool `json:"iscustomized,omitempty"`
Iscustomizediops bool `json:"iscustomizediops,omitempty"`
Maxiops int64 `json:"maxiops,omitempty"`
Miniops int64 `json:"miniops,omitempty"`
Name string `json:"name,omitempty"`
Provisioningtype string `json:"provisioningtype,omitempty"`
Storagetype string `json:"storagetype,omitempty"`
Tags string `json:"tags,omitempty"`
}
type DeleteDiskOfferingParams struct {
p map[string]interface{}
}
func (p *DeleteDiskOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteDiskOfferingParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteDiskOfferingParams instance,
// as then you are sure you have configured all required params
func (s *DiskOfferingService) NewDeleteDiskOfferingParams(id string) *DeleteDiskOfferingParams {
p := &DeleteDiskOfferingParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a disk offering.
func (s *DiskOfferingService) DeleteDiskOffering(p *DeleteDiskOfferingParams) (*DeleteDiskOfferingResponse, error) {
resp, err := s.cs.newRequest("deleteDiskOffering", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteDiskOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteDiskOfferingResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type ListDiskOfferingsParams struct {
p map[string]interface{}
}
func (p *ListDiskOfferingsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListDiskOfferingsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListDiskOfferingsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListDiskOfferingsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListDiskOfferingsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListDiskOfferingsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListDiskOfferingsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListDiskOfferingsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListDiskOfferingsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListDiskOfferingsParams instance,
// as then you are sure you have configured all required params
func (s *DiskOfferingService) NewListDiskOfferingsParams() *ListDiskOfferingsParams {
p := &ListDiskOfferingsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DiskOfferingService) GetDiskOfferingID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListDiskOfferingsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListDiskOfferings(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.DiskOfferings[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.DiskOfferings {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DiskOfferingService) GetDiskOfferingByName(name string, opts ...OptionFunc) (*DiskOffering, int, error) {
id, count, err := s.GetDiskOfferingID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetDiskOfferingByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DiskOfferingService) GetDiskOfferingByID(id string, opts ...OptionFunc) (*DiskOffering, int, error) {
p := &ListDiskOfferingsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListDiskOfferings(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.DiskOfferings[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for DiskOffering UUID: %s!", id)
}
// Lists all available disk offerings.
func (s *DiskOfferingService) ListDiskOfferings(p *ListDiskOfferingsParams) (*ListDiskOfferingsResponse, error) {
resp, err := s.cs.newRequest("listDiskOfferings", p.toURLValues())
if err != nil {
return nil, err
}
var r ListDiskOfferingsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListDiskOfferingsResponse struct {
Count int `json:"count"`
DiskOfferings []*DiskOffering `json:"diskoffering"`
}
type DiskOffering struct {
CacheMode string `json:"cacheMode,omitempty"`
Created string `json:"created,omitempty"`
DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
Disksize int64 `json:"disksize,omitempty"`
Displayoffering bool `json:"displayoffering,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
Id string `json:"id,omitempty"`
Iscustomized bool `json:"iscustomized,omitempty"`
Iscustomizediops bool `json:"iscustomizediops,omitempty"`
Maxiops int64 `json:"maxiops,omitempty"`
Miniops int64 `json:"miniops,omitempty"`
Name string `json:"name,omitempty"`
Provisioningtype string `json:"provisioningtype,omitempty"`
Storagetype string `json:"storagetype,omitempty"`
Tags string `json:"tags,omitempty"`
}

View File

@@ -1,951 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreateDomainParams struct {
p map[string]interface{}
}
func (p *CreateDomainParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["networkdomain"]; found {
u.Set("networkdomain", v.(string))
}
if v, found := p.p["parentdomainid"]; found {
u.Set("parentdomainid", v.(string))
}
return u
}
func (p *CreateDomainParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *CreateDomainParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateDomainParams) SetNetworkdomain(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdomain"] = v
return
}
func (p *CreateDomainParams) SetParentdomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["parentdomainid"] = v
return
}
// You should always use this function to get a new CreateDomainParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewCreateDomainParams(name string) *CreateDomainParams {
p := &CreateDomainParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
return p
}
// Creates a domain
func (s *DomainService) CreateDomain(p *CreateDomainParams) (*CreateDomainResponse, error) {
resp, err := s.cs.newRequest("createDomain", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateDomainResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateDomainResponse struct {
Cpuavailable string `json:"cpuavailable,omitempty"`
Cpulimit string `json:"cpulimit,omitempty"`
Cputotal int64 `json:"cputotal,omitempty"`
Haschild bool `json:"haschild,omitempty"`
Id string `json:"id,omitempty"`
Ipavailable string `json:"ipavailable,omitempty"`
Iplimit string `json:"iplimit,omitempty"`
Iptotal int64 `json:"iptotal,omitempty"`
Level int `json:"level,omitempty"`
Memoryavailable string `json:"memoryavailable,omitempty"`
Memorylimit string `json:"memorylimit,omitempty"`
Memorytotal int64 `json:"memorytotal,omitempty"`
Name string `json:"name,omitempty"`
Networkavailable string `json:"networkavailable,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Networklimit string `json:"networklimit,omitempty"`
Networktotal int64 `json:"networktotal,omitempty"`
Parentdomainid string `json:"parentdomainid,omitempty"`
Parentdomainname string `json:"parentdomainname,omitempty"`
Path string `json:"path,omitempty"`
Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
Projectavailable string `json:"projectavailable,omitempty"`
Projectlimit string `json:"projectlimit,omitempty"`
Projecttotal int64 `json:"projecttotal,omitempty"`
Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
Snapshotavailable string `json:"snapshotavailable,omitempty"`
Snapshotlimit string `json:"snapshotlimit,omitempty"`
Snapshottotal int64 `json:"snapshottotal,omitempty"`
State string `json:"state,omitempty"`
Templateavailable string `json:"templateavailable,omitempty"`
Templatelimit string `json:"templatelimit,omitempty"`
Templatetotal int64 `json:"templatetotal,omitempty"`
Vmavailable string `json:"vmavailable,omitempty"`
Vmlimit string `json:"vmlimit,omitempty"`
Vmtotal int64 `json:"vmtotal,omitempty"`
Volumeavailable string `json:"volumeavailable,omitempty"`
Volumelimit string `json:"volumelimit,omitempty"`
Volumetotal int64 `json:"volumetotal,omitempty"`
Vpcavailable string `json:"vpcavailable,omitempty"`
Vpclimit string `json:"vpclimit,omitempty"`
Vpctotal int64 `json:"vpctotal,omitempty"`
}
type UpdateDomainParams struct {
p map[string]interface{}
}
func (p *UpdateDomainParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["networkdomain"]; found {
u.Set("networkdomain", v.(string))
}
return u
}
func (p *UpdateDomainParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateDomainParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UpdateDomainParams) SetNetworkdomain(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdomain"] = v
return
}
// You should always use this function to get a new UpdateDomainParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewUpdateDomainParams(id string) *UpdateDomainParams {
p := &UpdateDomainParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a domain with a new name
func (s *DomainService) UpdateDomain(p *UpdateDomainParams) (*UpdateDomainResponse, error) {
resp, err := s.cs.newRequest("updateDomain", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateDomainResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateDomainResponse struct {
Cpuavailable string `json:"cpuavailable,omitempty"`
Cpulimit string `json:"cpulimit,omitempty"`
Cputotal int64 `json:"cputotal,omitempty"`
Haschild bool `json:"haschild,omitempty"`
Id string `json:"id,omitempty"`
Ipavailable string `json:"ipavailable,omitempty"`
Iplimit string `json:"iplimit,omitempty"`
Iptotal int64 `json:"iptotal,omitempty"`
Level int `json:"level,omitempty"`
Memoryavailable string `json:"memoryavailable,omitempty"`
Memorylimit string `json:"memorylimit,omitempty"`
Memorytotal int64 `json:"memorytotal,omitempty"`
Name string `json:"name,omitempty"`
Networkavailable string `json:"networkavailable,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Networklimit string `json:"networklimit,omitempty"`
Networktotal int64 `json:"networktotal,omitempty"`
Parentdomainid string `json:"parentdomainid,omitempty"`
Parentdomainname string `json:"parentdomainname,omitempty"`
Path string `json:"path,omitempty"`
Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
Projectavailable string `json:"projectavailable,omitempty"`
Projectlimit string `json:"projectlimit,omitempty"`
Projecttotal int64 `json:"projecttotal,omitempty"`
Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
Snapshotavailable string `json:"snapshotavailable,omitempty"`
Snapshotlimit string `json:"snapshotlimit,omitempty"`
Snapshottotal int64 `json:"snapshottotal,omitempty"`
State string `json:"state,omitempty"`
Templateavailable string `json:"templateavailable,omitempty"`
Templatelimit string `json:"templatelimit,omitempty"`
Templatetotal int64 `json:"templatetotal,omitempty"`
Vmavailable string `json:"vmavailable,omitempty"`
Vmlimit string `json:"vmlimit,omitempty"`
Vmtotal int64 `json:"vmtotal,omitempty"`
Volumeavailable string `json:"volumeavailable,omitempty"`
Volumelimit string `json:"volumelimit,omitempty"`
Volumetotal int64 `json:"volumetotal,omitempty"`
Vpcavailable string `json:"vpcavailable,omitempty"`
Vpclimit string `json:"vpclimit,omitempty"`
Vpctotal int64 `json:"vpctotal,omitempty"`
}
type DeleteDomainParams struct {
p map[string]interface{}
}
func (p *DeleteDomainParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["cleanup"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("cleanup", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteDomainParams) SetCleanup(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["cleanup"] = v
return
}
func (p *DeleteDomainParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteDomainParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewDeleteDomainParams(id string) *DeleteDomainParams {
p := &DeleteDomainParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes a specified domain
func (s *DomainService) DeleteDomain(p *DeleteDomainParams) (*DeleteDomainResponse, error) {
resp, err := s.cs.newRequest("deleteDomain", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteDomainResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteDomainResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListDomainsParams struct {
p map[string]interface{}
}
func (p *ListDomainsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["level"]; found {
vv := strconv.Itoa(v.(int))
u.Set("level", vv)
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListDomainsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListDomainsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListDomainsParams) SetLevel(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["level"] = v
return
}
func (p *ListDomainsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListDomainsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListDomainsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListDomainsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListDomainsParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewListDomainsParams() *ListDomainsParams {
p := &ListDomainsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListDomainsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListDomains(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.Domains[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.Domains {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainByName(name string, opts ...OptionFunc) (*Domain, int, error) {
id, count, err := s.GetDomainID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetDomainByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainByID(id string, opts ...OptionFunc) (*Domain, int, error) {
p := &ListDomainsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListDomains(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.Domains[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for Domain UUID: %s!", id)
}
// Lists domains and provides detailed information for listed domains
func (s *DomainService) ListDomains(p *ListDomainsParams) (*ListDomainsResponse, error) {
resp, err := s.cs.newRequest("listDomains", p.toURLValues())
if err != nil {
return nil, err
}
var r ListDomainsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListDomainsResponse struct {
Count int `json:"count"`
Domains []*Domain `json:"domain"`
}
type Domain struct {
Cpuavailable string `json:"cpuavailable,omitempty"`
Cpulimit string `json:"cpulimit,omitempty"`
Cputotal int64 `json:"cputotal,omitempty"`
Haschild bool `json:"haschild,omitempty"`
Id string `json:"id,omitempty"`
Ipavailable string `json:"ipavailable,omitempty"`
Iplimit string `json:"iplimit,omitempty"`
Iptotal int64 `json:"iptotal,omitempty"`
Level int `json:"level,omitempty"`
Memoryavailable string `json:"memoryavailable,omitempty"`
Memorylimit string `json:"memorylimit,omitempty"`
Memorytotal int64 `json:"memorytotal,omitempty"`
Name string `json:"name,omitempty"`
Networkavailable string `json:"networkavailable,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Networklimit string `json:"networklimit,omitempty"`
Networktotal int64 `json:"networktotal,omitempty"`
Parentdomainid string `json:"parentdomainid,omitempty"`
Parentdomainname string `json:"parentdomainname,omitempty"`
Path string `json:"path,omitempty"`
Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
Projectavailable string `json:"projectavailable,omitempty"`
Projectlimit string `json:"projectlimit,omitempty"`
Projecttotal int64 `json:"projecttotal,omitempty"`
Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
Snapshotavailable string `json:"snapshotavailable,omitempty"`
Snapshotlimit string `json:"snapshotlimit,omitempty"`
Snapshottotal int64 `json:"snapshottotal,omitempty"`
State string `json:"state,omitempty"`
Templateavailable string `json:"templateavailable,omitempty"`
Templatelimit string `json:"templatelimit,omitempty"`
Templatetotal int64 `json:"templatetotal,omitempty"`
Vmavailable string `json:"vmavailable,omitempty"`
Vmlimit string `json:"vmlimit,omitempty"`
Vmtotal int64 `json:"vmtotal,omitempty"`
Volumeavailable string `json:"volumeavailable,omitempty"`
Volumelimit string `json:"volumelimit,omitempty"`
Volumetotal int64 `json:"volumetotal,omitempty"`
Vpcavailable string `json:"vpcavailable,omitempty"`
Vpclimit string `json:"vpclimit,omitempty"`
Vpctotal int64 `json:"vpctotal,omitempty"`
}
type ListDomainChildrenParams struct {
p map[string]interface{}
}
func (p *ListDomainChildrenParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListDomainChildrenParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListDomainChildrenParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListDomainChildrenParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListDomainChildrenParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListDomainChildrenParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListDomainChildrenParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListDomainChildrenParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListDomainChildrenParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewListDomainChildrenParams() *ListDomainChildrenParams {
p := &ListDomainChildrenParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainChildrenID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListDomainChildrenParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListDomainChildren(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.DomainChildren[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.DomainChildren {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainChildrenByName(name string, opts ...OptionFunc) (*DomainChildren, int, error) {
id, count, err := s.GetDomainChildrenID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetDomainChildrenByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *DomainService) GetDomainChildrenByID(id string, opts ...OptionFunc) (*DomainChildren, int, error) {
p := &ListDomainChildrenParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListDomainChildren(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.DomainChildren[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for DomainChildren UUID: %s!", id)
}
// Lists all children domains belonging to a specified domain
func (s *DomainService) ListDomainChildren(p *ListDomainChildrenParams) (*ListDomainChildrenResponse, error) {
resp, err := s.cs.newRequest("listDomainChildren", p.toURLValues())
if err != nil {
return nil, err
}
var r ListDomainChildrenResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListDomainChildrenResponse struct {
Count int `json:"count"`
DomainChildren []*DomainChildren `json:"domainchildren"`
}
type DomainChildren struct {
Cpuavailable string `json:"cpuavailable,omitempty"`
Cpulimit string `json:"cpulimit,omitempty"`
Cputotal int64 `json:"cputotal,omitempty"`
Haschild bool `json:"haschild,omitempty"`
Id string `json:"id,omitempty"`
Ipavailable string `json:"ipavailable,omitempty"`
Iplimit string `json:"iplimit,omitempty"`
Iptotal int64 `json:"iptotal,omitempty"`
Level int `json:"level,omitempty"`
Memoryavailable string `json:"memoryavailable,omitempty"`
Memorylimit string `json:"memorylimit,omitempty"`
Memorytotal int64 `json:"memorytotal,omitempty"`
Name string `json:"name,omitempty"`
Networkavailable string `json:"networkavailable,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Networklimit string `json:"networklimit,omitempty"`
Networktotal int64 `json:"networktotal,omitempty"`
Parentdomainid string `json:"parentdomainid,omitempty"`
Parentdomainname string `json:"parentdomainname,omitempty"`
Path string `json:"path,omitempty"`
Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
Projectavailable string `json:"projectavailable,omitempty"`
Projectlimit string `json:"projectlimit,omitempty"`
Projecttotal int64 `json:"projecttotal,omitempty"`
Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
Snapshotavailable string `json:"snapshotavailable,omitempty"`
Snapshotlimit string `json:"snapshotlimit,omitempty"`
Snapshottotal int64 `json:"snapshottotal,omitempty"`
State string `json:"state,omitempty"`
Templateavailable string `json:"templateavailable,omitempty"`
Templatelimit string `json:"templatelimit,omitempty"`
Templatetotal int64 `json:"templatetotal,omitempty"`
Vmavailable string `json:"vmavailable,omitempty"`
Vmlimit string `json:"vmlimit,omitempty"`
Vmtotal int64 `json:"vmtotal,omitempty"`
Volumeavailable string `json:"volumeavailable,omitempty"`
Volumelimit string `json:"volumelimit,omitempty"`
Volumetotal int64 `json:"volumetotal,omitempty"`
Vpcavailable string `json:"vpcavailable,omitempty"`
Vpclimit string `json:"vpclimit,omitempty"`
Vpctotal int64 `json:"vpctotal,omitempty"`
}
type LinkDomainToLdapParams struct {
p map[string]interface{}
}
func (p *LinkDomainToLdapParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["accounttype"]; found {
vv := strconv.Itoa(v.(int))
u.Set("accounttype", vv)
}
if v, found := p.p["admin"]; found {
u.Set("admin", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *LinkDomainToLdapParams) SetAccounttype(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accounttype"] = v
return
}
func (p *LinkDomainToLdapParams) SetAdmin(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["admin"] = v
return
}
func (p *LinkDomainToLdapParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *LinkDomainToLdapParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *LinkDomainToLdapParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainType"] = v
return
}
// You should always use this function to get a new LinkDomainToLdapParams instance,
// as then you are sure you have configured all required params
func (s *DomainService) NewLinkDomainToLdapParams(accounttype int, domainid string, name string, domainType string) *LinkDomainToLdapParams {
p := &LinkDomainToLdapParams{}
p.p = make(map[string]interface{})
p.p["accounttype"] = accounttype
p.p["domainid"] = domainid
p.p["name"] = name
p.p["domainType"] = domainType
return p
}
// link an existing cloudstack domain to group or OU in ldap
func (s *DomainService) LinkDomainToLdap(p *LinkDomainToLdapParams) (*LinkDomainToLdapResponse, error) {
resp, err := s.cs.newRequest("linkDomainToLdap", p.toURLValues())
if err != nil {
return nil, err
}
var r LinkDomainToLdapResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type LinkDomainToLdapResponse struct {
Accountid string `json:"accountid,omitempty"`
Accounttype int `json:"accounttype,omitempty"`
Domainid int64 `json:"domainid,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
}

View File

@@ -1,495 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ListEventsParams struct {
p map[string]interface{}
}
func (p *ListEventsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["duration"]; found {
vv := strconv.Itoa(v.(int))
u.Set("duration", vv)
}
if v, found := p.p["enddate"]; found {
u.Set("enddate", v.(string))
}
if v, found := p.p["entrytime"]; found {
vv := strconv.Itoa(v.(int))
u.Set("entrytime", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["level"]; found {
u.Set("level", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *ListEventsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListEventsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListEventsParams) SetDuration(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["duration"] = v
return
}
func (p *ListEventsParams) SetEnddate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enddate"] = v
return
}
func (p *ListEventsParams) SetEntrytime(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["entrytime"] = v
return
}
func (p *ListEventsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListEventsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListEventsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListEventsParams) SetLevel(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["level"] = v
return
}
func (p *ListEventsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListEventsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListEventsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListEventsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListEventsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
func (p *ListEventsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["eventType"] = v
return
}
// You should always use this function to get a new ListEventsParams instance,
// as then you are sure you have configured all required params
func (s *EventService) NewListEventsParams() *ListEventsParams {
p := &ListEventsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *EventService) GetEventByID(id string, opts ...OptionFunc) (*Event, int, error) {
p := &ListEventsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListEvents(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.Events[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for Event UUID: %s!", id)
}
// A command to list events.
func (s *EventService) ListEvents(p *ListEventsParams) (*ListEventsResponse, error) {
resp, err := s.cs.newRequest("listEvents", p.toURLValues())
if err != nil {
return nil, err
}
var r ListEventsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListEventsResponse struct {
Count int `json:"count"`
Events []*Event `json:"event"`
}
type Event struct {
Account string `json:"account,omitempty"`
Created string `json:"created,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Level string `json:"level,omitempty"`
Parentid string `json:"parentid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
State string `json:"state,omitempty"`
Type string `json:"type,omitempty"`
Username string `json:"username,omitempty"`
}
type ListEventTypesParams struct {
p map[string]interface{}
}
func (p *ListEventTypesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
return u
}
// You should always use this function to get a new ListEventTypesParams instance,
// as then you are sure you have configured all required params
func (s *EventService) NewListEventTypesParams() *ListEventTypesParams {
p := &ListEventTypesParams{}
p.p = make(map[string]interface{})
return p
}
// List Event Types
func (s *EventService) ListEventTypes(p *ListEventTypesParams) (*ListEventTypesResponse, error) {
resp, err := s.cs.newRequest("listEventTypes", p.toURLValues())
if err != nil {
return nil, err
}
var r ListEventTypesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListEventTypesResponse struct {
Count int `json:"count"`
EventTypes []*EventType `json:"eventtype"`
}
type EventType struct {
Name string `json:"name,omitempty"`
}
type ArchiveEventsParams struct {
p map[string]interface{}
}
func (p *ArchiveEventsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enddate"]; found {
u.Set("enddate", v.(string))
}
if v, found := p.p["ids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("ids", vv)
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *ArchiveEventsParams) SetEnddate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enddate"] = v
return
}
func (p *ArchiveEventsParams) SetIds(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ids"] = v
return
}
func (p *ArchiveEventsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
func (p *ArchiveEventsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["eventType"] = v
return
}
// You should always use this function to get a new ArchiveEventsParams instance,
// as then you are sure you have configured all required params
func (s *EventService) NewArchiveEventsParams() *ArchiveEventsParams {
p := &ArchiveEventsParams{}
p.p = make(map[string]interface{})
return p
}
// Archive one or more events.
func (s *EventService) ArchiveEvents(p *ArchiveEventsParams) (*ArchiveEventsResponse, error) {
resp, err := s.cs.newRequest("archiveEvents", p.toURLValues())
if err != nil {
return nil, err
}
var r ArchiveEventsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ArchiveEventsResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type DeleteEventsParams struct {
p map[string]interface{}
}
func (p *DeleteEventsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enddate"]; found {
u.Set("enddate", v.(string))
}
if v, found := p.p["ids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("ids", vv)
}
if v, found := p.p["startdate"]; found {
u.Set("startdate", v.(string))
}
if v, found := p.p["type"]; found {
u.Set("type", v.(string))
}
return u
}
func (p *DeleteEventsParams) SetEnddate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enddate"] = v
return
}
func (p *DeleteEventsParams) SetIds(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ids"] = v
return
}
func (p *DeleteEventsParams) SetStartdate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startdate"] = v
return
}
func (p *DeleteEventsParams) SetType(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["eventType"] = v
return
}
// You should always use this function to get a new DeleteEventsParams instance,
// as then you are sure you have configured all required params
func (s *EventService) NewDeleteEventsParams() *DeleteEventsParams {
p := &DeleteEventsParams{}
p.p = make(map[string]interface{})
return p
}
// Delete one or more events.
func (s *EventService) DeleteEvents(p *DeleteEventsParams) (*DeleteEventsResponse, error) {
resp, err := s.cs.newRequest("deleteEvents", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteEventsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteEventsResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,299 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ListHypervisorsParams struct {
p map[string]interface{}
}
func (p *ListHypervisorsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListHypervisorsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListHypervisorsParams instance,
// as then you are sure you have configured all required params
func (s *HypervisorService) NewListHypervisorsParams() *ListHypervisorsParams {
p := &ListHypervisorsParams{}
p.p = make(map[string]interface{})
return p
}
// List hypervisors
func (s *HypervisorService) ListHypervisors(p *ListHypervisorsParams) (*ListHypervisorsResponse, error) {
resp, err := s.cs.newRequest("listHypervisors", p.toURLValues())
if err != nil {
return nil, err
}
var r ListHypervisorsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListHypervisorsResponse struct {
Count int `json:"count"`
Hypervisors []*Hypervisor `json:"hypervisor"`
}
type Hypervisor struct {
Name string `json:"name,omitempty"`
}
type UpdateHypervisorCapabilitiesParams struct {
p map[string]interface{}
}
func (p *UpdateHypervisorCapabilitiesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["maxguestslimit"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("maxguestslimit", vv)
}
if v, found := p.p["securitygroupenabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("securitygroupenabled", vv)
}
return u
}
func (p *UpdateHypervisorCapabilitiesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateHypervisorCapabilitiesParams) SetMaxguestslimit(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["maxguestslimit"] = v
return
}
func (p *UpdateHypervisorCapabilitiesParams) SetSecuritygroupenabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["securitygroupenabled"] = v
return
}
// You should always use this function to get a new UpdateHypervisorCapabilitiesParams instance,
// as then you are sure you have configured all required params
func (s *HypervisorService) NewUpdateHypervisorCapabilitiesParams() *UpdateHypervisorCapabilitiesParams {
p := &UpdateHypervisorCapabilitiesParams{}
p.p = make(map[string]interface{})
return p
}
// Updates a hypervisor capabilities.
func (s *HypervisorService) UpdateHypervisorCapabilities(p *UpdateHypervisorCapabilitiesParams) (*UpdateHypervisorCapabilitiesResponse, error) {
resp, err := s.cs.newRequest("updateHypervisorCapabilities", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateHypervisorCapabilitiesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateHypervisorCapabilitiesResponse struct {
Hypervisor string `json:"hypervisor,omitempty"`
Hypervisorversion string `json:"hypervisorversion,omitempty"`
Id string `json:"id,omitempty"`
Maxdatavolumeslimit int `json:"maxdatavolumeslimit,omitempty"`
Maxguestslimit int64 `json:"maxguestslimit,omitempty"`
Maxhostspercluster int `json:"maxhostspercluster,omitempty"`
Securitygroupenabled bool `json:"securitygroupenabled,omitempty"`
Storagemotionenabled bool `json:"storagemotionenabled,omitempty"`
}
type ListHypervisorCapabilitiesParams struct {
p map[string]interface{}
}
func (p *ListHypervisorCapabilitiesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hypervisor"]; found {
u.Set("hypervisor", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListHypervisorCapabilitiesParams) SetHypervisor(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hypervisor"] = v
return
}
func (p *ListHypervisorCapabilitiesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListHypervisorCapabilitiesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListHypervisorCapabilitiesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListHypervisorCapabilitiesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListHypervisorCapabilitiesParams instance,
// as then you are sure you have configured all required params
func (s *HypervisorService) NewListHypervisorCapabilitiesParams() *ListHypervisorCapabilitiesParams {
p := &ListHypervisorCapabilitiesParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *HypervisorService) GetHypervisorCapabilityByID(id string, opts ...OptionFunc) (*HypervisorCapability, int, error) {
p := &ListHypervisorCapabilitiesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListHypervisorCapabilities(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.HypervisorCapabilities[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for HypervisorCapability UUID: %s!", id)
}
// Lists all hypervisor capabilities.
func (s *HypervisorService) ListHypervisorCapabilities(p *ListHypervisorCapabilitiesParams) (*ListHypervisorCapabilitiesResponse, error) {
resp, err := s.cs.newRequest("listHypervisorCapabilities", p.toURLValues())
if err != nil {
return nil, err
}
var r ListHypervisorCapabilitiesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListHypervisorCapabilitiesResponse struct {
Count int `json:"count"`
HypervisorCapabilities []*HypervisorCapability `json:"hypervisorcapability"`
}
type HypervisorCapability struct {
Hypervisor string `json:"hypervisor,omitempty"`
Hypervisorversion string `json:"hypervisorversion,omitempty"`
Id string `json:"id,omitempty"`
Maxdatavolumeslimit int `json:"maxdatavolumeslimit,omitempty"`
Maxguestslimit int64 `json:"maxguestslimit,omitempty"`
Maxhostspercluster int `json:"maxhostspercluster,omitempty"`
Securitygroupenabled bool `json:"securitygroupenabled,omitempty"`
Storagemotionenabled bool `json:"storagemotionenabled,omitempty"`
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,239 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
type LdapCreateAccountParams struct {
p map[string]interface{}
}
func (p *LdapCreateAccountParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["accountdetails"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("accountdetails[%d].key", i), k)
u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv)
i++
}
}
if v, found := p.p["accountid"]; found {
u.Set("accountid", v.(string))
}
if v, found := p.p["accounttype"]; found {
vv := strconv.Itoa(v.(int))
u.Set("accounttype", vv)
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["networkdomain"]; found {
u.Set("networkdomain", v.(string))
}
if v, found := p.p["timezone"]; found {
u.Set("timezone", v.(string))
}
if v, found := p.p["userid"]; found {
u.Set("userid", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *LdapCreateAccountParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *LdapCreateAccountParams) SetAccountdetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accountdetails"] = v
return
}
func (p *LdapCreateAccountParams) SetAccountid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accountid"] = v
return
}
func (p *LdapCreateAccountParams) SetAccounttype(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["accounttype"] = v
return
}
func (p *LdapCreateAccountParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *LdapCreateAccountParams) SetNetworkdomain(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdomain"] = v
return
}
func (p *LdapCreateAccountParams) SetTimezone(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["timezone"] = v
return
}
func (p *LdapCreateAccountParams) SetUserid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["userid"] = v
return
}
func (p *LdapCreateAccountParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new LdapCreateAccountParams instance,
// as then you are sure you have configured all required params
func (s *LDAPService) NewLdapCreateAccountParams(accounttype int, username string) *LdapCreateAccountParams {
p := &LdapCreateAccountParams{}
p.p = make(map[string]interface{})
p.p["accounttype"] = accounttype
p.p["username"] = username
return p
}
// Creates an account from an LDAP user
func (s *LDAPService) LdapCreateAccount(p *LdapCreateAccountParams) (*LdapCreateAccountResponse, error) {
resp, err := s.cs.newRequest("ldapCreateAccount", p.toURLValues())
if err != nil {
return nil, err
}
var r LdapCreateAccountResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type LdapCreateAccountResponse struct {
Accountdetails map[string]string `json:"accountdetails,omitempty"`
Accounttype int `json:"accounttype,omitempty"`
Cpuavailable string `json:"cpuavailable,omitempty"`
Cpulimit string `json:"cpulimit,omitempty"`
Cputotal int64 `json:"cputotal,omitempty"`
Defaultzoneid string `json:"defaultzoneid,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Groups []string `json:"groups,omitempty"`
Id string `json:"id,omitempty"`
Ipavailable string `json:"ipavailable,omitempty"`
Iplimit string `json:"iplimit,omitempty"`
Iptotal int64 `json:"iptotal,omitempty"`
Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Memoryavailable string `json:"memoryavailable,omitempty"`
Memorylimit string `json:"memorylimit,omitempty"`
Memorytotal int64 `json:"memorytotal,omitempty"`
Name string `json:"name,omitempty"`
Networkavailable string `json:"networkavailable,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Networklimit string `json:"networklimit,omitempty"`
Networktotal int64 `json:"networktotal,omitempty"`
Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
Projectavailable string `json:"projectavailable,omitempty"`
Projectlimit string `json:"projectlimit,omitempty"`
Projecttotal int64 `json:"projecttotal,omitempty"`
Receivedbytes int64 `json:"receivedbytes,omitempty"`
Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
Sentbytes int64 `json:"sentbytes,omitempty"`
Snapshotavailable string `json:"snapshotavailable,omitempty"`
Snapshotlimit string `json:"snapshotlimit,omitempty"`
Snapshottotal int64 `json:"snapshottotal,omitempty"`
State string `json:"state,omitempty"`
Templateavailable string `json:"templateavailable,omitempty"`
Templatelimit string `json:"templatelimit,omitempty"`
Templatetotal int64 `json:"templatetotal,omitempty"`
User []struct {
Account string `json:"account,omitempty"`
Accountid string `json:"accountid,omitempty"`
Accounttype int `json:"accounttype,omitempty"`
Apikey string `json:"apikey,omitempty"`
Created string `json:"created,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Email string `json:"email,omitempty"`
Firstname string `json:"firstname,omitempty"`
Id string `json:"id,omitempty"`
Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Lastname string `json:"lastname,omitempty"`
Secretkey string `json:"secretkey,omitempty"`
State string `json:"state,omitempty"`
Timezone string `json:"timezone,omitempty"`
Username string `json:"username,omitempty"`
} `json:"user,omitempty"`
Vmavailable string `json:"vmavailable,omitempty"`
Vmlimit string `json:"vmlimit,omitempty"`
Vmrunning int `json:"vmrunning,omitempty"`
Vmstopped int `json:"vmstopped,omitempty"`
Vmtotal int64 `json:"vmtotal,omitempty"`
Volumeavailable string `json:"volumeavailable,omitempty"`
Volumelimit string `json:"volumelimit,omitempty"`
Volumetotal int64 `json:"volumetotal,omitempty"`
Vpcavailable string `json:"vpcavailable,omitempty"`
Vpclimit string `json:"vpclimit,omitempty"`
Vpctotal int64 `json:"vpctotal,omitempty"`
}

View File

@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,475 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type UpdateResourceLimitParams struct {
p map[string]interface{}
}
func (p *UpdateResourceLimitParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["max"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("max", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
vv := strconv.Itoa(v.(int))
u.Set("resourcetype", vv)
}
return u
}
func (p *UpdateResourceLimitParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *UpdateResourceLimitParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *UpdateResourceLimitParams) SetMax(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["max"] = v
return
}
func (p *UpdateResourceLimitParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *UpdateResourceLimitParams) SetResourcetype(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
// You should always use this function to get a new UpdateResourceLimitParams instance,
// as then you are sure you have configured all required params
func (s *LimitService) NewUpdateResourceLimitParams(resourcetype int) *UpdateResourceLimitParams {
p := &UpdateResourceLimitParams{}
p.p = make(map[string]interface{})
p.p["resourcetype"] = resourcetype
return p
}
// Updates resource limits for an account or domain.
func (s *LimitService) UpdateResourceLimit(p *UpdateResourceLimitParams) (*UpdateResourceLimitResponse, error) {
resp, err := s.cs.newRequest("updateResourceLimit", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateResourceLimitResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateResourceLimitResponse struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Max int64 `json:"max,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
}
type UpdateResourceCountParams struct {
p map[string]interface{}
}
func (p *UpdateResourceCountParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
vv := strconv.Itoa(v.(int))
u.Set("resourcetype", vv)
}
return u
}
func (p *UpdateResourceCountParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *UpdateResourceCountParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *UpdateResourceCountParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *UpdateResourceCountParams) SetResourcetype(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
// You should always use this function to get a new UpdateResourceCountParams instance,
// as then you are sure you have configured all required params
func (s *LimitService) NewUpdateResourceCountParams(domainid string) *UpdateResourceCountParams {
p := &UpdateResourceCountParams{}
p.p = make(map[string]interface{})
p.p["domainid"] = domainid
return p
}
// Recalculate and update resource count for an account or domain.
func (s *LimitService) UpdateResourceCount(p *UpdateResourceCountParams) (*UpdateResourceCountResponse, error) {
resp, err := s.cs.newRequest("updateResourceCount", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateResourceCountResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateResourceCountResponse struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourcecount int64 `json:"resourcecount,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
}
type ListResourceLimitsParams struct {
p map[string]interface{}
}
func (p *ListResourceLimitsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("id", vv)
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
vv := strconv.Itoa(v.(int))
u.Set("resourcetype", vv)
}
return u
}
func (p *ListResourceLimitsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListResourceLimitsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListResourceLimitsParams) SetId(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListResourceLimitsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListResourceLimitsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListResourceLimitsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListResourceLimitsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListResourceLimitsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListResourceLimitsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListResourceLimitsParams) SetResourcetype(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
// You should always use this function to get a new ListResourceLimitsParams instance,
// as then you are sure you have configured all required params
func (s *LimitService) NewListResourceLimitsParams() *ListResourceLimitsParams {
p := &ListResourceLimitsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists resource limits.
func (s *LimitService) ListResourceLimits(p *ListResourceLimitsParams) (*ListResourceLimitsResponse, error) {
resp, err := s.cs.newRequest("listResourceLimits", p.toURLValues())
if err != nil {
return nil, err
}
var r ListResourceLimitsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListResourceLimitsResponse struct {
Count int `json:"count"`
ResourceLimits []*ResourceLimit `json:"resourcelimit"`
}
type ResourceLimit struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Max int64 `json:"max,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
}
type GetApiLimitParams struct {
p map[string]interface{}
}
func (p *GetApiLimitParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
return u
}
// You should always use this function to get a new GetApiLimitParams instance,
// as then you are sure you have configured all required params
func (s *LimitService) NewGetApiLimitParams() *GetApiLimitParams {
p := &GetApiLimitParams{}
p.p = make(map[string]interface{})
return p
}
// Get API limit count for the caller
func (s *LimitService) GetApiLimit(p *GetApiLimitParams) (*GetApiLimitResponse, error) {
resp, err := s.cs.newRequest("getApiLimit", p.toURLValues())
if err != nil {
return nil, err
}
var r GetApiLimitResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type GetApiLimitResponse struct {
Account string `json:"account,omitempty"`
Accountid string `json:"accountid,omitempty"`
ApiAllowed int `json:"apiAllowed,omitempty"`
ApiIssued int `json:"apiIssued,omitempty"`
ExpireAfter int64 `json:"expireAfter,omitempty"`
}
type ResetApiLimitParams struct {
p map[string]interface{}
}
func (p *ResetApiLimitParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
return u
}
func (p *ResetApiLimitParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
// You should always use this function to get a new ResetApiLimitParams instance,
// as then you are sure you have configured all required params
func (s *LimitService) NewResetApiLimitParams() *ResetApiLimitParams {
p := &ResetApiLimitParams{}
p.p = make(map[string]interface{})
return p
}
// Reset api count
func (s *LimitService) ResetApiLimit(p *ResetApiLimitParams) (*ResetApiLimitResponse, error) {
resp, err := s.cs.newRequest("resetApiLimit", p.toURLValues())
if err != nil {
return nil, err
}
var r ResetApiLimitResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ResetApiLimitResponse struct {
Account string `json:"account,omitempty"`
Accountid string `json:"accountid,omitempty"`
ApiAllowed int `json:"apiAllowed,omitempty"`
ApiIssued int `json:"apiIssued,omitempty"`
ExpireAfter int64 `json:"expireAfter,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,631 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type EnableStaticNatParams struct {
p map[string]interface{}
}
func (p *EnableStaticNatParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["ipaddressid"]; found {
u.Set("ipaddressid", v.(string))
}
if v, found := p.p["networkid"]; found {
u.Set("networkid", v.(string))
}
if v, found := p.p["virtualmachineid"]; found {
u.Set("virtualmachineid", v.(string))
}
if v, found := p.p["vmguestip"]; found {
u.Set("vmguestip", v.(string))
}
return u
}
func (p *EnableStaticNatParams) SetIpaddressid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddressid"] = v
return
}
func (p *EnableStaticNatParams) SetNetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkid"] = v
return
}
func (p *EnableStaticNatParams) SetVirtualmachineid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["virtualmachineid"] = v
return
}
func (p *EnableStaticNatParams) SetVmguestip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vmguestip"] = v
return
}
// You should always use this function to get a new EnableStaticNatParams instance,
// as then you are sure you have configured all required params
func (s *NATService) NewEnableStaticNatParams(ipaddressid string, virtualmachineid string) *EnableStaticNatParams {
p := &EnableStaticNatParams{}
p.p = make(map[string]interface{})
p.p["ipaddressid"] = ipaddressid
p.p["virtualmachineid"] = virtualmachineid
return p
}
// Enables static NAT for given IP address
func (s *NATService) EnableStaticNat(p *EnableStaticNatParams) (*EnableStaticNatResponse, error) {
resp, err := s.cs.newRequest("enableStaticNat", p.toURLValues())
if err != nil {
return nil, err
}
var r EnableStaticNatResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type EnableStaticNatResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type CreateIpForwardingRuleParams struct {
p map[string]interface{}
}
func (p *CreateIpForwardingRuleParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["cidrlist"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("cidrlist", vv)
}
if v, found := p.p["endport"]; found {
vv := strconv.Itoa(v.(int))
u.Set("endport", vv)
}
if v, found := p.p["ipaddressid"]; found {
u.Set("ipaddressid", v.(string))
}
if v, found := p.p["openfirewall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("openfirewall", vv)
}
if v, found := p.p["protocol"]; found {
u.Set("protocol", v.(string))
}
if v, found := p.p["startport"]; found {
vv := strconv.Itoa(v.(int))
u.Set("startport", vv)
}
return u
}
func (p *CreateIpForwardingRuleParams) SetCidrlist(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["cidrlist"] = v
return
}
func (p *CreateIpForwardingRuleParams) SetEndport(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endport"] = v
return
}
func (p *CreateIpForwardingRuleParams) SetIpaddressid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddressid"] = v
return
}
func (p *CreateIpForwardingRuleParams) SetOpenfirewall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["openfirewall"] = v
return
}
func (p *CreateIpForwardingRuleParams) SetProtocol(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["protocol"] = v
return
}
func (p *CreateIpForwardingRuleParams) SetStartport(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startport"] = v
return
}
// You should always use this function to get a new CreateIpForwardingRuleParams instance,
// as then you are sure you have configured all required params
func (s *NATService) NewCreateIpForwardingRuleParams(ipaddressid string, protocol string, startport int) *CreateIpForwardingRuleParams {
p := &CreateIpForwardingRuleParams{}
p.p = make(map[string]interface{})
p.p["ipaddressid"] = ipaddressid
p.p["protocol"] = protocol
p.p["startport"] = startport
return p
}
// Creates an IP forwarding rule
func (s *NATService) CreateIpForwardingRule(p *CreateIpForwardingRuleParams) (*CreateIpForwardingRuleResponse, error) {
resp, err := s.cs.newRequest("createIpForwardingRule", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateIpForwardingRuleResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type CreateIpForwardingRuleResponse struct {
JobID string `json:"jobid,omitempty"`
Cidrlist string `json:"cidrlist,omitempty"`
Fordisplay bool `json:"fordisplay,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ipaddressid string `json:"ipaddressid,omitempty"`
Networkid string `json:"networkid,omitempty"`
Privateendport string `json:"privateendport,omitempty"`
Privateport string `json:"privateport,omitempty"`
Protocol string `json:"protocol,omitempty"`
Publicendport string `json:"publicendport,omitempty"`
Publicport string `json:"publicport,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
Virtualmachinename string `json:"virtualmachinename,omitempty"`
Vmguestip string `json:"vmguestip,omitempty"`
}
type DeleteIpForwardingRuleParams struct {
p map[string]interface{}
}
func (p *DeleteIpForwardingRuleParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteIpForwardingRuleParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteIpForwardingRuleParams instance,
// as then you are sure you have configured all required params
func (s *NATService) NewDeleteIpForwardingRuleParams(id string) *DeleteIpForwardingRuleParams {
p := &DeleteIpForwardingRuleParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes an IP forwarding rule
func (s *NATService) DeleteIpForwardingRule(p *DeleteIpForwardingRuleParams) (*DeleteIpForwardingRuleResponse, error) {
resp, err := s.cs.newRequest("deleteIpForwardingRule", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteIpForwardingRuleResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteIpForwardingRuleResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListIpForwardingRulesParams struct {
p map[string]interface{}
}
func (p *ListIpForwardingRulesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["ipaddressid"]; found {
u.Set("ipaddressid", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["virtualmachineid"]; found {
u.Set("virtualmachineid", v.(string))
}
return u
}
func (p *ListIpForwardingRulesParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListIpForwardingRulesParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListIpForwardingRulesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListIpForwardingRulesParams) SetIpaddressid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddressid"] = v
return
}
func (p *ListIpForwardingRulesParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListIpForwardingRulesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListIpForwardingRulesParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListIpForwardingRulesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListIpForwardingRulesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListIpForwardingRulesParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListIpForwardingRulesParams) SetVirtualmachineid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["virtualmachineid"] = v
return
}
// You should always use this function to get a new ListIpForwardingRulesParams instance,
// as then you are sure you have configured all required params
func (s *NATService) NewListIpForwardingRulesParams() *ListIpForwardingRulesParams {
p := &ListIpForwardingRulesParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *NATService) GetIpForwardingRuleByID(id string, opts ...OptionFunc) (*IpForwardingRule, int, error) {
p := &ListIpForwardingRulesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListIpForwardingRules(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.IpForwardingRules[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for IpForwardingRule UUID: %s!", id)
}
// List the IP forwarding rules
func (s *NATService) ListIpForwardingRules(p *ListIpForwardingRulesParams) (*ListIpForwardingRulesResponse, error) {
resp, err := s.cs.newRequest("listIpForwardingRules", p.toURLValues())
if err != nil {
return nil, err
}
var r ListIpForwardingRulesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListIpForwardingRulesResponse struct {
Count int `json:"count"`
IpForwardingRules []*IpForwardingRule `json:"ipforwardingrule"`
}
type IpForwardingRule struct {
Cidrlist string `json:"cidrlist,omitempty"`
Fordisplay bool `json:"fordisplay,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ipaddressid string `json:"ipaddressid,omitempty"`
Networkid string `json:"networkid,omitempty"`
Privateendport string `json:"privateendport,omitempty"`
Privateport string `json:"privateport,omitempty"`
Protocol string `json:"protocol,omitempty"`
Publicendport string `json:"publicendport,omitempty"`
Publicport string `json:"publicport,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
Virtualmachinename string `json:"virtualmachinename,omitempty"`
Vmguestip string `json:"vmguestip,omitempty"`
}
type DisableStaticNatParams struct {
p map[string]interface{}
}
func (p *DisableStaticNatParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["ipaddressid"]; found {
u.Set("ipaddressid", v.(string))
}
return u
}
func (p *DisableStaticNatParams) SetIpaddressid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddressid"] = v
return
}
// You should always use this function to get a new DisableStaticNatParams instance,
// as then you are sure you have configured all required params
func (s *NATService) NewDisableStaticNatParams(ipaddressid string) *DisableStaticNatParams {
p := &DisableStaticNatParams{}
p.p = make(map[string]interface{})
p.p["ipaddressid"] = ipaddressid
return p
}
// Disables static rule for given IP address
func (s *NATService) DisableStaticNat(p *DisableStaticNatParams) (*DisableStaticNatResponse, error) {
resp, err := s.cs.newRequest("disableStaticNat", p.toURLValues())
if err != nil {
return nil, err
}
var r DisableStaticNatResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DisableStaticNatResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,245 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
type AddNetworkDeviceParams struct {
p map[string]interface{}
}
func (p *AddNetworkDeviceParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["networkdeviceparameterlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].key", i), k)
u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].value", i), vv)
i++
}
}
if v, found := p.p["networkdevicetype"]; found {
u.Set("networkdevicetype", v.(string))
}
return u
}
func (p *AddNetworkDeviceParams) SetNetworkdeviceparameterlist(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdeviceparameterlist"] = v
return
}
func (p *AddNetworkDeviceParams) SetNetworkdevicetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdevicetype"] = v
return
}
// You should always use this function to get a new AddNetworkDeviceParams instance,
// as then you are sure you have configured all required params
func (s *NetworkDeviceService) NewAddNetworkDeviceParams() *AddNetworkDeviceParams {
p := &AddNetworkDeviceParams{}
p.p = make(map[string]interface{})
return p
}
// Adds a network device of one of the following types: ExternalDhcp, ExternalFirewall, ExternalLoadBalancer, PxeServer
func (s *NetworkDeviceService) AddNetworkDevice(p *AddNetworkDeviceParams) (*AddNetworkDeviceResponse, error) {
resp, err := s.cs.newRequest("addNetworkDevice", p.toURLValues())
if err != nil {
return nil, err
}
var r AddNetworkDeviceResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type AddNetworkDeviceResponse struct {
Id string `json:"id,omitempty"`
}
type ListNetworkDeviceParams struct {
p map[string]interface{}
}
func (p *ListNetworkDeviceParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["networkdeviceparameterlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].key", i), k)
u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].value", i), vv)
i++
}
}
if v, found := p.p["networkdevicetype"]; found {
u.Set("networkdevicetype", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListNetworkDeviceParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListNetworkDeviceParams) SetNetworkdeviceparameterlist(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdeviceparameterlist"] = v
return
}
func (p *ListNetworkDeviceParams) SetNetworkdevicetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkdevicetype"] = v
return
}
func (p *ListNetworkDeviceParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListNetworkDeviceParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListNetworkDeviceParams instance,
// as then you are sure you have configured all required params
func (s *NetworkDeviceService) NewListNetworkDeviceParams() *ListNetworkDeviceParams {
p := &ListNetworkDeviceParams{}
p.p = make(map[string]interface{})
return p
}
// List network devices
func (s *NetworkDeviceService) ListNetworkDevice(p *ListNetworkDeviceParams) (*ListNetworkDeviceResponse, error) {
resp, err := s.cs.newRequest("listNetworkDevice", p.toURLValues())
if err != nil {
return nil, err
}
var r ListNetworkDeviceResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListNetworkDeviceResponse struct {
Count int `json:"count"`
NetworkDevice []*NetworkDevice `json:"networkdevice"`
}
type NetworkDevice struct {
Id string `json:"id,omitempty"`
}
type DeleteNetworkDeviceParams struct {
p map[string]interface{}
}
func (p *DeleteNetworkDeviceParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteNetworkDeviceParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteNetworkDeviceParams instance,
// as then you are sure you have configured all required params
func (s *NetworkDeviceService) NewDeleteNetworkDeviceParams(id string) *DeleteNetworkDeviceParams {
p := &DeleteNetworkDeviceParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes network device.
func (s *NetworkDeviceService) DeleteNetworkDevice(p *DeleteNetworkDeviceParams) (*DeleteNetworkDeviceResponse, error) {
resp, err := s.cs.newRequest("deleteNetworkDevice", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteNetworkDeviceResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteNetworkDeviceResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}

View File

@@ -1,951 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreateNetworkOfferingParams struct {
p map[string]interface{}
}
func (p *CreateNetworkOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["availability"]; found {
u.Set("availability", v.(string))
}
if v, found := p.p["conservemode"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("conservemode", vv)
}
if v, found := p.p["details"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("details[%d].key", i), k)
u.Set(fmt.Sprintf("details[%d].value", i), vv)
i++
}
}
if v, found := p.p["displaytext"]; found {
u.Set("displaytext", v.(string))
}
if v, found := p.p["egressdefaultpolicy"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("egressdefaultpolicy", vv)
}
if v, found := p.p["guestiptype"]; found {
u.Set("guestiptype", v.(string))
}
if v, found := p.p["ispersistent"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("ispersistent", vv)
}
if v, found := p.p["keepaliveenabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("keepaliveenabled", vv)
}
if v, found := p.p["maxconnections"]; found {
vv := strconv.Itoa(v.(int))
u.Set("maxconnections", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["networkrate"]; found {
vv := strconv.Itoa(v.(int))
u.Set("networkrate", vv)
}
if v, found := p.p["servicecapabilitylist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("servicecapabilitylist[%d].key", i), k)
u.Set(fmt.Sprintf("servicecapabilitylist[%d].value", i), vv)
i++
}
}
if v, found := p.p["serviceofferingid"]; found {
u.Set("serviceofferingid", v.(string))
}
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
if v, found := p.p["specifyipranges"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("specifyipranges", vv)
}
if v, found := p.p["specifyvlan"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("specifyvlan", vv)
}
if v, found := p.p["supportedservices"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("supportedservices", vv)
}
if v, found := p.p["tags"]; found {
u.Set("tags", v.(string))
}
if v, found := p.p["traffictype"]; found {
u.Set("traffictype", v.(string))
}
return u
}
func (p *CreateNetworkOfferingParams) SetAvailability(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["availability"] = v
return
}
func (p *CreateNetworkOfferingParams) SetConservemode(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["conservemode"] = v
return
}
func (p *CreateNetworkOfferingParams) SetDetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["details"] = v
return
}
func (p *CreateNetworkOfferingParams) SetDisplaytext(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displaytext"] = v
return
}
func (p *CreateNetworkOfferingParams) SetEgressdefaultpolicy(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["egressdefaultpolicy"] = v
return
}
func (p *CreateNetworkOfferingParams) SetGuestiptype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["guestiptype"] = v
return
}
func (p *CreateNetworkOfferingParams) SetIspersistent(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ispersistent"] = v
return
}
func (p *CreateNetworkOfferingParams) SetKeepaliveenabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keepaliveenabled"] = v
return
}
func (p *CreateNetworkOfferingParams) SetMaxconnections(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["maxconnections"] = v
return
}
func (p *CreateNetworkOfferingParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateNetworkOfferingParams) SetNetworkrate(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkrate"] = v
return
}
func (p *CreateNetworkOfferingParams) SetServicecapabilitylist(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["servicecapabilitylist"] = v
return
}
func (p *CreateNetworkOfferingParams) SetServiceofferingid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["serviceofferingid"] = v
return
}
func (p *CreateNetworkOfferingParams) SetServiceproviderlist(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["serviceproviderlist"] = v
return
}
func (p *CreateNetworkOfferingParams) SetSpecifyipranges(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["specifyipranges"] = v
return
}
func (p *CreateNetworkOfferingParams) SetSpecifyvlan(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["specifyvlan"] = v
return
}
func (p *CreateNetworkOfferingParams) SetSupportedservices(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["supportedservices"] = v
return
}
func (p *CreateNetworkOfferingParams) SetTags(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
func (p *CreateNetworkOfferingParams) SetTraffictype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["traffictype"] = v
return
}
// You should always use this function to get a new CreateNetworkOfferingParams instance,
// as then you are sure you have configured all required params
func (s *NetworkOfferingService) NewCreateNetworkOfferingParams(displaytext string, guestiptype string, name string, supportedservices []string, traffictype string) *CreateNetworkOfferingParams {
p := &CreateNetworkOfferingParams{}
p.p = make(map[string]interface{})
p.p["displaytext"] = displaytext
p.p["guestiptype"] = guestiptype
p.p["name"] = name
p.p["supportedservices"] = supportedservices
p.p["traffictype"] = traffictype
return p
}
// Creates a network offering.
func (s *NetworkOfferingService) CreateNetworkOffering(p *CreateNetworkOfferingParams) (*CreateNetworkOfferingResponse, error) {
resp, err := s.cs.newRequest("createNetworkOffering", p.toURLValues())
if err != nil {
return nil, err
}
if resp, err = getRawValue(resp); err != nil {
return nil, err
}
var r CreateNetworkOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateNetworkOfferingResponse struct {
Availability string `json:"availability,omitempty"`
Conservemode bool `json:"conservemode,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"`
Forvpc bool `json:"forvpc,omitempty"`
Guestiptype string `json:"guestiptype,omitempty"`
Id string `json:"id,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Ispersistent bool `json:"ispersistent,omitempty"`
Maxconnections int `json:"maxconnections,omitempty"`
Name string `json:"name,omitempty"`
Networkrate int `json:"networkrate,omitempty"`
Service []struct {
Capability []struct {
Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
} `json:"capability,omitempty"`
Name string `json:"name,omitempty"`
Provider []struct {
Canenableindividualservice bool `json:"canenableindividualservice,omitempty"`
Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Servicelist []string `json:"servicelist,omitempty"`
State string `json:"state,omitempty"`
} `json:"provider,omitempty"`
} `json:"service,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Specifyipranges bool `json:"specifyipranges,omitempty"`
Specifyvlan bool `json:"specifyvlan,omitempty"`
State string `json:"state,omitempty"`
Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"`
Tags string `json:"tags,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
}
type UpdateNetworkOfferingParams struct {
p map[string]interface{}
}
func (p *UpdateNetworkOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["availability"]; found {
u.Set("availability", v.(string))
}
if v, found := p.p["displaytext"]; found {
u.Set("displaytext", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keepaliveenabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("keepaliveenabled", vv)
}
if v, found := p.p["maxconnections"]; found {
vv := strconv.Itoa(v.(int))
u.Set("maxconnections", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["sortkey"]; found {
vv := strconv.Itoa(v.(int))
u.Set("sortkey", vv)
}
if v, found := p.p["state"]; found {
u.Set("state", v.(string))
}
return u
}
func (p *UpdateNetworkOfferingParams) SetAvailability(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["availability"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetDisplaytext(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displaytext"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetKeepaliveenabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keepaliveenabled"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetMaxconnections(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["maxconnections"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetSortkey(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["sortkey"] = v
return
}
func (p *UpdateNetworkOfferingParams) SetState(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["state"] = v
return
}
// You should always use this function to get a new UpdateNetworkOfferingParams instance,
// as then you are sure you have configured all required params
func (s *NetworkOfferingService) NewUpdateNetworkOfferingParams() *UpdateNetworkOfferingParams {
p := &UpdateNetworkOfferingParams{}
p.p = make(map[string]interface{})
return p
}
// Updates a network offering.
func (s *NetworkOfferingService) UpdateNetworkOffering(p *UpdateNetworkOfferingParams) (*UpdateNetworkOfferingResponse, error) {
resp, err := s.cs.newRequest("updateNetworkOffering", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateNetworkOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateNetworkOfferingResponse struct {
Availability string `json:"availability,omitempty"`
Conservemode bool `json:"conservemode,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"`
Forvpc bool `json:"forvpc,omitempty"`
Guestiptype string `json:"guestiptype,omitempty"`
Id string `json:"id,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Ispersistent bool `json:"ispersistent,omitempty"`
Maxconnections int `json:"maxconnections,omitempty"`
Name string `json:"name,omitempty"`
Networkrate int `json:"networkrate,omitempty"`
Service []struct {
Capability []struct {
Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
} `json:"capability,omitempty"`
Name string `json:"name,omitempty"`
Provider []struct {
Canenableindividualservice bool `json:"canenableindividualservice,omitempty"`
Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Servicelist []string `json:"servicelist,omitempty"`
State string `json:"state,omitempty"`
} `json:"provider,omitempty"`
} `json:"service,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Specifyipranges bool `json:"specifyipranges,omitempty"`
Specifyvlan bool `json:"specifyvlan,omitempty"`
State string `json:"state,omitempty"`
Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"`
Tags string `json:"tags,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
}
type DeleteNetworkOfferingParams struct {
p map[string]interface{}
}
func (p *DeleteNetworkOfferingParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteNetworkOfferingParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteNetworkOfferingParams instance,
// as then you are sure you have configured all required params
func (s *NetworkOfferingService) NewDeleteNetworkOfferingParams(id string) *DeleteNetworkOfferingParams {
p := &DeleteNetworkOfferingParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes a network offering.
func (s *NetworkOfferingService) DeleteNetworkOffering(p *DeleteNetworkOfferingParams) (*DeleteNetworkOfferingResponse, error) {
resp, err := s.cs.newRequest("deleteNetworkOffering", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteNetworkOfferingResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteNetworkOfferingResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type ListNetworkOfferingsParams struct {
p map[string]interface{}
}
func (p *ListNetworkOfferingsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["availability"]; found {
u.Set("availability", v.(string))
}
if v, found := p.p["displaytext"]; found {
u.Set("displaytext", v.(string))
}
if v, found := p.p["forvpc"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forvpc", vv)
}
if v, found := p.p["guestiptype"]; found {
u.Set("guestiptype", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isdefault"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isdefault", vv)
}
if v, found := p.p["istagged"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("istagged", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["networkid"]; found {
u.Set("networkid", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["sourcenatsupported"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("sourcenatsupported", vv)
}
if v, found := p.p["specifyipranges"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("specifyipranges", vv)
}
if v, found := p.p["specifyvlan"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("specifyvlan", vv)
}
if v, found := p.p["state"]; found {
u.Set("state", v.(string))
}
if v, found := p.p["supportedservices"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("supportedservices", vv)
}
if v, found := p.p["tags"]; found {
u.Set("tags", v.(string))
}
if v, found := p.p["traffictype"]; found {
u.Set("traffictype", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListNetworkOfferingsParams) SetAvailability(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["availability"] = v
return
}
func (p *ListNetworkOfferingsParams) SetDisplaytext(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["displaytext"] = v
return
}
func (p *ListNetworkOfferingsParams) SetForvpc(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forvpc"] = v
return
}
func (p *ListNetworkOfferingsParams) SetGuestiptype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["guestiptype"] = v
return
}
func (p *ListNetworkOfferingsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListNetworkOfferingsParams) SetIsdefault(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isdefault"] = v
return
}
func (p *ListNetworkOfferingsParams) SetIstagged(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["istagged"] = v
return
}
func (p *ListNetworkOfferingsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListNetworkOfferingsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListNetworkOfferingsParams) SetNetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkid"] = v
return
}
func (p *ListNetworkOfferingsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListNetworkOfferingsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListNetworkOfferingsParams) SetSourcenatsupported(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["sourcenatsupported"] = v
return
}
func (p *ListNetworkOfferingsParams) SetSpecifyipranges(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["specifyipranges"] = v
return
}
func (p *ListNetworkOfferingsParams) SetSpecifyvlan(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["specifyvlan"] = v
return
}
func (p *ListNetworkOfferingsParams) SetState(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["state"] = v
return
}
func (p *ListNetworkOfferingsParams) SetSupportedservices(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["supportedservices"] = v
return
}
func (p *ListNetworkOfferingsParams) SetTags(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
func (p *ListNetworkOfferingsParams) SetTraffictype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["traffictype"] = v
return
}
func (p *ListNetworkOfferingsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListNetworkOfferingsParams instance,
// as then you are sure you have configured all required params
func (s *NetworkOfferingService) NewListNetworkOfferingsParams() *ListNetworkOfferingsParams {
p := &ListNetworkOfferingsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *NetworkOfferingService) GetNetworkOfferingID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListNetworkOfferingsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListNetworkOfferings(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.NetworkOfferings[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.NetworkOfferings {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *NetworkOfferingService) GetNetworkOfferingByName(name string, opts ...OptionFunc) (*NetworkOffering, int, error) {
id, count, err := s.GetNetworkOfferingID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetNetworkOfferingByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *NetworkOfferingService) GetNetworkOfferingByID(id string, opts ...OptionFunc) (*NetworkOffering, int, error) {
p := &ListNetworkOfferingsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListNetworkOfferings(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.NetworkOfferings[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for NetworkOffering UUID: %s!", id)
}
// Lists all available network offerings.
func (s *NetworkOfferingService) ListNetworkOfferings(p *ListNetworkOfferingsParams) (*ListNetworkOfferingsResponse, error) {
resp, err := s.cs.newRequest("listNetworkOfferings", p.toURLValues())
if err != nil {
return nil, err
}
var r ListNetworkOfferingsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListNetworkOfferingsResponse struct {
Count int `json:"count"`
NetworkOfferings []*NetworkOffering `json:"networkoffering"`
}
type NetworkOffering struct {
Availability string `json:"availability,omitempty"`
Conservemode bool `json:"conservemode,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"`
Forvpc bool `json:"forvpc,omitempty"`
Guestiptype string `json:"guestiptype,omitempty"`
Id string `json:"id,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Ispersistent bool `json:"ispersistent,omitempty"`
Maxconnections int `json:"maxconnections,omitempty"`
Name string `json:"name,omitempty"`
Networkrate int `json:"networkrate,omitempty"`
Service []struct {
Capability []struct {
Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
} `json:"capability,omitempty"`
Name string `json:"name,omitempty"`
Provider []struct {
Canenableindividualservice bool `json:"canenableindividualservice,omitempty"`
Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Servicelist []string `json:"servicelist,omitempty"`
State string `json:"state,omitempty"`
} `json:"provider,omitempty"`
} `json:"service,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Specifyipranges bool `json:"specifyipranges,omitempty"`
Specifyvlan bool `json:"specifyvlan,omitempty"`
State string `json:"state,omitempty"`
Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"`
Tags string `json:"tags,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,574 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type AddIpToNicParams struct {
p map[string]interface{}
}
func (p *AddIpToNicParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["ipaddress"]; found {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["nicid"]; found {
u.Set("nicid", v.(string))
}
return u
}
func (p *AddIpToNicParams) SetIpaddress(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddress"] = v
return
}
func (p *AddIpToNicParams) SetNicid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nicid"] = v
return
}
// You should always use this function to get a new AddIpToNicParams instance,
// as then you are sure you have configured all required params
func (s *NicService) NewAddIpToNicParams(nicid string) *AddIpToNicParams {
p := &AddIpToNicParams{}
p.p = make(map[string]interface{})
p.p["nicid"] = nicid
return p
}
// Assigns secondary IP to NIC
func (s *NicService) AddIpToNic(p *AddIpToNicParams) (*AddIpToNicResponse, error) {
resp, err := s.cs.newRequest("addIpToNic", p.toURLValues())
if err != nil {
return nil, err
}
var r AddIpToNicResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddIpToNicResponse struct {
JobID string `json:"jobid,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Networkid string `json:"networkid,omitempty"`
Nicid string `json:"nicid,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
}
type RemoveIpFromNicParams struct {
p map[string]interface{}
}
func (p *RemoveIpFromNicParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *RemoveIpFromNicParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new RemoveIpFromNicParams instance,
// as then you are sure you have configured all required params
func (s *NicService) NewRemoveIpFromNicParams(id string) *RemoveIpFromNicParams {
p := &RemoveIpFromNicParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Removes secondary IP from the NIC.
func (s *NicService) RemoveIpFromNic(p *RemoveIpFromNicParams) (*RemoveIpFromNicResponse, error) {
resp, err := s.cs.newRequest("removeIpFromNic", p.toURLValues())
if err != nil {
return nil, err
}
var r RemoveIpFromNicResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type RemoveIpFromNicResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type UpdateVmNicIpParams struct {
p map[string]interface{}
}
func (p *UpdateVmNicIpParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["ipaddress"]; found {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["nicid"]; found {
u.Set("nicid", v.(string))
}
return u
}
func (p *UpdateVmNicIpParams) SetIpaddress(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddress"] = v
return
}
func (p *UpdateVmNicIpParams) SetNicid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nicid"] = v
return
}
// You should always use this function to get a new UpdateVmNicIpParams instance,
// as then you are sure you have configured all required params
func (s *NicService) NewUpdateVmNicIpParams(nicid string) *UpdateVmNicIpParams {
p := &UpdateVmNicIpParams{}
p.p = make(map[string]interface{})
p.p["nicid"] = nicid
return p
}
// Update the default Ip of a VM Nic
func (s *NicService) UpdateVmNicIp(p *UpdateVmNicIpParams) (*UpdateVmNicIpResponse, error) {
resp, err := s.cs.newRequest("updateVmNicIp", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateVmNicIpResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type UpdateVmNicIpResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Affinitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Type string `json:"type,omitempty"`
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
} `json:"affinitygroup,omitempty"`
Cpunumber int `json:"cpunumber,omitempty"`
Cpuspeed int `json:"cpuspeed,omitempty"`
Cpuused string `json:"cpuused,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Diskioread int64 `json:"diskioread,omitempty"`
Diskiowrite int64 `json:"diskiowrite,omitempty"`
Diskkbsread int64 `json:"diskkbsread,omitempty"`
Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
Diskofferingid string `json:"diskofferingid,omitempty"`
Diskofferingname string `json:"diskofferingname,omitempty"`
Displayname string `json:"displayname,omitempty"`
Displayvm bool `json:"displayvm,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Group string `json:"group,omitempty"`
Groupid string `json:"groupid,omitempty"`
Guestosid string `json:"guestosid,omitempty"`
Haenable bool `json:"haenable,omitempty"`
Hostid string `json:"hostid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Instancename string `json:"instancename,omitempty"`
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
Isodisplaytext string `json:"isodisplaytext,omitempty"`
Isoid string `json:"isoid,omitempty"`
Isoname string `json:"isoname,omitempty"`
Keypair string `json:"keypair,omitempty"`
Memory int `json:"memory,omitempty"`
Name string `json:"name,omitempty"`
Networkkbsread int64 `json:"networkkbsread,omitempty"`
Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
Nic []struct {
Broadcasturi string `json:"broadcasturi,omitempty"`
Deviceid string `json:"deviceid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Netmask string `json:"netmask,omitempty"`
Networkid string `json:"networkid,omitempty"`
Networkname string `json:"networkname,omitempty"`
Secondaryip []struct {
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
} `json:"secondaryip,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Type string `json:"type,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
} `json:"nic,omitempty"`
Ostypeid int64 `json:"ostypeid,omitempty"`
Password string `json:"password,omitempty"`
Passwordenabled bool `json:"passwordenabled,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Publicip string `json:"publicip,omitempty"`
Publicipid string `json:"publicipid,omitempty"`
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
Rootdevicetype string `json:"rootdevicetype,omitempty"`
Securitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Egressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"egressrule,omitempty"`
Id string `json:"id,omitempty"`
Ingressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"ingressrule,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinecount int `json:"virtualmachinecount,omitempty"`
Virtualmachineids []string `json:"virtualmachineids,omitempty"`
} `json:"securitygroup,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Servicestate string `json:"servicestate,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
Templateid string `json:"templateid,omitempty"`
Templatename string `json:"templatename,omitempty"`
Userid string `json:"userid,omitempty"`
Username string `json:"username,omitempty"`
Vgpu string `json:"vgpu,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type ListNicsParams struct {
p map[string]interface{}
}
func (p *ListNicsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["networkid"]; found {
u.Set("networkid", v.(string))
}
if v, found := p.p["nicid"]; found {
u.Set("nicid", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["virtualmachineid"]; found {
u.Set("virtualmachineid", v.(string))
}
return u
}
func (p *ListNicsParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *ListNicsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListNicsParams) SetNetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkid"] = v
return
}
func (p *ListNicsParams) SetNicid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nicid"] = v
return
}
func (p *ListNicsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListNicsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListNicsParams) SetVirtualmachineid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["virtualmachineid"] = v
return
}
// You should always use this function to get a new ListNicsParams instance,
// as then you are sure you have configured all required params
func (s *NicService) NewListNicsParams(virtualmachineid string) *ListNicsParams {
p := &ListNicsParams{}
p.p = make(map[string]interface{})
p.p["virtualmachineid"] = virtualmachineid
return p
}
// list the vm nics IP to NIC
func (s *NicService) ListNics(p *ListNicsParams) (*ListNicsResponse, error) {
resp, err := s.cs.newRequest("listNics", p.toURLValues())
if err != nil {
return nil, err
}
var r ListNicsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListNicsResponse struct {
Count int `json:"count"`
Nics []*Nic `json:"nic"`
}
type Nic struct {
Broadcasturi string `json:"broadcasturi,omitempty"`
Deviceid string `json:"deviceid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Netmask string `json:"netmask,omitempty"`
Networkid string `json:"networkid,omitempty"`
Networkname string `json:"networkname,omitempty"`
Secondaryip []struct {
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
} `json:"secondaryip,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Type string `json:"type,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
}

View File

@@ -1,332 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type AddNiciraNvpDeviceParams struct {
p map[string]interface{}
}
func (p *AddNiciraNvpDeviceParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["hostname"]; found {
u.Set("hostname", v.(string))
}
if v, found := p.p["l3gatewayserviceuuid"]; found {
u.Set("l3gatewayserviceuuid", v.(string))
}
if v, found := p.p["password"]; found {
u.Set("password", v.(string))
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
if v, found := p.p["transportzoneuuid"]; found {
u.Set("transportzoneuuid", v.(string))
}
if v, found := p.p["username"]; found {
u.Set("username", v.(string))
}
return u
}
func (p *AddNiciraNvpDeviceParams) SetHostname(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostname"] = v
return
}
func (p *AddNiciraNvpDeviceParams) SetL3gatewayserviceuuid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["l3gatewayserviceuuid"] = v
return
}
func (p *AddNiciraNvpDeviceParams) SetPassword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["password"] = v
return
}
func (p *AddNiciraNvpDeviceParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
func (p *AddNiciraNvpDeviceParams) SetTransportzoneuuid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["transportzoneuuid"] = v
return
}
func (p *AddNiciraNvpDeviceParams) SetUsername(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["username"] = v
return
}
// You should always use this function to get a new AddNiciraNvpDeviceParams instance,
// as then you are sure you have configured all required params
func (s *NiciraNVPService) NewAddNiciraNvpDeviceParams(hostname string, password string, physicalnetworkid string, transportzoneuuid string, username string) *AddNiciraNvpDeviceParams {
p := &AddNiciraNvpDeviceParams{}
p.p = make(map[string]interface{})
p.p["hostname"] = hostname
p.p["password"] = password
p.p["physicalnetworkid"] = physicalnetworkid
p.p["transportzoneuuid"] = transportzoneuuid
p.p["username"] = username
return p
}
// Adds a Nicira NVP device
func (s *NiciraNVPService) AddNiciraNvpDevice(p *AddNiciraNvpDeviceParams) (*AddNiciraNvpDeviceResponse, error) {
resp, err := s.cs.newRequest("addNiciraNvpDevice", p.toURLValues())
if err != nil {
return nil, err
}
var r AddNiciraNvpDeviceResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddNiciraNvpDeviceResponse struct {
JobID string `json:"jobid,omitempty"`
Hostname string `json:"hostname,omitempty"`
L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"`
Niciradevicename string `json:"niciradevicename,omitempty"`
Nvpdeviceid string `json:"nvpdeviceid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Provider string `json:"provider,omitempty"`
Transportzoneuuid string `json:"transportzoneuuid,omitempty"`
}
type DeleteNiciraNvpDeviceParams struct {
p map[string]interface{}
}
func (p *DeleteNiciraNvpDeviceParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["nvpdeviceid"]; found {
u.Set("nvpdeviceid", v.(string))
}
return u
}
func (p *DeleteNiciraNvpDeviceParams) SetNvpdeviceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nvpdeviceid"] = v
return
}
// You should always use this function to get a new DeleteNiciraNvpDeviceParams instance,
// as then you are sure you have configured all required params
func (s *NiciraNVPService) NewDeleteNiciraNvpDeviceParams(nvpdeviceid string) *DeleteNiciraNvpDeviceParams {
p := &DeleteNiciraNvpDeviceParams{}
p.p = make(map[string]interface{})
p.p["nvpdeviceid"] = nvpdeviceid
return p
}
// delete a nicira nvp device
func (s *NiciraNVPService) DeleteNiciraNvpDevice(p *DeleteNiciraNvpDeviceParams) (*DeleteNiciraNvpDeviceResponse, error) {
resp, err := s.cs.newRequest("deleteNiciraNvpDevice", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteNiciraNvpDeviceResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteNiciraNvpDeviceResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListNiciraNvpDevicesParams struct {
p map[string]interface{}
}
func (p *ListNiciraNvpDevicesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["nvpdeviceid"]; found {
u.Set("nvpdeviceid", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["physicalnetworkid"]; found {
u.Set("physicalnetworkid", v.(string))
}
return u
}
func (p *ListNiciraNvpDevicesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListNiciraNvpDevicesParams) SetNvpdeviceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nvpdeviceid"] = v
return
}
func (p *ListNiciraNvpDevicesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListNiciraNvpDevicesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListNiciraNvpDevicesParams) SetPhysicalnetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["physicalnetworkid"] = v
return
}
// You should always use this function to get a new ListNiciraNvpDevicesParams instance,
// as then you are sure you have configured all required params
func (s *NiciraNVPService) NewListNiciraNvpDevicesParams() *ListNiciraNvpDevicesParams {
p := &ListNiciraNvpDevicesParams{}
p.p = make(map[string]interface{})
return p
}
// Lists Nicira NVP devices
func (s *NiciraNVPService) ListNiciraNvpDevices(p *ListNiciraNvpDevicesParams) (*ListNiciraNvpDevicesResponse, error) {
resp, err := s.cs.newRequest("listNiciraNvpDevices", p.toURLValues())
if err != nil {
return nil, err
}
var r ListNiciraNvpDevicesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListNiciraNvpDevicesResponse struct {
Count int `json:"count"`
NiciraNvpDevices []*NiciraNvpDevice `json:"niciranvpdevice"`
}
type NiciraNvpDevice struct {
Hostname string `json:"hostname,omitempty"`
L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"`
Niciradevicename string `json:"niciradevicename,omitempty"`
Nvpdeviceid string `json:"nvpdeviceid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Provider string `json:"provider,omitempty"`
Transportzoneuuid string `json:"transportzoneuuid,omitempty"`
}

View File

@@ -1,268 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ConfigureOvsElementParams struct {
p map[string]interface{}
}
func (p *ConfigureOvsElementParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("enabled", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *ConfigureOvsElementParams) SetEnabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enabled"] = v
return
}
func (p *ConfigureOvsElementParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new ConfigureOvsElementParams instance,
// as then you are sure you have configured all required params
func (s *OvsElementService) NewConfigureOvsElementParams(enabled bool, id string) *ConfigureOvsElementParams {
p := &ConfigureOvsElementParams{}
p.p = make(map[string]interface{})
p.p["enabled"] = enabled
p.p["id"] = id
return p
}
// Configures an ovs element.
func (s *OvsElementService) ConfigureOvsElement(p *ConfigureOvsElementParams) (*ConfigureOvsElementResponse, error) {
resp, err := s.cs.newRequest("configureOvsElement", p.toURLValues())
if err != nil {
return nil, err
}
var r ConfigureOvsElementResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type ConfigureOvsElementResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Id string `json:"id,omitempty"`
Nspid string `json:"nspid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
}
type ListOvsElementsParams struct {
p map[string]interface{}
}
func (p *ListOvsElementsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["enabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("enabled", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["nspid"]; found {
u.Set("nspid", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListOvsElementsParams) SetEnabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enabled"] = v
return
}
func (p *ListOvsElementsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListOvsElementsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListOvsElementsParams) SetNspid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nspid"] = v
return
}
func (p *ListOvsElementsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListOvsElementsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListOvsElementsParams instance,
// as then you are sure you have configured all required params
func (s *OvsElementService) NewListOvsElementsParams() *ListOvsElementsParams {
p := &ListOvsElementsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *OvsElementService) GetOvsElementByID(id string, opts ...OptionFunc) (*OvsElement, int, error) {
p := &ListOvsElementsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListOvsElements(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.OvsElements[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for OvsElement UUID: %s!", id)
}
// Lists all available ovs elements.
func (s *OvsElementService) ListOvsElements(p *ListOvsElementsParams) (*ListOvsElementsResponse, error) {
resp, err := s.cs.newRequest("listOvsElements", p.toURLValues())
if err != nil {
return nil, err
}
var r ListOvsElementsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListOvsElementsResponse struct {
Count int `json:"count"`
OvsElements []*OvsElement `json:"ovselement"`
}
type OvsElement struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Id string `json:"id,omitempty"`
Nspid string `json:"nspid,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
}

View File

@@ -1,882 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreatePodParams struct {
p map[string]interface{}
}
func (p *CreatePodParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["allocationstate"]; found {
u.Set("allocationstate", v.(string))
}
if v, found := p.p["endip"]; found {
u.Set("endip", v.(string))
}
if v, found := p.p["gateway"]; found {
u.Set("gateway", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["netmask"]; found {
u.Set("netmask", v.(string))
}
if v, found := p.p["startip"]; found {
u.Set("startip", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *CreatePodParams) SetAllocationstate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["allocationstate"] = v
return
}
func (p *CreatePodParams) SetEndip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endip"] = v
return
}
func (p *CreatePodParams) SetGateway(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["gateway"] = v
return
}
func (p *CreatePodParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreatePodParams) SetNetmask(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["netmask"] = v
return
}
func (p *CreatePodParams) SetStartip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startip"] = v
return
}
func (p *CreatePodParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new CreatePodParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewCreatePodParams(gateway string, name string, netmask string, startip string, zoneid string) *CreatePodParams {
p := &CreatePodParams{}
p.p = make(map[string]interface{})
p.p["gateway"] = gateway
p.p["name"] = name
p.p["netmask"] = netmask
p.p["startip"] = startip
p.p["zoneid"] = zoneid
return p
}
// Creates a new Pod.
func (s *PodService) CreatePod(p *CreatePodParams) (*CreatePodResponse, error) {
resp, err := s.cs.newRequest("createPod", p.toURLValues())
if err != nil {
return nil, err
}
var r CreatePodResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreatePodResponse struct {
Allocationstate string `json:"allocationstate,omitempty"`
Capacity []struct {
Capacitytotal int64 `json:"capacitytotal,omitempty"`
Capacityused int64 `json:"capacityused,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Percentused string `json:"percentused,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Type int `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
} `json:"capacity,omitempty"`
Endip string `json:"endip,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Netmask string `json:"netmask,omitempty"`
Startip string `json:"startip,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type UpdatePodParams struct {
p map[string]interface{}
}
func (p *UpdatePodParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["allocationstate"]; found {
u.Set("allocationstate", v.(string))
}
if v, found := p.p["endip"]; found {
u.Set("endip", v.(string))
}
if v, found := p.p["gateway"]; found {
u.Set("gateway", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["netmask"]; found {
u.Set("netmask", v.(string))
}
if v, found := p.p["startip"]; found {
u.Set("startip", v.(string))
}
return u
}
func (p *UpdatePodParams) SetAllocationstate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["allocationstate"] = v
return
}
func (p *UpdatePodParams) SetEndip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endip"] = v
return
}
func (p *UpdatePodParams) SetGateway(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["gateway"] = v
return
}
func (p *UpdatePodParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdatePodParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *UpdatePodParams) SetNetmask(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["netmask"] = v
return
}
func (p *UpdatePodParams) SetStartip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startip"] = v
return
}
// You should always use this function to get a new UpdatePodParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewUpdatePodParams(id string) *UpdatePodParams {
p := &UpdatePodParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a Pod.
func (s *PodService) UpdatePod(p *UpdatePodParams) (*UpdatePodResponse, error) {
resp, err := s.cs.newRequest("updatePod", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdatePodResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdatePodResponse struct {
Allocationstate string `json:"allocationstate,omitempty"`
Capacity []struct {
Capacitytotal int64 `json:"capacitytotal,omitempty"`
Capacityused int64 `json:"capacityused,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Percentused string `json:"percentused,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Type int `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
} `json:"capacity,omitempty"`
Endip string `json:"endip,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Netmask string `json:"netmask,omitempty"`
Startip string `json:"startip,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type DeletePodParams struct {
p map[string]interface{}
}
func (p *DeletePodParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeletePodParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeletePodParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewDeletePodParams(id string) *DeletePodParams {
p := &DeletePodParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes a Pod.
func (s *PodService) DeletePod(p *DeletePodParams) (*DeletePodResponse, error) {
resp, err := s.cs.newRequest("deletePod", p.toURLValues())
if err != nil {
return nil, err
}
var r DeletePodResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeletePodResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type ListPodsParams struct {
p map[string]interface{}
}
func (p *ListPodsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["allocationstate"]; found {
u.Set("allocationstate", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["showcapacities"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("showcapacities", vv)
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListPodsParams) SetAllocationstate(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["allocationstate"] = v
return
}
func (p *ListPodsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListPodsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListPodsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListPodsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListPodsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListPodsParams) SetShowcapacities(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["showcapacities"] = v
return
}
func (p *ListPodsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListPodsParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewListPodsParams() *ListPodsParams {
p := &ListPodsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PodService) GetPodID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListPodsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListPods(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.Pods[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.Pods {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PodService) GetPodByName(name string, opts ...OptionFunc) (*Pod, int, error) {
id, count, err := s.GetPodID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetPodByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PodService) GetPodByID(id string, opts ...OptionFunc) (*Pod, int, error) {
p := &ListPodsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListPods(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.Pods[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for Pod UUID: %s!", id)
}
// Lists all Pods.
func (s *PodService) ListPods(p *ListPodsParams) (*ListPodsResponse, error) {
resp, err := s.cs.newRequest("listPods", p.toURLValues())
if err != nil {
return nil, err
}
var r ListPodsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListPodsResponse struct {
Count int `json:"count"`
Pods []*Pod `json:"pod"`
}
type Pod struct {
Allocationstate string `json:"allocationstate,omitempty"`
Capacity []struct {
Capacitytotal int64 `json:"capacitytotal,omitempty"`
Capacityused int64 `json:"capacityused,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Percentused string `json:"percentused,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Type int `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
} `json:"capacity,omitempty"`
Endip string `json:"endip,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Netmask string `json:"netmask,omitempty"`
Startip string `json:"startip,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type DedicatePodParams struct {
p map[string]interface{}
}
func (p *DedicatePodParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
return u
}
func (p *DedicatePodParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *DedicatePodParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *DedicatePodParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
// You should always use this function to get a new DedicatePodParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewDedicatePodParams(domainid string, podid string) *DedicatePodParams {
p := &DedicatePodParams{}
p.p = make(map[string]interface{})
p.p["domainid"] = domainid
p.p["podid"] = podid
return p
}
// Dedicates a Pod.
func (s *PodService) DedicatePod(p *DedicatePodParams) (*DedicatePodResponse, error) {
resp, err := s.cs.newRequest("dedicatePod", p.toURLValues())
if err != nil {
return nil, err
}
var r DedicatePodResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DedicatePodResponse struct {
JobID string `json:"jobid,omitempty"`
Accountid string `json:"accountid,omitempty"`
Affinitygroupid string `json:"affinitygroupid,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
}
type ReleaseDedicatedPodParams struct {
p map[string]interface{}
}
func (p *ReleaseDedicatedPodParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
return u
}
func (p *ReleaseDedicatedPodParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
// You should always use this function to get a new ReleaseDedicatedPodParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewReleaseDedicatedPodParams(podid string) *ReleaseDedicatedPodParams {
p := &ReleaseDedicatedPodParams{}
p.p = make(map[string]interface{})
p.p["podid"] = podid
return p
}
// Release the dedication for the pod
func (s *PodService) ReleaseDedicatedPod(p *ReleaseDedicatedPodParams) (*ReleaseDedicatedPodResponse, error) {
resp, err := s.cs.newRequest("releaseDedicatedPod", p.toURLValues())
if err != nil {
return nil, err
}
var r ReleaseDedicatedPodResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type ReleaseDedicatedPodResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListDedicatedPodsParams struct {
p map[string]interface{}
}
func (p *ListDedicatedPodsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["affinitygroupid"]; found {
u.Set("affinitygroupid", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
return u
}
func (p *ListDedicatedPodsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListDedicatedPodsParams) SetAffinitygroupid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["affinitygroupid"] = v
return
}
func (p *ListDedicatedPodsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListDedicatedPodsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListDedicatedPodsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListDedicatedPodsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListDedicatedPodsParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
// You should always use this function to get a new ListDedicatedPodsParams instance,
// as then you are sure you have configured all required params
func (s *PodService) NewListDedicatedPodsParams() *ListDedicatedPodsParams {
p := &ListDedicatedPodsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists dedicated pods.
func (s *PodService) ListDedicatedPods(p *ListDedicatedPodsParams) (*ListDedicatedPodsResponse, error) {
resp, err := s.cs.newRequest("listDedicatedPods", p.toURLValues())
if err != nil {
return nil, err
}
var r ListDedicatedPodsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListDedicatedPodsResponse struct {
Count int `json:"count"`
DedicatedPods []*DedicatedPod `json:"dedicatedpod"`
}
type DedicatedPod struct {
Accountid string `json:"accountid,omitempty"`
Affinitygroupid string `json:"affinitygroupid,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
}

View File

@@ -1,800 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ListStoragePoolsParams struct {
p map[string]interface{}
}
func (p *ListStoragePoolsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["ipaddress"]; found {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["path"]; found {
u.Set("path", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["scope"]; found {
u.Set("scope", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListStoragePoolsParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
return
}
func (p *ListStoragePoolsParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListStoragePoolsParams) SetIpaddress(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["ipaddress"] = v
return
}
func (p *ListStoragePoolsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListStoragePoolsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListStoragePoolsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListStoragePoolsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListStoragePoolsParams) SetPath(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["path"] = v
return
}
func (p *ListStoragePoolsParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *ListStoragePoolsParams) SetScope(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["scope"] = v
return
}
func (p *ListStoragePoolsParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListStoragePoolsParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewListStoragePoolsParams() *ListStoragePoolsParams {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolID(name string, opts ...OptionFunc) (string, int, error) {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListStoragePools(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
}
if l.Count == 1 {
return l.StoragePools[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.StoragePools {
if v.Name == name {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error) {
id, count, err := s.GetStoragePoolID(name, opts...)
if err != nil {
return nil, count, err
}
r, count, err := s.GetStoragePoolByID(id, opts...)
if err != nil {
return nil, count, err
}
return r, count, nil
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PoolService) GetStoragePoolByID(id string, opts ...OptionFunc) (*StoragePool, int, error) {
p := &ListStoragePoolsParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListStoragePools(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.StoragePools[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for StoragePool UUID: %s!", id)
}
// Lists storage pools.
func (s *PoolService) ListStoragePools(p *ListStoragePoolsParams) (*ListStoragePoolsResponse, error) {
resp, err := s.cs.newRequest("listStoragePools", p.toURLValues())
if err != nil {
return nil, err
}
var r ListStoragePoolsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListStoragePoolsResponse struct {
Count int `json:"count"`
StoragePools []*StoragePool `json:"storagepool"`
}
type StoragePool struct {
Capacityiops int64 `json:"capacityiops,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Created string `json:"created,omitempty"`
Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
Disksizetotal int64 `json:"disksizetotal,omitempty"`
Disksizeused int64 `json:"disksizeused,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Name string `json:"name,omitempty"`
Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
Path string `json:"path,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Scope string `json:"scope,omitempty"`
State string `json:"state,omitempty"`
Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
Suitableformigration bool `json:"suitableformigration,omitempty"`
Tags string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type CreateStoragePoolParams struct {
p map[string]interface{}
}
func (p *CreateStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["capacitybytes"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacitybytes", vv)
}
if v, found := p.p["capacityiops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacityiops", vv)
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["details"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("details[%d].key", i), k)
u.Set(fmt.Sprintf("details[%d].value", i), vv)
i++
}
}
if v, found := p.p["hypervisor"]; found {
u.Set("hypervisor", v.(string))
}
if v, found := p.p["managed"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("managed", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["provider"]; found {
u.Set("provider", v.(string))
}
if v, found := p.p["scope"]; found {
u.Set("scope", v.(string))
}
if v, found := p.p["tags"]; found {
u.Set("tags", v.(string))
}
if v, found := p.p["url"]; found {
u.Set("url", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *CreateStoragePoolParams) SetCapacitybytes(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacitybytes"] = v
return
}
func (p *CreateStoragePoolParams) SetCapacityiops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacityiops"] = v
return
}
func (p *CreateStoragePoolParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
return
}
func (p *CreateStoragePoolParams) SetDetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["details"] = v
return
}
func (p *CreateStoragePoolParams) SetHypervisor(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hypervisor"] = v
return
}
func (p *CreateStoragePoolParams) SetManaged(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["managed"] = v
return
}
func (p *CreateStoragePoolParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateStoragePoolParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *CreateStoragePoolParams) SetProvider(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["provider"] = v
return
}
func (p *CreateStoragePoolParams) SetScope(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["scope"] = v
return
}
func (p *CreateStoragePoolParams) SetTags(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
func (p *CreateStoragePoolParams) SetUrl(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["url"] = v
return
}
func (p *CreateStoragePoolParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new CreateStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewCreateStoragePoolParams(name string, url string, zoneid string) *CreateStoragePoolParams {
p := &CreateStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
p.p["url"] = url
p.p["zoneid"] = zoneid
return p
}
// Creates a storage pool.
func (s *PoolService) CreateStoragePool(p *CreateStoragePoolParams) (*CreateStoragePoolResponse, error) {
resp, err := s.cs.newRequest("createStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateStoragePoolResponse struct {
Capacityiops int64 `json:"capacityiops,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Created string `json:"created,omitempty"`
Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
Disksizetotal int64 `json:"disksizetotal,omitempty"`
Disksizeused int64 `json:"disksizeused,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Name string `json:"name,omitempty"`
Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
Path string `json:"path,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Scope string `json:"scope,omitempty"`
State string `json:"state,omitempty"`
Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
Suitableformigration bool `json:"suitableformigration,omitempty"`
Tags string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type UpdateStoragePoolParams struct {
p map[string]interface{}
}
func (p *UpdateStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["capacitybytes"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacitybytes", vv)
}
if v, found := p.p["capacityiops"]; found {
vv := strconv.FormatInt(v.(int64), 10)
u.Set("capacityiops", vv)
}
if v, found := p.p["enabled"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("enabled", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["tags"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("tags", vv)
}
return u
}
func (p *UpdateStoragePoolParams) SetCapacitybytes(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacitybytes"] = v
return
}
func (p *UpdateStoragePoolParams) SetCapacityiops(v int64) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["capacityiops"] = v
return
}
func (p *UpdateStoragePoolParams) SetEnabled(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["enabled"] = v
return
}
func (p *UpdateStoragePoolParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateStoragePoolParams) SetTags(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
// You should always use this function to get a new UpdateStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewUpdateStoragePoolParams(id string) *UpdateStoragePoolParams {
p := &UpdateStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a storage pool.
func (s *PoolService) UpdateStoragePool(p *UpdateStoragePoolParams) (*UpdateStoragePoolResponse, error) {
resp, err := s.cs.newRequest("updateStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateStoragePoolResponse struct {
Capacityiops int64 `json:"capacityiops,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Created string `json:"created,omitempty"`
Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
Disksizetotal int64 `json:"disksizetotal,omitempty"`
Disksizeused int64 `json:"disksizeused,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Name string `json:"name,omitempty"`
Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
Path string `json:"path,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Scope string `json:"scope,omitempty"`
State string `json:"state,omitempty"`
Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
Suitableformigration bool `json:"suitableformigration,omitempty"`
Tags string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type DeleteStoragePoolParams struct {
p map[string]interface{}
}
func (p *DeleteStoragePoolParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["forced"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forced", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeleteStoragePoolParams) SetForced(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forced"] = v
return
}
func (p *DeleteStoragePoolParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeleteStoragePoolParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewDeleteStoragePoolParams(id string) *DeleteStoragePoolParams {
p := &DeleteStoragePoolParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Deletes a storage pool.
func (s *PoolService) DeleteStoragePool(p *DeleteStoragePoolParams) (*DeleteStoragePoolResponse, error) {
resp, err := s.cs.newRequest("deleteStoragePool", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteStoragePoolResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteStoragePoolResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type FindStoragePoolsForMigrationParams struct {
p map[string]interface{}
}
func (p *FindStoragePoolsForMigrationParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *FindStoragePoolsForMigrationParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *FindStoragePoolsForMigrationParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *FindStoragePoolsForMigrationParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *FindStoragePoolsForMigrationParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new FindStoragePoolsForMigrationParams instance,
// as then you are sure you have configured all required params
func (s *PoolService) NewFindStoragePoolsForMigrationParams(id string) *FindStoragePoolsForMigrationParams {
p := &FindStoragePoolsForMigrationParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Lists storage pools available for migration of a volume.
func (s *PoolService) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error) {
resp, err := s.cs.newRequest("findStoragePoolsForMigration", p.toURLValues())
if err != nil {
return nil, err
}
var r FindStoragePoolsForMigrationResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type FindStoragePoolsForMigrationResponse struct {
Capacityiops int64 `json:"capacityiops,omitempty"`
Clusterid string `json:"clusterid,omitempty"`
Clustername string `json:"clustername,omitempty"`
Created string `json:"created,omitempty"`
Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
Disksizetotal int64 `json:"disksizetotal,omitempty"`
Disksizeused int64 `json:"disksizeused,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Name string `json:"name,omitempty"`
Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
Path string `json:"path,omitempty"`
Podid string `json:"podid,omitempty"`
Podname string `json:"podname,omitempty"`
Scope string `json:"scope,omitempty"`
State string `json:"state,omitempty"`
Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
Suitableformigration bool `json:"suitableformigration,omitempty"`
Tags string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}

View File

@@ -1,393 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreatePortableIpRangeParams struct {
p map[string]interface{}
}
func (p *CreatePortableIpRangeParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["endip"]; found {
u.Set("endip", v.(string))
}
if v, found := p.p["gateway"]; found {
u.Set("gateway", v.(string))
}
if v, found := p.p["netmask"]; found {
u.Set("netmask", v.(string))
}
if v, found := p.p["regionid"]; found {
vv := strconv.Itoa(v.(int))
u.Set("regionid", vv)
}
if v, found := p.p["startip"]; found {
u.Set("startip", v.(string))
}
if v, found := p.p["vlan"]; found {
u.Set("vlan", v.(string))
}
return u
}
func (p *CreatePortableIpRangeParams) SetEndip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endip"] = v
return
}
func (p *CreatePortableIpRangeParams) SetGateway(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["gateway"] = v
return
}
func (p *CreatePortableIpRangeParams) SetNetmask(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["netmask"] = v
return
}
func (p *CreatePortableIpRangeParams) SetRegionid(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["regionid"] = v
return
}
func (p *CreatePortableIpRangeParams) SetStartip(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["startip"] = v
return
}
func (p *CreatePortableIpRangeParams) SetVlan(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vlan"] = v
return
}
// You should always use this function to get a new CreatePortableIpRangeParams instance,
// as then you are sure you have configured all required params
func (s *PortableIPService) NewCreatePortableIpRangeParams(endip string, gateway string, netmask string, regionid int, startip string) *CreatePortableIpRangeParams {
p := &CreatePortableIpRangeParams{}
p.p = make(map[string]interface{})
p.p["endip"] = endip
p.p["gateway"] = gateway
p.p["netmask"] = netmask
p.p["regionid"] = regionid
p.p["startip"] = startip
return p
}
// adds a range of portable public IP's to a region
func (s *PortableIPService) CreatePortableIpRange(p *CreatePortableIpRangeParams) (*CreatePortableIpRangeResponse, error) {
resp, err := s.cs.newRequest("createPortableIpRange", p.toURLValues())
if err != nil {
return nil, err
}
var r CreatePortableIpRangeResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type CreatePortableIpRangeResponse struct {
JobID string `json:"jobid,omitempty"`
Endip string `json:"endip,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Netmask string `json:"netmask,omitempty"`
Portableipaddress []struct {
Accountid string `json:"accountid,omitempty"`
Allocated string `json:"allocated,omitempty"`
Domainid string `json:"domainid,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Networkid string `json:"networkid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Regionid int `json:"regionid,omitempty"`
State string `json:"state,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
} `json:"portableipaddress,omitempty"`
Regionid int `json:"regionid,omitempty"`
Startip string `json:"startip,omitempty"`
Vlan string `json:"vlan,omitempty"`
}
type DeletePortableIpRangeParams struct {
p map[string]interface{}
}
func (p *DeletePortableIpRangeParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DeletePortableIpRangeParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DeletePortableIpRangeParams instance,
// as then you are sure you have configured all required params
func (s *PortableIPService) NewDeletePortableIpRangeParams(id string) *DeletePortableIpRangeParams {
p := &DeletePortableIpRangeParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// deletes a range of portable public IP's associated with a region
func (s *PortableIPService) DeletePortableIpRange(p *DeletePortableIpRangeParams) (*DeletePortableIpRangeResponse, error) {
resp, err := s.cs.newRequest("deletePortableIpRange", p.toURLValues())
if err != nil {
return nil, err
}
var r DeletePortableIpRangeResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeletePortableIpRangeResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListPortableIpRangesParams struct {
p map[string]interface{}
}
func (p *ListPortableIpRangesParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["regionid"]; found {
vv := strconv.Itoa(v.(int))
u.Set("regionid", vv)
}
return u
}
func (p *ListPortableIpRangesParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListPortableIpRangesParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListPortableIpRangesParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListPortableIpRangesParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListPortableIpRangesParams) SetRegionid(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["regionid"] = v
return
}
// You should always use this function to get a new ListPortableIpRangesParams instance,
// as then you are sure you have configured all required params
func (s *PortableIPService) NewListPortableIpRangesParams() *ListPortableIpRangesParams {
p := &ListPortableIpRangesParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *PortableIPService) GetPortableIpRangeByID(id string, opts ...OptionFunc) (*PortableIpRange, int, error) {
p := &ListPortableIpRangesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
}
l, err := s.ListPortableIpRanges(p)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id)) {
return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
}
return nil, -1, err
}
if l.Count == 0 {
return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
}
if l.Count == 1 {
return l.PortableIpRanges[0], l.Count, nil
}
return nil, l.Count, fmt.Errorf("There is more then one result for PortableIpRange UUID: %s!", id)
}
// list portable IP ranges
func (s *PortableIPService) ListPortableIpRanges(p *ListPortableIpRangesParams) (*ListPortableIpRangesResponse, error) {
resp, err := s.cs.newRequest("listPortableIpRanges", p.toURLValues())
if err != nil {
return nil, err
}
var r ListPortableIpRangesResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListPortableIpRangesResponse struct {
Count int `json:"count"`
PortableIpRanges []*PortableIpRange `json:"portableiprange"`
}
type PortableIpRange struct {
Endip string `json:"endip,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Netmask string `json:"netmask,omitempty"`
Portableipaddress []struct {
Accountid string `json:"accountid,omitempty"`
Allocated string `json:"allocated,omitempty"`
Domainid string `json:"domainid,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Networkid string `json:"networkid,omitempty"`
Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
Regionid int `json:"regionid,omitempty"`
State string `json:"state,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
} `json:"portableipaddress,omitempty"`
Regionid int `json:"regionid,omitempty"`
Startip string `json:"startip,omitempty"`
Vlan string `json:"vlan,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,60 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
)
type QuotaIsEnabledParams struct {
p map[string]interface{}
}
func (p *QuotaIsEnabledParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
return u
}
// You should always use this function to get a new QuotaIsEnabledParams instance,
// as then you are sure you have configured all required params
func (s *QuotaService) NewQuotaIsEnabledParams() *QuotaIsEnabledParams {
p := &QuotaIsEnabledParams{}
p.p = make(map[string]interface{})
return p
}
// Return true if the plugin is enabled
func (s *QuotaService) QuotaIsEnabled(p *QuotaIsEnabledParams) (*QuotaIsEnabledResponse, error) {
resp, err := s.cs.newRequest("quotaIsEnabled", p.toURLValues())
if err != nil {
return nil, err
}
var r QuotaIsEnabledResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type QuotaIsEnabledResponse struct {
Isenabled bool `json:"isenabled,omitempty"`
}

View File

@@ -1,336 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type AddRegionParams struct {
p map[string]interface{}
}
func (p *AddRegionParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["endpoint"]; found {
u.Set("endpoint", v.(string))
}
if v, found := p.p["id"]; found {
vv := strconv.Itoa(v.(int))
u.Set("id", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
return u
}
func (p *AddRegionParams) SetEndpoint(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endpoint"] = v
return
}
func (p *AddRegionParams) SetId(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *AddRegionParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
// You should always use this function to get a new AddRegionParams instance,
// as then you are sure you have configured all required params
func (s *RegionService) NewAddRegionParams(endpoint string, id int, name string) *AddRegionParams {
p := &AddRegionParams{}
p.p = make(map[string]interface{})
p.p["endpoint"] = endpoint
p.p["id"] = id
p.p["name"] = name
return p
}
// Adds a Region
func (s *RegionService) AddRegion(p *AddRegionParams) (*AddRegionResponse, error) {
resp, err := s.cs.newRequest("addRegion", p.toURLValues())
if err != nil {
return nil, err
}
var r AddRegionResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type AddRegionResponse struct {
Endpoint string `json:"endpoint,omitempty"`
Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
}
type UpdateRegionParams struct {
p map[string]interface{}
}
func (p *UpdateRegionParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["endpoint"]; found {
u.Set("endpoint", v.(string))
}
if v, found := p.p["id"]; found {
vv := strconv.Itoa(v.(int))
u.Set("id", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
return u
}
func (p *UpdateRegionParams) SetEndpoint(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["endpoint"] = v
return
}
func (p *UpdateRegionParams) SetId(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *UpdateRegionParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
// You should always use this function to get a new UpdateRegionParams instance,
// as then you are sure you have configured all required params
func (s *RegionService) NewUpdateRegionParams(id int) *UpdateRegionParams {
p := &UpdateRegionParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Updates a region
func (s *RegionService) UpdateRegion(p *UpdateRegionParams) (*UpdateRegionResponse, error) {
resp, err := s.cs.newRequest("updateRegion", p.toURLValues())
if err != nil {
return nil, err
}
var r UpdateRegionResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type UpdateRegionResponse struct {
Endpoint string `json:"endpoint,omitempty"`
Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
}
type RemoveRegionParams struct {
p map[string]interface{}
}
func (p *RemoveRegionParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
vv := strconv.Itoa(v.(int))
u.Set("id", vv)
}
return u
}
func (p *RemoveRegionParams) SetId(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new RemoveRegionParams instance,
// as then you are sure you have configured all required params
func (s *RegionService) NewRemoveRegionParams(id int) *RemoveRegionParams {
p := &RemoveRegionParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Removes specified region
func (s *RegionService) RemoveRegion(p *RemoveRegionParams) (*RemoveRegionResponse, error) {
resp, err := s.cs.newRequest("removeRegion", p.toURLValues())
if err != nil {
return nil, err
}
var r RemoveRegionResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type RemoveRegionResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type ListRegionsParams struct {
p map[string]interface{}
}
func (p *ListRegionsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
vv := strconv.Itoa(v.(int))
u.Set("id", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListRegionsParams) SetId(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListRegionsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListRegionsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListRegionsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListRegionsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListRegionsParams instance,
// as then you are sure you have configured all required params
func (s *RegionService) NewListRegionsParams() *ListRegionsParams {
p := &ListRegionsParams{}
p.p = make(map[string]interface{})
return p
}
// Lists Regions
func (s *RegionService) ListRegions(p *ListRegionsParams) (*ListRegionsResponse, error) {
resp, err := s.cs.newRequest("listRegions", p.toURLValues())
if err != nil {
return nil, err
}
var r ListRegionsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListRegionsResponse struct {
Count int `json:"count"`
Regions []*Region `json:"region"`
}
type Region struct {
Endpoint string `json:"endpoint,omitempty"`
Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
}

View File

@@ -1,423 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
type AddResourceDetailParams struct {
p map[string]interface{}
}
func (p *AddResourceDetailParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["details"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("details[%d].key", i), k)
u.Set(fmt.Sprintf("details[%d].value", i), vv)
i++
}
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["resourceid"]; found {
u.Set("resourceid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
return u
}
func (p *AddResourceDetailParams) SetDetails(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["details"] = v
return
}
func (p *AddResourceDetailParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *AddResourceDetailParams) SetResourceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceid"] = v
return
}
func (p *AddResourceDetailParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
// You should always use this function to get a new AddResourceDetailParams instance,
// as then you are sure you have configured all required params
func (s *ResourcemetadataService) NewAddResourceDetailParams(details map[string]string, resourceid string, resourcetype string) *AddResourceDetailParams {
p := &AddResourceDetailParams{}
p.p = make(map[string]interface{})
p.p["details"] = details
p.p["resourceid"] = resourceid
p.p["resourcetype"] = resourcetype
return p
}
// Adds detail for the Resource.
func (s *ResourcemetadataService) AddResourceDetail(p *AddResourceDetailParams) (*AddResourceDetailResponse, error) {
resp, err := s.cs.newRequest("addResourceDetail", p.toURLValues())
if err != nil {
return nil, err
}
var r AddResourceDetailResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type AddResourceDetailResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type RemoveResourceDetailParams struct {
p map[string]interface{}
}
func (p *RemoveResourceDetailParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["key"]; found {
u.Set("key", v.(string))
}
if v, found := p.p["resourceid"]; found {
u.Set("resourceid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
return u
}
func (p *RemoveResourceDetailParams) SetKey(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["key"] = v
return
}
func (p *RemoveResourceDetailParams) SetResourceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceid"] = v
return
}
func (p *RemoveResourceDetailParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
// You should always use this function to get a new RemoveResourceDetailParams instance,
// as then you are sure you have configured all required params
func (s *ResourcemetadataService) NewRemoveResourceDetailParams(resourceid string, resourcetype string) *RemoveResourceDetailParams {
p := &RemoveResourceDetailParams{}
p.p = make(map[string]interface{})
p.p["resourceid"] = resourceid
p.p["resourcetype"] = resourcetype
return p
}
// Removes detail for the Resource.
func (s *ResourcemetadataService) RemoveResourceDetail(p *RemoveResourceDetailParams) (*RemoveResourceDetailResponse, error) {
resp, err := s.cs.newRequest("removeResourceDetail", p.toURLValues())
if err != nil {
return nil, err
}
var r RemoveResourceDetailResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type RemoveResourceDetailResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListResourceDetailsParams struct {
p map[string]interface{}
}
func (p *ListResourceDetailsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["fordisplay"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("fordisplay", vv)
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["key"]; found {
u.Set("key", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["resourceid"]; found {
u.Set("resourceid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
if v, found := p.p["value"]; found {
u.Set("value", v.(string))
}
return u
}
func (p *ListResourceDetailsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListResourceDetailsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListResourceDetailsParams) SetFordisplay(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fordisplay"] = v
return
}
func (p *ListResourceDetailsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListResourceDetailsParams) SetKey(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["key"] = v
return
}
func (p *ListResourceDetailsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListResourceDetailsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListResourceDetailsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListResourceDetailsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListResourceDetailsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListResourceDetailsParams) SetResourceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceid"] = v
return
}
func (p *ListResourceDetailsParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
func (p *ListResourceDetailsParams) SetValue(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["value"] = v
return
}
// You should always use this function to get a new ListResourceDetailsParams instance,
// as then you are sure you have configured all required params
func (s *ResourcemetadataService) NewListResourceDetailsParams(resourcetype string) *ListResourceDetailsParams {
p := &ListResourceDetailsParams{}
p.p = make(map[string]interface{})
p.p["resourcetype"] = resourcetype
return p
}
// List resource detail(s)
func (s *ResourcemetadataService) ListResourceDetails(p *ListResourceDetailsParams) (*ListResourceDetailsResponse, error) {
resp, err := s.cs.newRequest("listResourceDetails", p.toURLValues())
if err != nil {
return nil, err
}
var r ListResourceDetailsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListResourceDetailsResponse struct {
Count int `json:"count"`
ResourceDetails []*ResourceDetail `json:"resourcedetail"`
}
type ResourceDetail struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
}

View File

@@ -1,544 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type ListStorageTagsParams struct {
p map[string]interface{}
}
func (p *ListStorageTagsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
return u
}
func (p *ListStorageTagsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListStorageTagsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListStorageTagsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
// You should always use this function to get a new ListStorageTagsParams instance,
// as then you are sure you have configured all required params
func (s *ResourcetagsService) NewListStorageTagsParams() *ListStorageTagsParams {
p := &ListStorageTagsParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *ResourcetagsService) GetStorageTagID(keyword string, opts ...OptionFunc) (string, int, error) {
p := &ListStorageTagsParams{}
p.p = make(map[string]interface{})
p.p["keyword"] = keyword
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
}
l, err := s.ListStorageTags(p)
if err != nil {
return "", -1, err
}
if l.Count == 0 {
return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
}
if l.Count == 1 {
return l.StorageTags[0].Id, l.Count, nil
}
if l.Count > 1 {
for _, v := range l.StorageTags {
if v.Name == keyword {
return v.Id, l.Count, nil
}
}
}
return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
}
// Lists storage tags
func (s *ResourcetagsService) ListStorageTags(p *ListStorageTagsParams) (*ListStorageTagsResponse, error) {
resp, err := s.cs.newRequest("listStorageTags", p.toURLValues())
if err != nil {
return nil, err
}
var r ListStorageTagsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListStorageTagsResponse struct {
Count int `json:"count"`
StorageTags []*StorageTag `json:"storagetag"`
}
type StorageTag struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Poolid int64 `json:"poolid,omitempty"`
}
type CreateTagsParams struct {
p map[string]interface{}
}
func (p *CreateTagsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["customer"]; found {
u.Set("customer", v.(string))
}
if v, found := p.p["resourceids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("resourceids", vv)
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
if v, found := p.p["tags"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("tags[%d].key", i), k)
u.Set(fmt.Sprintf("tags[%d].value", i), vv)
i++
}
}
return u
}
func (p *CreateTagsParams) SetCustomer(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["customer"] = v
return
}
func (p *CreateTagsParams) SetResourceids(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceids"] = v
return
}
func (p *CreateTagsParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
func (p *CreateTagsParams) SetTags(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
// You should always use this function to get a new CreateTagsParams instance,
// as then you are sure you have configured all required params
func (s *ResourcetagsService) NewCreateTagsParams(resourceids []string, resourcetype string, tags map[string]string) *CreateTagsParams {
p := &CreateTagsParams{}
p.p = make(map[string]interface{})
p.p["resourceids"] = resourceids
p.p["resourcetype"] = resourcetype
p.p["tags"] = tags
return p
}
// Creates resource tag(s)
func (s *ResourcetagsService) CreateTags(p *CreateTagsParams) (*CreateTagsResponse, error) {
resp, err := s.cs.newRequest("createTags", p.toURLValues())
if err != nil {
return nil, err
}
var r CreateTagsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type CreateTagsResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type DeleteTagsParams struct {
p map[string]interface{}
}
func (p *DeleteTagsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["resourceids"]; found {
vv := strings.Join(v.([]string), ",")
u.Set("resourceids", vv)
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
if v, found := p.p["tags"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("tags[%d].key", i), k)
u.Set(fmt.Sprintf("tags[%d].value", i), vv)
i++
}
}
return u
}
func (p *DeleteTagsParams) SetResourceids(v []string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceids"] = v
return
}
func (p *DeleteTagsParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
func (p *DeleteTagsParams) SetTags(v map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["tags"] = v
return
}
// You should always use this function to get a new DeleteTagsParams instance,
// as then you are sure you have configured all required params
func (s *ResourcetagsService) NewDeleteTagsParams(resourceids []string, resourcetype string) *DeleteTagsParams {
p := &DeleteTagsParams{}
p.p = make(map[string]interface{})
p.p["resourceids"] = resourceids
p.p["resourcetype"] = resourcetype
return p
}
// Deleting resource tag(s)
func (s *ResourcetagsService) DeleteTags(p *DeleteTagsParams) (*DeleteTagsResponse, error) {
resp, err := s.cs.newRequest("deleteTags", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteTagsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type DeleteTagsResponse struct {
JobID string `json:"jobid,omitempty"`
Displaytext string `json:"displaytext,omitempty"`
Success bool `json:"success,omitempty"`
}
type ListTagsParams struct {
p map[string]interface{}
}
func (p *ListTagsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["customer"]; found {
u.Set("customer", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["key"]; found {
u.Set("key", v.(string))
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["resourceid"]; found {
u.Set("resourceid", v.(string))
}
if v, found := p.p["resourcetype"]; found {
u.Set("resourcetype", v.(string))
}
if v, found := p.p["value"]; found {
u.Set("value", v.(string))
}
return u
}
func (p *ListTagsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListTagsParams) SetCustomer(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["customer"] = v
return
}
func (p *ListTagsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListTagsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListTagsParams) SetKey(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["key"] = v
return
}
func (p *ListTagsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListTagsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListTagsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListTagsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListTagsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListTagsParams) SetResourceid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourceid"] = v
return
}
func (p *ListTagsParams) SetResourcetype(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["resourcetype"] = v
return
}
func (p *ListTagsParams) SetValue(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["value"] = v
return
}
// You should always use this function to get a new ListTagsParams instance,
// as then you are sure you have configured all required params
func (s *ResourcetagsService) NewListTagsParams() *ListTagsParams {
p := &ListTagsParams{}
p.p = make(map[string]interface{})
return p
}
// List resource tag(s)
func (s *ResourcetagsService) ListTags(p *ListTagsParams) (*ListTagsResponse, error) {
resp, err := s.cs.newRequest("listTags", p.toURLValues())
if err != nil {
return nil, err
}
var r ListTagsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListTagsResponse struct {
Count int `json:"count"`
Tags []*Tag `json:"tag"`
}
type Tag struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,746 +0,0 @@
//
// Copyright 2016, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"net/url"
"strconv"
)
type ResetSSHKeyForVirtualMachineParams struct {
p map[string]interface{}
}
func (p *ResetSSHKeyForVirtualMachineParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["keypair"]; found {
u.Set("keypair", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
return u
}
func (p *ResetSSHKeyForVirtualMachineParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ResetSSHKeyForVirtualMachineParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ResetSSHKeyForVirtualMachineParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ResetSSHKeyForVirtualMachineParams) SetKeypair(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keypair"] = v
return
}
func (p *ResetSSHKeyForVirtualMachineParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
// You should always use this function to get a new ResetSSHKeyForVirtualMachineParams instance,
// as then you are sure you have configured all required params
func (s *SSHService) NewResetSSHKeyForVirtualMachineParams(id string, keypair string) *ResetSSHKeyForVirtualMachineParams {
p := &ResetSSHKeyForVirtualMachineParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
p.p["keypair"] = keypair
return p
}
// Resets the SSH Key for virtual machine. The virtual machine must be in a "Stopped" state. [async]
func (s *SSHService) ResetSSHKeyForVirtualMachine(p *ResetSSHKeyForVirtualMachineParams) (*ResetSSHKeyForVirtualMachineResponse, error) {
resp, err := s.cs.newRequest("resetSSHKeyForVirtualMachine", p.toURLValues())
if err != nil {
return nil, err
}
var r ResetSSHKeyForVirtualMachineResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
b, err = getRawValue(b)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
}
return &r, nil
}
type ResetSSHKeyForVirtualMachineResponse struct {
JobID string `json:"jobid,omitempty"`
Account string `json:"account,omitempty"`
Affinitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Type string `json:"type,omitempty"`
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
} `json:"affinitygroup,omitempty"`
Cpunumber int `json:"cpunumber,omitempty"`
Cpuspeed int `json:"cpuspeed,omitempty"`
Cpuused string `json:"cpuused,omitempty"`
Created string `json:"created,omitempty"`
Details map[string]string `json:"details,omitempty"`
Diskioread int64 `json:"diskioread,omitempty"`
Diskiowrite int64 `json:"diskiowrite,omitempty"`
Diskkbsread int64 `json:"diskkbsread,omitempty"`
Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
Diskofferingid string `json:"diskofferingid,omitempty"`
Diskofferingname string `json:"diskofferingname,omitempty"`
Displayname string `json:"displayname,omitempty"`
Displayvm bool `json:"displayvm,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
Group string `json:"group,omitempty"`
Groupid string `json:"groupid,omitempty"`
Guestosid string `json:"guestosid,omitempty"`
Haenable bool `json:"haenable,omitempty"`
Hostid string `json:"hostid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Hypervisor string `json:"hypervisor,omitempty"`
Id string `json:"id,omitempty"`
Instancename string `json:"instancename,omitempty"`
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
Isodisplaytext string `json:"isodisplaytext,omitempty"`
Isoid string `json:"isoid,omitempty"`
Isoname string `json:"isoname,omitempty"`
Keypair string `json:"keypair,omitempty"`
Memory int `json:"memory,omitempty"`
Name string `json:"name,omitempty"`
Networkkbsread int64 `json:"networkkbsread,omitempty"`
Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
Nic []struct {
Broadcasturi string `json:"broadcasturi,omitempty"`
Deviceid string `json:"deviceid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Netmask string `json:"netmask,omitempty"`
Networkid string `json:"networkid,omitempty"`
Networkname string `json:"networkname,omitempty"`
Secondaryip []struct {
Id string `json:"id,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
} `json:"secondaryip,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Type string `json:"type,omitempty"`
Virtualmachineid string `json:"virtualmachineid,omitempty"`
} `json:"nic,omitempty"`
Ostypeid int64 `json:"ostypeid,omitempty"`
Password string `json:"password,omitempty"`
Passwordenabled bool `json:"passwordenabled,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Publicip string `json:"publicip,omitempty"`
Publicipid string `json:"publicipid,omitempty"`
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
Rootdevicetype string `json:"rootdevicetype,omitempty"`
Securitygroup []struct {
Account string `json:"account,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Egressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"egressrule,omitempty"`
Id string `json:"id,omitempty"`
Ingressrule []struct {
Account string `json:"account,omitempty"`
Cidr string `json:"cidr,omitempty"`
Endport int `json:"endport,omitempty"`
Icmpcode int `json:"icmpcode,omitempty"`
Icmptype int `json:"icmptype,omitempty"`
Protocol string `json:"protocol,omitempty"`
Ruleid string `json:"ruleid,omitempty"`
Securitygroupname string `json:"securitygroupname,omitempty"`
Startport int `json:"startport,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
} `json:"ingressrule,omitempty"`
Name string `json:"name,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Virtualmachinecount int `json:"virtualmachinecount,omitempty"`
Virtualmachineids []string `json:"virtualmachineids,omitempty"`
} `json:"securitygroup,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Servicestate string `json:"servicestate,omitempty"`
State string `json:"state,omitempty"`
Tags []struct {
Account string `json:"account,omitempty"`
Customer string `json:"customer,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Key string `json:"key,omitempty"`
Project string `json:"project,omitempty"`
Projectid string `json:"projectid,omitempty"`
Resourceid string `json:"resourceid,omitempty"`
Resourcetype string `json:"resourcetype,omitempty"`
Value string `json:"value,omitempty"`
} `json:"tags,omitempty"`
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
Templateid string `json:"templateid,omitempty"`
Templatename string `json:"templatename,omitempty"`
Userid string `json:"userid,omitempty"`
Username string `json:"username,omitempty"`
Vgpu string `json:"vgpu,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type RegisterSSHKeyPairParams struct {
p map[string]interface{}
}
func (p *RegisterSSHKeyPairParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["publickey"]; found {
u.Set("publickey", v.(string))
}
return u
}
func (p *RegisterSSHKeyPairParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *RegisterSSHKeyPairParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *RegisterSSHKeyPairParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *RegisterSSHKeyPairParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *RegisterSSHKeyPairParams) SetPublickey(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["publickey"] = v
return
}
// You should always use this function to get a new RegisterSSHKeyPairParams instance,
// as then you are sure you have configured all required params
func (s *SSHService) NewRegisterSSHKeyPairParams(name string, publickey string) *RegisterSSHKeyPairParams {
p := &RegisterSSHKeyPairParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
p.p["publickey"] = publickey
return p
}
// Register a public key in a keypair under a certain name
func (s *SSHService) RegisterSSHKeyPair(p *RegisterSSHKeyPairParams) (*RegisterSSHKeyPairResponse, error) {
resp, err := s.cs.newRequest("registerSSHKeyPair", p.toURLValues())
if err != nil {
return nil, err
}
if resp, err = getRawValue(resp); err != nil {
return nil, err
}
var r RegisterSSHKeyPairResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type RegisterSSHKeyPairResponse struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
Name string `json:"name,omitempty"`
}
type CreateSSHKeyPairParams struct {
p map[string]interface{}
}
func (p *CreateSSHKeyPairParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
return u
}
func (p *CreateSSHKeyPairParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *CreateSSHKeyPairParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *CreateSSHKeyPairParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *CreateSSHKeyPairParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
// You should always use this function to get a new CreateSSHKeyPairParams instance,
// as then you are sure you have configured all required params
func (s *SSHService) NewCreateSSHKeyPairParams(name string) *CreateSSHKeyPairParams {
p := &CreateSSHKeyPairParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
return p
}
// Create a new keypair and returns the private key
func (s *SSHService) CreateSSHKeyPair(p *CreateSSHKeyPairParams) (*CreateSSHKeyPairResponse, error) {
resp, err := s.cs.newRequest("createSSHKeyPair", p.toURLValues())
if err != nil {
return nil, err
}
if resp, err = getRawValue(resp); err != nil {
return nil, err
}
var r CreateSSHKeyPairResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type CreateSSHKeyPairResponse struct {
Privatekey string `json:"privatekey,omitempty"`
}
type DeleteSSHKeyPairParams struct {
p map[string]interface{}
}
func (p *DeleteSSHKeyPairParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
return u
}
func (p *DeleteSSHKeyPairParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *DeleteSSHKeyPairParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *DeleteSSHKeyPairParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *DeleteSSHKeyPairParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
// You should always use this function to get a new DeleteSSHKeyPairParams instance,
// as then you are sure you have configured all required params
func (s *SSHService) NewDeleteSSHKeyPairParams(name string) *DeleteSSHKeyPairParams {
p := &DeleteSSHKeyPairParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
return p
}
// Deletes a keypair by name
func (s *SSHService) DeleteSSHKeyPair(p *DeleteSSHKeyPairParams) (*DeleteSSHKeyPairResponse, error) {
resp, err := s.cs.newRequest("deleteSSHKeyPair", p.toURLValues())
if err != nil {
return nil, err
}
var r DeleteSSHKeyPairResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type DeleteSSHKeyPairResponse struct {
Displaytext string `json:"displaytext,omitempty"`
Success string `json:"success,omitempty"`
}
type ListSSHKeyPairsParams struct {
p map[string]interface{}
}
func (p *ListSSHKeyPairsParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["fingerprint"]; found {
u.Set("fingerprint", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
return u
}
func (p *ListSSHKeyPairsParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListSSHKeyPairsParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListSSHKeyPairsParams) SetFingerprint(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["fingerprint"] = v
return
}
func (p *ListSSHKeyPairsParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListSSHKeyPairsParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListSSHKeyPairsParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListSSHKeyPairsParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListSSHKeyPairsParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListSSHKeyPairsParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListSSHKeyPairsParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
// You should always use this function to get a new ListSSHKeyPairsParams instance,
// as then you are sure you have configured all required params
func (s *SSHService) NewListSSHKeyPairsParams() *ListSSHKeyPairsParams {
p := &ListSSHKeyPairsParams{}
p.p = make(map[string]interface{})
return p
}
// List registered keypairs
func (s *SSHService) ListSSHKeyPairs(p *ListSSHKeyPairsParams) (*ListSSHKeyPairsResponse, error) {
resp, err := s.cs.newRequest("listSSHKeyPairs", p.toURLValues())
if err != nil {
return nil, err
}
var r ListSSHKeyPairsResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListSSHKeyPairsResponse struct {
Count int `json:"count"`
SSHKeyPairs []*SSHKeyPair `json:"sshkeypair"`
}
type SSHKeyPair struct {
Account string `json:"account,omitempty"`
Domain string `json:"domain,omitempty"`
Domainid string `json:"domainid,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
Name string `json:"name,omitempty"`
}

Some files were not shown because too many files have changed in this diff Show More