Update github.com/xenolf/lego to 0.4.1
This commit is contained in:
parent
5042c5bf40
commit
e8d63b2a3b
105 changed files with 4299 additions and 2075 deletions
201
vendor/github.com/exoscale/egoscale/LICENSE
generated
vendored
Normal file
201
vendor/github.com/exoscale/egoscale/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
|||
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 2014 exoscale(tm)
|
||||
|
||||
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.
|
42
vendor/github.com/exoscale/egoscale/affinitygroup.go
generated
vendored
Normal file
42
vendor/github.com/exoscale/egoscale/affinitygroup.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateAffinityGroup(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
params.Set("type", "host anti-affinity")
|
||||
|
||||
resp, err := exo.Request("createAffinityGroup", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r CreateAffinityGroupResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobId, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteAffinityGroup(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteAffinityGroup", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DeleteAffinityGroupResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobId, nil
|
||||
|
||||
}
|
36
vendor/github.com/exoscale/egoscale/async.go
generated
vendored
Normal file
36
vendor/github.com/exoscale/egoscale/async.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) PollAsyncJob(jobid string) (*QueryAsyncJobResultResponse, error) {
|
||||
params := url.Values{}
|
||||
|
||||
params.Set("jobid", jobid)
|
||||
|
||||
resp, err := exo.Request("queryAsyncJobResult", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r QueryAsyncJobResultResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) AsyncToVirtualMachine(resp QueryAsyncJobResultResponse) (*DeployVirtualMachineResponse, error) {
|
||||
var r DeployVirtualMachineWrappedResponse
|
||||
|
||||
if err := json.Unmarshal(resp.Jobresult, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
153
vendor/github.com/exoscale/egoscale/dns.go
generated
vendored
Normal file
153
vendor/github.com/exoscale/egoscale/dns.go
generated
vendored
Normal file
|
@ -0,0 +1,153 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateDomain(name string) (*DNSDomain, error) {
|
||||
var hdr = make(http.Header)
|
||||
var domain DNSDomainCreateRequest
|
||||
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
domain.Domain.Name = name
|
||||
m, err := json.Marshal(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains", string(m), "POST", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var d *DNSDomain
|
||||
if err := json.Unmarshal(resp, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetDomain(name string) (*DNSDomain, error) {
|
||||
var hdr = make(http.Header)
|
||||
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/"+name, "", "GET", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var d *DNSDomain
|
||||
if err := json.Unmarshal(resp, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteDomain(name string) error {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
_, err := exo.DetailedRequest("/v1/domains/"+name, "", "DELETE", hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetRecords(name string) ([]*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/"+name+"/records", "", "GET", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r []*DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) CreateRecord(name string, rec DNSRecord) (*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
var rr DNSRecordResponse
|
||||
rr.Record = rec
|
||||
|
||||
body, err := json.Marshal(rr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/"+name+"/records", string(body), "POST", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r *DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) UpdateRecord(name string, rec DNSRecord) (*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
id := strconv.FormatInt(rec.Id, 10)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
var rr DNSRecordResponse
|
||||
rr.Record = rec
|
||||
|
||||
body, err := json.Marshal(rr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/"+name+"/records/"+id,
|
||||
string(body), "PUT", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r *DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteRecord(name string, rec DNSRecord) error {
|
||||
var hdr = make(http.Header)
|
||||
id := strconv.FormatInt(rec.Id, 10)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey+":"+exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
_, err := exo.DetailedRequest("/v1/domains/"+name+"/records/"+id,
|
||||
"", "DELETE", hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
9
vendor/github.com/exoscale/egoscale/error.go
generated
vendored
Normal file
9
vendor/github.com/exoscale/egoscale/error.go
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (e *Error) Error() error {
|
||||
return fmt.Errorf("exoscale API error %d (internal code: %d): %s", e.ErrorCode, e.CSErrorCode, e.ErrorText)
|
||||
}
|
144
vendor/github.com/exoscale/egoscale/groups.go
generated
vendored
Normal file
144
vendor/github.com/exoscale/egoscale/groups.go
generated
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateEgressRule(rule SecurityGroupRule) (*AuthorizeSecurityGroupEgressResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
|
||||
if rule.Cidr != "" {
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
} else if len(rule.UserSecurityGroupList) > 0 {
|
||||
usg, err := json.Marshal(rule.UserSecurityGroupList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("usersecuritygrouplist", string(usg))
|
||||
} else {
|
||||
return nil, fmt.Errorf("No Egress rule CIDR or Security Group List provided")
|
||||
}
|
||||
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Protocol == "ICMP" {
|
||||
params.Set("icmpcode", fmt.Sprintf("%d", rule.IcmpCode))
|
||||
params.Set("icmptype", fmt.Sprintf("%d", rule.IcmpType))
|
||||
} else if rule.Protocol == "TCP" || rule.Protocol == "UDP" {
|
||||
params.Set("startport", fmt.Sprintf("%d", rule.Port))
|
||||
params.Set("endport", fmt.Sprintf("%d", rule.Port))
|
||||
} else {
|
||||
return nil, fmt.Errorf("Invalid Egress rule Protocol: %s", rule.Protocol)
|
||||
}
|
||||
|
||||
resp, err := exo.Request("authorizeSecurityGroupEgress", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r AuthorizeSecurityGroupEgressResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) CreateIngressRule(rule SecurityGroupRule) (*AuthorizeSecurityGroupIngressResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
|
||||
if rule.Cidr != "" {
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
} else if len(rule.UserSecurityGroupList) > 0 {
|
||||
for i := 0; i < len(rule.UserSecurityGroupList); i++ {
|
||||
params.Set(fmt.Sprintf("usersecuritygrouplist[%d].account", i), rule.UserSecurityGroupList[i].Account)
|
||||
params.Set(fmt.Sprintf("usersecuritygrouplist[%d].group", i), rule.UserSecurityGroupList[i].Group)
|
||||
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("No Ingress rule CIDR or Security Group List provided")
|
||||
}
|
||||
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Protocol == "ICMP" {
|
||||
params.Set("icmpcode", fmt.Sprintf("%d", rule.IcmpCode))
|
||||
params.Set("icmptype", fmt.Sprintf("%d", rule.IcmpType))
|
||||
} else if rule.Protocol == "TCP" || rule.Protocol == "UDP" {
|
||||
params.Set("startport", fmt.Sprintf("%d", rule.Port))
|
||||
params.Set("endport", fmt.Sprintf("%d", rule.Port))
|
||||
} else {
|
||||
return nil, fmt.Errorf("Invalid Egress rule Protocol: %s", rule.Protocol)
|
||||
}
|
||||
|
||||
fmt.Printf("## params: %+v\n", params)
|
||||
|
||||
resp, err := exo.Request("authorizeSecurityGroupIngress", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r AuthorizeSecurityGroupIngressResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) CreateSecurityGroupWithRules(name string, ingress []SecurityGroupRule, egress []SecurityGroupRule) (*CreateSecurityGroupResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("createSecurityGroup", params)
|
||||
|
||||
var r CreateSecurityGroupResponseWrapper
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sgid := r.Wrapped.Id
|
||||
|
||||
for _, erule := range egress {
|
||||
erule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateEgressRule(erule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, inrule := range ingress {
|
||||
inrule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateIngressRule(inrule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteSecurityGroup(name string) error {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteSecurityGroup", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("## response: %+v\n", resp)
|
||||
return nil
|
||||
}
|
21
vendor/github.com/exoscale/egoscale/init.go
generated
vendored
Normal file
21
vendor/github.com/exoscale/egoscale/init.go
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewClient(endpoint string, apiKey string, apiSecret string) *Client {
|
||||
cs := &Client{
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
|
||||
},
|
||||
},
|
||||
endpoint: endpoint,
|
||||
apiKey: apiKey,
|
||||
apiSecret: apiSecret,
|
||||
}
|
||||
return cs
|
||||
}
|
40
vendor/github.com/exoscale/egoscale/ip.go
generated
vendored
Normal file
40
vendor/github.com/exoscale/egoscale/ip.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) AddIpToNic(nic_id string, ip_address string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("nicid", nic_id)
|
||||
params.Set("ipaddress", ip_address)
|
||||
|
||||
resp, err := exo.Request("addIpToNic", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r AddIpToNicResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.Id, nil
|
||||
}
|
||||
|
||||
func (exo *Client) RemoveIpFromNic(nic_id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", nic_id)
|
||||
|
||||
resp, err := exo.Request("removeIpFromNic", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r RemoveIpFromNicResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return r.JobID, nil
|
||||
}
|
59
vendor/github.com/exoscale/egoscale/keypair.go
generated
vendored
Normal file
59
vendor/github.com/exoscale/egoscale/keypair.go
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateKeypair(name string) (*CreateSSHKeyPairResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("createSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r CreateSSHKeyPairWrappedResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteKeypair(name string) (*StandardResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r StandardResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
|
||||
}
|
||||
|
||||
func (exo *Client) RegisterKeypair(name string, key string) (*CreateSSHKeyPairResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
params.Set("publicKey", key)
|
||||
|
||||
resp, err := exo.Request("registerSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r CreateSSHKeyPairWrappedResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
133
vendor/github.com/exoscale/egoscale/request.go
generated
vendored
Normal file
133
vendor/github.com/exoscale/egoscale/request.go
generated
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func csQuotePlus(s string) string {
|
||||
return strings.Replace(s, "+", "%20", -1)
|
||||
}
|
||||
|
||||
func csEncode(s string) string {
|
||||
return csQuotePlus(url.QueryEscape(s))
|
||||
}
|
||||
|
||||
func rawValue(b json.RawMessage) (json.RawMessage, error) {
|
||||
var m map[string]json.RawMessage
|
||||
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range m {
|
||||
return v, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func rawValues(b json.RawMessage) (json.RawMessage, error) {
|
||||
var i []json.RawMessage
|
||||
|
||||
if err := json.Unmarshal(b, &i); err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return i[0], nil
|
||||
}
|
||||
|
||||
func (exo *Client) ParseResponse(resp *http.Response) (json.RawMessage, error) {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a, err := rawValues(b)
|
||||
|
||||
if a == nil {
|
||||
b, err = rawValue(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
var e Error
|
||||
if err := json.Unmarshal(b, &e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/* Need to account for differet error types */
|
||||
if e.ErrorCode != 0 {
|
||||
return nil, e.Error()
|
||||
} else {
|
||||
var de DNSError
|
||||
if err := json.Unmarshal(b, &de); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("Exoscale error (%d): %s", resp.StatusCode, strings.Join(de.Name, "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (exo *Client) Request(command string, params url.Values) (json.RawMessage, error) {
|
||||
|
||||
mac := hmac.New(sha1.New, []byte(exo.apiSecret))
|
||||
keys := make([]string, 0)
|
||||
unencoded := make([]string, 0)
|
||||
|
||||
params.Set("apikey", exo.apiKey)
|
||||
params.Set("command", command)
|
||||
params.Set("response", "json")
|
||||
|
||||
for k, _ := range params {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
arg := k + "=" + csEncode(params[k][0])
|
||||
unencoded = append(unencoded, arg)
|
||||
}
|
||||
sign_string := strings.ToLower(strings.Join(unencoded, "&"))
|
||||
|
||||
mac.Write([]byte(sign_string))
|
||||
signature := csEncode(base64.StdEncoding.EncodeToString(mac.Sum(nil)))
|
||||
query := params.Encode()
|
||||
url := exo.endpoint + "?" + csQuotePlus(query) + "&signature=" + signature
|
||||
|
||||
resp, err := exo.client.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
return exo.ParseResponse(resp)
|
||||
}
|
||||
|
||||
func (exo *Client) DetailedRequest(uri string, params string, method string, header http.Header) (json.RawMessage, error) {
|
||||
url := exo.endpoint + uri
|
||||
|
||||
req, err := http.NewRequest(method, url, strings.NewReader(params))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header = header
|
||||
|
||||
response, err := exo.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
return exo.ParseResponse(response)
|
||||
}
|
230
vendor/github.com/exoscale/egoscale/topology.go
generated
vendored
Normal file
230
vendor/github.com/exoscale/egoscale/topology.go
generated
vendored
Normal file
|
@ -0,0 +1,230 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (exo *Client) GetSecurityGroups() (map[string]SecurityGroup, error) {
|
||||
var sgs map[string]SecurityGroup
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listSecurityGroups", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListSecurityGroupsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sgs = make(map[string]SecurityGroup)
|
||||
for _, sg := range r.SecurityGroups {
|
||||
sgs[sg.Name] = *sg
|
||||
}
|
||||
return sgs, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetSecurityGroupId(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listSecurityGroups", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r ListSecurityGroupsResponse
|
||||
err = json.Unmarshal(resp, &r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, sg := range r.SecurityGroups {
|
||||
if sg.Name == name {
|
||||
return sg.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetZones() (map[string]string, error) {
|
||||
var zones map[string]string
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listZones", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListZonesResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
zones = make(map[string]string)
|
||||
for _, zone := range r.Zones {
|
||||
zones[zone.Name] = zone.Id
|
||||
}
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetProfiles() (map[string]string, error) {
|
||||
|
||||
var profiles map[string]string
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listServiceOfferings", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListServiceOfferingsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
profiles = make(map[string]string)
|
||||
for _, offering := range r.ServiceOfferings {
|
||||
profiles[strings.ToLower(offering.Name)] = offering.Id
|
||||
}
|
||||
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetKeypairs() ([]SSHKeyPair, error) {
|
||||
params := url.Values{}
|
||||
|
||||
resp, err := exo.Request("listSSHKeyPairs", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListSSHKeyPairsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var keypairs = make([]SSHKeyPair, r.Count, r.Count)
|
||||
for i, keypair := range r.SSHKeyPairs {
|
||||
keypairs[i] = *keypair
|
||||
}
|
||||
return keypairs, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetAffinityGroups() (map[string]string, error) {
|
||||
var affinitygroups map[string]string
|
||||
params := url.Values{}
|
||||
|
||||
resp, err := exo.Request("listAffinityGroups", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListAffinityGroupsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
affinitygroups = make(map[string]string)
|
||||
for _, affinitygroup := range r.AffinityGroups {
|
||||
affinitygroups[affinitygroup.Name] = affinitygroup.Id
|
||||
}
|
||||
return affinitygroups, nil
|
||||
|
||||
}
|
||||
|
||||
func (exo *Client) GetImages() (map[string]map[int]string, error) {
|
||||
var images map[string]map[int]string
|
||||
images = make(map[string]map[int]string)
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("templatefilter", "featured")
|
||||
|
||||
resp, err := exo.Request("listTemplates", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListTemplatesResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`^Linux (?P<name>.+?) (?P<version>[0-9.]+).*$`)
|
||||
for _, template := range r.Templates {
|
||||
size := int(template.Size / (1024 * 1024 * 1024))
|
||||
submatch := re.FindStringSubmatch(template.Name)
|
||||
if len(submatch) > 0 {
|
||||
name := strings.Replace(strings.ToLower(submatch[1]), " ", "-", -1)
|
||||
version := submatch[2]
|
||||
image := fmt.Sprintf("%s-%s", name, version)
|
||||
|
||||
_, present := images[image]
|
||||
if !present {
|
||||
images[image] = make(map[int]string)
|
||||
}
|
||||
images[image][size] = template.Id
|
||||
|
||||
images[fmt.Sprintf("%s-%s", name, version)][size] = template.Id
|
||||
}
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetTopology() (*Topology, error) {
|
||||
|
||||
zones, err := exo.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images, err := exo.GetImages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
securityGroups, err := exo.GetSecurityGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groups := make(map[string]string)
|
||||
for k, v := range securityGroups {
|
||||
groups[k] = v.Id
|
||||
}
|
||||
|
||||
keypairs, err := exo.GetKeypairs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/* Convert the ssh keypair to contain just the name */
|
||||
keynames := make([]string, len(keypairs))
|
||||
for i, k := range keypairs {
|
||||
keynames[i] = k.Name
|
||||
}
|
||||
|
||||
affinitygroups, err := exo.GetAffinityGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profiles, err := exo.GetProfiles()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
topo := &Topology{
|
||||
Zones: zones,
|
||||
Profiles: profiles,
|
||||
Images: images,
|
||||
Keypairs: keynames,
|
||||
AffinityGroups: affinitygroups,
|
||||
SecurityGroups: groups,
|
||||
}
|
||||
|
||||
return topo, nil
|
||||
}
|
530
vendor/github.com/exoscale/egoscale/types.go
generated
vendored
Normal file
530
vendor/github.com/exoscale/egoscale/types.go
generated
vendored
Normal file
|
@ -0,0 +1,530 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
endpoint string
|
||||
apiKey string
|
||||
apiSecret string
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
ErrorCode int `json:"errorcode"`
|
||||
CSErrorCode int `json:"cserrorcode"`
|
||||
ErrorText string `json:"errortext"`
|
||||
}
|
||||
|
||||
type StandardResponse struct {
|
||||
Success string `json:"success"`
|
||||
DisplayText string `json:"displaytext"`
|
||||
}
|
||||
|
||||
type Topology struct {
|
||||
Zones map[string]string
|
||||
Images map[string]map[int]string
|
||||
Profiles map[string]string
|
||||
Keypairs []string
|
||||
SecurityGroups map[string]string
|
||||
AffinityGroups map[string]string
|
||||
}
|
||||
|
||||
type SecurityGroupRule struct {
|
||||
Cidr string
|
||||
IcmpType int
|
||||
IcmpCode int
|
||||
Port int
|
||||
Protocol string
|
||||
SecurityGroupId string
|
||||
UserSecurityGroupList []UserSecurityGroup `json:"usersecuritygrouplist,omitempty"`
|
||||
}
|
||||
|
||||
type UserSecurityGroup struct {
|
||||
Group string `json:"group,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
||||
|
||||
type MachineProfile struct {
|
||||
Name string
|
||||
SecurityGroups []string
|
||||
Keypair string
|
||||
Userdata string
|
||||
ServiceOffering string
|
||||
Template string
|
||||
Zone string
|
||||
AffinityGroups []string
|
||||
}
|
||||
|
||||
type ListZonesResponse struct {
|
||||
Count int `json:"count"`
|
||||
Zones []*Zone `json:"zone"`
|
||||
}
|
||||
|
||||
type Zone struct {
|
||||
Allocationstate string `json:"allocationstate,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Domainname string `json:"domainname,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Internaldns1 string `json:"internaldns1,omitempty"`
|
||||
Internaldns2 string `json:"internaldns2,omitempty"`
|
||||
Ip6dns1 string `json:"ip6dns1,omitempty"`
|
||||
Ip6dns2 string `json:"ip6dns2,omitempty"`
|
||||
Localstorageenabled bool `json:"localstorageenabled,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networktype string `json:"networktype,omitempty"`
|
||||
Resourcedetails map[string]string `json:"resourcedetails,omitempty"`
|
||||
Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"`
|
||||
Vlan string `json:"vlan,omitempty"`
|
||||
Zonetoken string `json:"zonetoken,omitempty"`
|
||||
}
|
||||
|
||||
type ListServiceOfferingsResponse struct {
|
||||
Count int `json:"count"`
|
||||
ServiceOfferings []*ServiceOffering `json:"serviceoffering"`
|
||||
}
|
||||
|
||||
type ServiceOffering struct {
|
||||
Cpunumber int `json:"cpunumber,omitempty"`
|
||||
Cpuspeed int `json:"cpuspeed,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Hosttags string `json:"hosttags,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Iscustomized bool `json:"iscustomized,omitempty"`
|
||||
Issystem bool `json:"issystem,omitempty"`
|
||||
Isvolatile bool `json:"isvolatile,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networkrate int `json:"networkrate,omitempty"`
|
||||
Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
|
||||
}
|
||||
|
||||
type ListTemplatesResponse struct {
|
||||
Count int `json:"count"`
|
||||
Templates []*Template `json:"template"`
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Accountid string `json:"accountid,omitempty"`
|
||||
Bootable bool `json:"bootable,omitempty"`
|
||||
Checksum string `json:"checksum,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
CrossZones bool `json:"crossZones,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Hostid string `json:"hostid,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Hypervisor string `json:"hypervisor,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
|
||||
Isextractable bool `json:"isextractable,omitempty"`
|
||||
Isfeatured bool `json:"isfeatured,omitempty"`
|
||||
Ispublic bool `json:"ispublic,omitempty"`
|
||||
Isready bool `json:"isready,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Ostypeid string `json:"ostypeid,omitempty"`
|
||||
Ostypename string `json:"ostypename,omitempty"`
|
||||
Passwordenabled bool `json:"passwordenabled,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
Removed string `json:"removed,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
Sourcetemplateid string `json:"sourcetemplateid,omitempty"`
|
||||
Sshkeyenabled bool `json:"sshkeyenabled,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
type ListSSHKeyPairsResponse struct {
|
||||
Count int `json:"count"`
|
||||
SSHKeyPairs []*SSHKeyPair `json:"sshkeypair"`
|
||||
}
|
||||
|
||||
type SSHKeyPair struct {
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type ListAffinityGroupsResponse struct {
|
||||
Count int `json:"count"`
|
||||
AffinityGroups []*AffinityGroup `json:"affinitygroup"`
|
||||
}
|
||||
|
||||
type AffinityGroup struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAffinityGroupResponseWrapper struct {
|
||||
Wrapped AffinityGroup `json:"affinitygroup"`
|
||||
}
|
||||
|
||||
type ListSecurityGroupsResponse struct {
|
||||
Count int `json:"count"`
|
||||
SecurityGroups []*SecurityGroup `json:"securitygroup"`
|
||||
}
|
||||
|
||||
type SecurityGroup 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"`
|
||||
IngressRules []struct {
|
||||
RuleId string `json:"ruleid,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
StartPort int `json:"startport,omitempty"`
|
||||
EndPort int `json:"endport,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
IcmpCode int `json:"icmpcode,omitempty"`
|
||||
IcmpType int `json:"icmptype,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"ingressrule,omitempty"`
|
||||
EgressRules []struct {
|
||||
RuleId string `json:"ruleid,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
StartPort int `json:"startport,omitempty"`
|
||||
EndPort int `json:"endport,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
IcmpCode int `json:"icmpcode,omitempty"`
|
||||
IcmpType int `json:"icmptype,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"egressrule,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSecurityGroupResponseWrapper struct {
|
||||
Wrapped CreateSecurityGroupResponse `json:"securitygroup"`
|
||||
}
|
||||
type CreateSecurityGroupResponse 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 AuthorizeSecurityGroupIngressResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type AuthorizeSecurityGroupEgressResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type DeployVirtualMachineWrappedResponse struct {
|
||||
Wrapped DeployVirtualMachineResponse `json:"virtualmachine"`
|
||||
}
|
||||
|
||||
type DeployVirtualMachineResponse 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"`
|
||||
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"`
|
||||
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"`
|
||||
Gateway string `json:"gateway,omitempty"`
|
||||
Id string `json:"id,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 []string `json:"secondaryip,omitempty"`
|
||||
Traffictype string `json:"traffictype,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
} `json:"nic,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"`
|
||||
Serviceofferingid string `json:"serviceofferingid,omitempty"`
|
||||
Serviceofferingname string `json:"serviceofferingname,omitempty"`
|
||||
Servicestate string `json:"servicestate,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
|
||||
Templateid string `json:"templateid,omitempty"`
|
||||
Templatename string `json:"templatename,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
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 ListVirtualMachinesResponse struct {
|
||||
Count int `json:"count"`
|
||||
VirtualMachines []*VirtualMachine `json:"virtualmachine"`
|
||||
}
|
||||
|
||||
type VirtualMachine struct {
|
||||
Account string `json:"account,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"`
|
||||
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"`
|
||||
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"`
|
||||
} `json:"nic,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"`
|
||||
SecurityGroups []struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitemtpy"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"securitygroup,omitempty"`
|
||||
Serviceofferingid string `json:"serviceofferingid,omitempty"`
|
||||
Serviceofferingname string `json:"serviceofferingname,omitempty"`
|
||||
Servicestate string `json:"servicestate,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
|
||||
Templateid string `json:"templateid,omitempty"`
|
||||
Templatename string `json:"templatename,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
type StartVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type StopVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DestroyVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type RebootVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSSHKeyPairWrappedResponse struct {
|
||||
Wrapped CreateSSHKeyPairResponse `json:"keypair,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type RemoveIpFromNicResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type AddIpToNicResponse struct {
|
||||
Id string `json:"id"`
|
||||
IpAddress string `json:"ipaddress"`
|
||||
NetworkId string `json:"networkid"`
|
||||
NicId string `json:"nicid"`
|
||||
VmId string `json:"virtualmachineid"`
|
||||
}
|
||||
|
||||
type CreateAffinityGroupResponse struct {
|
||||
JobId string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DeleteAffinityGroupResponse struct {
|
||||
JobId string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DeleteSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type DNSDomain struct {
|
||||
Id int64 `json:"id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
RegistrantId int64 `json:"registrant_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
UnicodeName string `json:"unicode_name"`
|
||||
Token string `json:"token"`
|
||||
State string `json:"state"`
|
||||
Language string `json:"language,omitempty"`
|
||||
Lockable bool `json:"lockable"`
|
||||
AutoRenew bool `json:"auto_renew"`
|
||||
WhoisProtected bool `json:"whois_protected"`
|
||||
RecordCount int64 `json:"record_count"`
|
||||
ServiceCount int64 `json:"service_count"`
|
||||
ExpiresOn string `json:"expires_on,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
type DNSDomainCreateRequest struct {
|
||||
Domain struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"domain"`
|
||||
}
|
||||
|
||||
type DNSRecord struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
DomainId int64 `json:"domain_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Ttl int `json:"ttl,omitempty"`
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
Content string `json:"content"`
|
||||
RecordType string `json:"record_type"`
|
||||
Prio int `json:"prio,omitempty"`
|
||||
}
|
||||
|
||||
type DNSRecordResponse struct {
|
||||
Record DNSRecord `json:"record"`
|
||||
}
|
||||
|
||||
type DNSError struct {
|
||||
Name []string `json:"name"`
|
||||
}
|
159
vendor/github.com/exoscale/egoscale/vm.go
generated
vendored
Normal file
159
vendor/github.com/exoscale/egoscale/vm.go
generated
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateVirtualMachine(p MachineProfile) (string, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("serviceofferingid", p.ServiceOffering)
|
||||
params.Set("templateid", p.Template)
|
||||
params.Set("zoneid", p.Zone)
|
||||
|
||||
params.Set("displayname", p.Name)
|
||||
if len(p.Userdata) > 0 {
|
||||
params.Set("userdata", base64.StdEncoding.EncodeToString([]byte(p.Userdata)))
|
||||
}
|
||||
if len(p.Keypair) > 0 {
|
||||
params.Set("keypair", p.Keypair)
|
||||
}
|
||||
if len(p.AffinityGroups) > 0 {
|
||||
params.Set("affinitygroupnames", strings.Join(p.AffinityGroups, ","))
|
||||
}
|
||||
|
||||
params.Set("securitygroupids", strings.Join(p.SecurityGroups, ","))
|
||||
|
||||
resp, err := exo.Request("deployVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DeployVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) StartVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("startVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r StartVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) StopVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("stopVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r StopVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) RebootVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("rebootVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r RebootVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DestroyVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("destroyVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DestroyVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListVirtualMachinesResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(r.VirtualMachines) == 1 {
|
||||
machine := r.VirtualMachines[0]
|
||||
return machine, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("cannot retrieve virtualmachine with id %s", id)
|
||||
}
|
||||
}
|
||||
|
||||
func (exo *Client) ListVirtualMachines() ([]*VirtualMachine, error) {
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListVirtualMachinesResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.VirtualMachines, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue