Merge pull request #13585 from augabet/bump_govcloudair

bump govcloudair vendor
This commit is contained in:
Jake Champlin 2017-05-16 10:45:25 -04:00 committed by GitHub
commit 73dbded87e
7 changed files with 417 additions and 59 deletions

37
vendor/github.com/ukcloud/govcloudair/Makefile generated vendored Normal file
View File

@ -0,0 +1,37 @@
TEST?=./...
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
default: fmt test testrace vet
# test runs the test suite and vets the code
test: get-deps fmtcheck
@golint ./...
@echo "==> Running Tests"
@go list $(TEST) | xargs -n1 go test -timeout=60s -parallel=10 $(TESTARGS)
# testrace runs the race checker
testrace:
@go list $(TEST) | xargs -n1 go test -race $(TESTARGS)
# vet runs the Go source code static analysis tool `vet` to find
# any common errors.
vet:
@echo "==> Running Go Vet"
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
get-deps:
@echo "==> Fetching dependencies"
@go get -v $(TEST)
@go get -u github.com/golang/lint/golint
fmt:
gofmt -w $(GOFMT_FILES)
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

View File

@ -141,7 +141,7 @@ func (c *VCDClient) vcdauthorize(user, pass, org string) error {
func (c *VCDClient) RetrieveOrg(vcdname string) (Org, error) {
req := c.Client.NewRequest(map[string]string{}, "GET", c.OrgHREF, nil)
req.Header.Add("Accept", "vnd.vmware.vcloud.org+xml;version=5.5")
req.Header.Add("Accept", "application/*+xml;version=5.5")
// TODO: wrap into checkresp to parse error
resp, err := checkResp(c.Client.Http.Do(req))

View File

@ -115,6 +115,10 @@ func (e *EdgeGateway) AddDhcpPool(network *types.OrgVDCNetwork, dhcppool []inter
}
func (e *EdgeGateway) RemoveNATMapping(nattype, externalIP, internalIP, port string) (Task, error) {
return e.RemoveNATPortMapping(nattype, externalIP, port, internalIP, port)
}
func (e *EdgeGateway) RemoveNATPortMapping(nattype, externalIP, externalPort string, internalIP, internalPort string) (Task, error) {
// Find uplink interface
var uplink types.Reference
for _, gi := range e.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface {
@ -140,7 +144,7 @@ func (e *EdgeGateway) RemoveNATMapping(nattype, externalIP, internalIP, port str
// If matches, let's skip it and continue the loop
if v.RuleType == nattype &&
v.GatewayNatRule.OriginalIP == externalIP &&
v.GatewayNatRule.OriginalPort == port &&
v.GatewayNatRule.OriginalPort == externalPort &&
v.GatewayNatRule.Interface.HREF == uplink.HREF {
log.Printf("[DEBUG] REMOVING %s Rule: %#v", v.RuleType, v.GatewayNatRule)
continue
@ -190,6 +194,10 @@ func (e *EdgeGateway) RemoveNATMapping(nattype, externalIP, internalIP, port str
}
func (e *EdgeGateway) AddNATMapping(nattype, externalIP, internalIP, port string) (Task, error) {
return e.AddNATPortMapping(nattype, externalIP, port, internalIP, port)
}
func (e *EdgeGateway) AddNATPortMapping(nattype, externalIP, externalPort string, internalIP, internalPort string) (Task, error) {
// Find uplink interface
var uplink types.Reference
for _, gi := range e.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface {
@ -218,8 +226,9 @@ func (e *EdgeGateway) AddNATMapping(nattype, externalIP, internalIP, port string
// If matches, let's skip it and continue the loop
if v.RuleType == nattype &&
v.GatewayNatRule.OriginalIP == externalIP &&
v.GatewayNatRule.OriginalPort == port &&
v.GatewayNatRule.OriginalPort == externalPort &&
v.GatewayNatRule.TranslatedIP == internalIP &&
v.GatewayNatRule.TranslatedPort == internalPort &&
v.GatewayNatRule.Interface.HREF == uplink.HREF {
continue
}
@ -237,9 +246,9 @@ func (e *EdgeGateway) AddNATMapping(nattype, externalIP, internalIP, port string
HREF: uplink.HREF,
},
OriginalIP: externalIP,
OriginalPort: port,
OriginalPort: externalPort,
TranslatedIP: internalIP,
TranslatedPort: port,
TranslatedPort: internalPort,
Protocol: "tcp",
},
}
@ -623,3 +632,49 @@ func (e *EdgeGateway) Create1to1Mapping(internal, external, description string)
return *task, nil
}
func (e *EdgeGateway) AddIpsecVPN(ipsecVPNConfig *types.EdgeGatewayServiceConfiguration) (Task, error) {
err := e.Refresh()
if err != nil {
fmt.Printf("error: %v\n", err)
}
output, err := xml.MarshalIndent(ipsecVPNConfig, " ", " ")
if err != nil {
fmt.Errorf("error marshaling ipsecVPNConfig compose: %s", err)
}
debug := os.Getenv("GOVCLOUDAIR_DEBUG")
if debug == "true" {
fmt.Printf("\n\nXML DEBUG: %s\n\n", string(output))
}
b := bytes.NewBufferString(xml.Header + string(output))
log.Printf("[DEBUG] ipsecVPN configuration: %s", b)
s, _ := url.ParseRequestURI(e.EdgeGateway.HREF)
s.Path += "/action/configureServices"
fmt.Println(s)
req := e.c.NewRequest(map[string]string{}, "POST", *s, b)
req.Header.Add("Content-Type", "application/vnd.vmware.admin.edgeGatewayServiceConfiguration+xml")
resp, err := checkResp(e.c.Http.Do(req))
if err != nil {
return Task{}, fmt.Errorf("error reconfiguring Edge Gateway: %s", err)
}
task := NewTask(e.c)
if err = decodeBody(resp, task.Task); err != nil {
return Task{}, fmt.Errorf("error decoding Task response: %s", err)
}
// The request was successful
return *task, nil
}

View File

@ -687,6 +687,29 @@ type ComposeVAppParams struct {
AllEULAsAccepted bool `xml:"AllEULAsAccepted,omitempty"` // True confirms acceptance of all EULAs in a vApp template. Instantiation fails if this element is missing, empty, or set to false and one or more EulaSection elements are present.
}
type ReComposeVAppParams struct {
XMLName xml.Name `xml:"RecomposeVAppParams"`
Ovf string `xml:"xmlns:ovf,attr"`
Xsi string `xml:"xmlns:xsi,attr"`
Xmlns string `xml:"xmlns,attr"`
// Attributes
Name string `xml:"name,attr,omitempty"` // Typically used to name or identify the subject of the request. For example, the name of the object being created or modified.
Deploy bool `xml:"deploy,attr"` // True if the vApp should be deployed at instantiation. Defaults to true.
PowerOn bool `xml:"powerOn,attr"` // True if the vApp should be powered-on at instantiation. Defaults to true.
LinkedClone bool `xml:"linkedClone,attr,omitempty"` // Reserved. Unimplemented.
// Elements
Description string `xml:"Description,omitempty"` // Optional description.
VAppParent *Reference `xml:"VAppParent,omitempty"` // Reserved. Unimplemented.
InstantiationParams *InstantiationParams `xml:"InstantiationParams,omitempty"` // Instantiation parameters for the composed vApp.
SourcedItem *SourcedCompositionItemParam `xml:"SourcedItem,omitempty"` // Composition item. One of: vApp vAppTemplate Vm.
AllEULAsAccepted bool `xml:"AllEULAsAccepted,omitempty"`
DeleteItem *DeleteItem `xml:"DeleteItem,omitempty"`
}
type DeleteItem struct {
HREF string `xml:"href,attr,omitempty"`
}
// SourcedCompositionItemParam represents a vApp, vApp template or Vm to include in a composed vApp.
// Type: SourcedCompositionItemParamType
// Namespace: http://www.vmware.com/vcloud/v1.5
@ -1164,6 +1187,7 @@ type EdgeGatewayServiceConfiguration struct {
GatewayDhcpService *GatewayDhcpService `xml:"GatewayDhcpService,omitempty"`
FirewallService *FirewallService `xml:"FirewallService,omitempty"`
NatService *NatService `xml:"NatService,omitempty"`
GatewayIpsecVpnService *GatewayIpsecVpnService `xml:"GatewayIpsecVpnService,omitempty"` // Substitute for NetworkService. Gateway Ipsec VPN service settings
}
// GatewayFeatures represents edge gateway services.
@ -1352,12 +1376,13 @@ type GatewayIpsecVpnTunnel struct {
Description string `xml:"Description,omitempty"` // A description of the tunnel.
// TODO: Fix this in a better way
IpsecVpnThirdPartyPeer *IpsecVpnThirdPartyPeer `xml:"IpsecVpnThirdPartyPeer,omitempty"` // Details about the peer network.
IpsecVpnLocalPeer *IpsecVpnLocalPeer `xml:"IpsecVpnLocalPeer"` // Details about the local peer network.
PeerIPAddress string `xml:"PeerIpAddress"` // IP address of the peer endpoint.
PeerID string `xml:"PeerId"` // Id for the peer end point
LocalIPAddress string `xml:"LocalIpAddress"` // Address of the local network.
LocalID string `xml:"LocalId"` // Id for local end point
LocalSubnet *IpsecVpnSubnet `xml:"LocalSubnet"` // List of local subnets in the tunnel.
PeerSubnet *IpsecVpnSubnet `xml:"PeerSubnet"` // List of peer subnets in the tunnel.
LocalSubnet []*IpsecVpnSubnet `xml:"LocalSubnet"` // List of local subnets in the tunnel.
PeerSubnet []*IpsecVpnSubnet `xml:"PeerSubnet"` // List of peer subnets in the tunnel.
SharedSecret string `xml:"SharedSecret"` // Shared secret used for authentication.
SharedSecretEncrypted bool `xml:"SharedSecretEncrypted,omitempty"` // True if shared secret is encrypted.
EncryptionProtocol string `xml:"EncryptionProtocol"` // Encryption protocol to be used. One of: AES, AES256, TRIPLEDES
@ -1372,6 +1397,12 @@ type IpsecVpnThirdPartyPeer struct {
PeerID string `xml:"PeerId,omitempty"` // Id for the peer end point
}
// IpsecVpnThirdPartyPeer represents details about a peer network
type IpsecVpnLocalPeer struct {
ID string `xml:"Id"` // Id for the peer end point
Name string `xml:"Name"` // Name for the peer
}
// IpsecVpnSubnet represents subnet details.
// Type: IpsecVpnSubnetType
// Namespace: http://www.vmware.com/vcloud/v1.5

View File

@ -55,6 +55,195 @@ func (v *VApp) Refresh() error {
return nil
}
func (v *VApp) ComposeRawVApp(name string) error {
vcomp := &types.ComposeVAppParams{
Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
Xsi: "http://www.w3.org/2001/XMLSchema-instance",
Xmlns: "http://www.vmware.com/vcloud/v1.5",
Deploy: false,
Name: name,
PowerOn: false,
}
output, err := xml.MarshalIndent(vcomp, " ", " ")
if err != nil {
return fmt.Errorf("error marshaling vapp compose: %s", err)
}
debug := os.Getenv("GOVCLOUDAIR_DEBUG")
if debug == "true" {
fmt.Printf("\n\nXML DEBUG: %s\n\n", string(output))
}
b := bytes.NewBufferString(xml.Header + string(output))
s := v.c.VCDVDCHREF
s.Path += "/action/composeVApp"
req := v.c.NewRequest(map[string]string{}, "POST", s, b)
req.Header.Add("Content-Type", "application/vnd.vmware.vcloud.composeVAppParams+xml")
resp, err := checkResp(v.c.Http.Do(req))
if err != nil {
return fmt.Errorf("error instantiating a new vApp: %s", err)
}
if err = decodeBody(resp, v.VApp); err != nil {
return fmt.Errorf("error decoding vApp response: %s", err)
}
task := NewTask(v.c)
for _, t := range v.VApp.Tasks.Task {
task.Task = t
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("Error performing task: %#v", err)
}
}
return nil
}
func (v *VApp) AddVM(orgvdcnetwork OrgVDCNetwork, vapptemplate VAppTemplate, name string) error {
vcomp := &types.ReComposeVAppParams{
Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
Xsi: "http://www.w3.org/2001/XMLSchema-instance",
Xmlns: "http://www.vmware.com/vcloud/v1.5",
Deploy: false,
Name: v.VApp.Name,
PowerOn: false,
Description: v.VApp.Description,
SourcedItem: &types.SourcedCompositionItemParam{
Source: &types.Reference{
HREF: vapptemplate.VAppTemplate.Children.VM[0].HREF,
Name: name,
},
InstantiationParams: &types.InstantiationParams{
NetworkConnectionSection: &types.NetworkConnectionSection{
Type: vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.Type,
HREF: vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.HREF,
Info: "Network config for sourced item",
PrimaryNetworkConnectionIndex: vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.PrimaryNetworkConnectionIndex,
NetworkConnection: &types.NetworkConnection{
Network: orgvdcnetwork.OrgVDCNetwork.Name,
NetworkConnectionIndex: vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.NetworkConnection.NetworkConnectionIndex,
IsConnected: true,
IPAddressAllocationMode: "POOL",
},
},
},
NetworkAssignment: &types.NetworkAssignment{
InnerNetwork: orgvdcnetwork.OrgVDCNetwork.Name,
ContainerNetwork: orgvdcnetwork.OrgVDCNetwork.Name,
},
},
}
output, _ := xml.MarshalIndent(vcomp, " ", " ")
s, _ := url.ParseRequestURI(v.VApp.HREF)
s.Path += "/action/recomposeVApp"
fmt.Println(s)
fmt.Println(string(output))
b := bytes.NewBufferString(xml.Header + string(output))
req := v.c.NewRequest(map[string]string{}, "POST", *s, b)
req.Header.Add("Content-Type", "application/vnd.vmware.vcloud.recomposeVAppParams+xml")
task := NewTask(v.c)
v.Refresh()
if v.VApp.Tasks != nil {
fmt.Println("AYE")
for _, t := range v.VApp.Tasks.Task {
task.Task = t
err := task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("Error performing task: %#v", err)
}
}
} else {
fmt.Println("NO")
}
resp, err := checkResp(v.c.Http.Do(req))
if err != nil {
return fmt.Errorf("error instantiating a new vApp: %s", err)
}
task = NewTask(v.c)
if err = decodeBody(resp, task.Task); err != nil {
return fmt.Errorf("error decoding task response: %s", err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("Error performing task: %#v", err)
}
return nil
}
func (v *VApp) RemoveVM(vm VM) error {
task := NewTask(v.c)
for _, t := range v.VApp.Tasks.Task {
task.Task = t
err := task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("Error performing task: %#v", err)
}
}
vcomp := &types.ReComposeVAppParams{
Ovf: "http://schemas.dmtf.org/ovf/envelope/1",
Xsi: "http://www.w3.org/2001/XMLSchema-instance",
Xmlns: "http://www.vmware.com/vcloud/v1.5",
DeleteItem: &types.DeleteItem{
HREF: vm.VM.HREF,
},
}
output, _ := xml.MarshalIndent(vcomp, " ", " ")
s, _ := url.ParseRequestURI(v.VApp.HREF)
s.Path += "/action/recomposeVApp"
fmt.Println(s)
fmt.Println(string(output))
b := bytes.NewBufferString(xml.Header + string(output))
req := v.c.NewRequest(map[string]string{}, "POST", *s, b)
req.Header.Add("Content-Type", "application/vnd.vmware.vcloud.recomposeVAppParams+xml")
resp, err := checkResp(v.c.Http.Do(req))
if err != nil {
return fmt.Errorf("error instantiating a new vApp: %s", err)
}
task = NewTask(v.c)
if err = decodeBody(resp, task.Task); err != nil {
return fmt.Errorf("error decoding task response: %s", err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("Error performing task: %#v", err)
}
return nil
}
func (v *VApp) ComposeVApp(orgvdcnetwork OrgVDCNetwork, vapptemplate VAppTemplate, name string, description string) (Task, error) {
if vapptemplate.VAppTemplate.Children == nil || orgvdcnetwork.OrgVDCNetwork == nil {
@ -396,7 +585,10 @@ func (v *VApp) Delete() (Task, error) {
}
func (v *VApp) RunCustomizationScript(computername, script string) (Task, error) {
return v.Customize(computername, script, false)
}
func (v *VApp) Customize(computername, script string, changeSid bool) (Task, error) {
err := v.Refresh()
if err != nil {
return Task{}, fmt.Errorf("error refreshing vapp before running customization: %v", err)
@ -418,6 +610,7 @@ func (v *VApp) RunCustomizationScript(computername, script string) (Task, error)
Enabled: true,
ComputerName: computername,
CustomizationScript: script,
ChangeSid: false,
}
output, err := xml.MarshalIndent(vu, " ", " ")

View File

@ -217,7 +217,7 @@ func (v *Vdc) FindVAppByName(vapp string) (VApp, error) {
newvapp := NewVApp(v.c)
if err = decodeBody(resp, newvapp.VApp); err != nil {
return VApp{}, fmt.Errorf("error decoding vApp response: %s", err)
return VApp{}, fmt.Errorf("error decoding vApp response: %s", err.Error())
}
return *newvapp, nil
@ -228,6 +228,48 @@ func (v *Vdc) FindVAppByName(vapp string) (VApp, error) {
return VApp{}, fmt.Errorf("can't find vApp: %s", vapp)
}
func (v *Vdc) FindVMByName(vapp VApp, vm string) (VM, error) {
err := v.Refresh()
if err != nil {
return VM{}, fmt.Errorf("error refreshing vdc: %s", err)
}
for _, child := range vapp.VApp.Children.VM {
if child.Name == vm {
u, err := url.ParseRequestURI(child.HREF)
if err != nil {
return VM{}, fmt.Errorf("error decoding vdc response: %s", err)
}
// Querying the VApp
req := v.c.NewRequest(map[string]string{}, "GET", *u, nil)
resp, err := checkResp(v.c.Http.Do(req))
if err != nil {
return VM{}, fmt.Errorf("error retrieving vm: %s", err)
}
newvm := NewVM(v.c)
//body, err := ioutil.ReadAll(resp.Body)
//fmt.Println(string(body))
if err = decodeBody(resp, newvm.VM); err != nil {
return VM{}, fmt.Errorf("error decoding vm response: %s", err.Error())
}
return *newvm, nil
}
}
return VM{}, fmt.Errorf("can't find vm: %s", vm)
}
func (v *Vdc) FindVAppByID(vappid string) (VApp, error) {
// Horrible hack to fetch a vapp with its id.

12
vendor/vendor.json vendored
View File

@ -2980,16 +2980,16 @@
"revisionTime": "2016-09-28T01:52:44Z"
},
{
"checksumSHA1": "y4ihcZrjJdyQDnsKLelo9/1MjqE=",
"checksumSHA1": "cm+mGoVXAuESxVeudG1FSIN0lv4=",
"path": "github.com/ukcloud/govcloudair",
"revision": "9076b4221ebf430944c716c798e904e00cbaa89d",
"revisionTime": "2017-01-31T00:00:54Z"
"revision": "3c7799ae4b9cd5896a77990514578681c837c7bb",
"revisionTime": "2017-04-12T09:42:31Z"
},
{
"checksumSHA1": "CridJfrpcrjMdXnf7PbqA/+7wuY=",
"checksumSHA1": "8FHandxT6XIwsawRe0eNupivqho=",
"path": "github.com/ukcloud/govcloudair/types/v56",
"revision": "9076b4221ebf430944c716c798e904e00cbaa89d",
"revisionTime": "2017-01-31T00:00:54Z"
"revision": "3c7799ae4b9cd5896a77990514578681c837c7bb",
"revisionTime": "2017-04-12T09:42:31Z"
},
{
"checksumSHA1": "CdE9OUEGLn2pAv1UMuM5rSlaUpM=",