vendor: add github.com/Azure/azure-sdk-for-go and dependencies

This commit is contained in:
Nick Craig-Wood
2017-08-04 22:54:27 +01:00
parent 132f71d504
commit 91cfcc21ff
958 changed files with 320589 additions and 0 deletions
@@ -0,0 +1,47 @@
// Package virtualnetwork provides a client for Virtual Networks.
package virtualnetwork
import (
"encoding/xml"
"github.com/Azure/azure-sdk-for-go/management"
)
const (
azureNetworkConfigurationURL = "services/networking/media"
)
// NewClient is used to return new VirtualNetworkClient instance
func NewClient(client management.Client) VirtualNetworkClient {
return VirtualNetworkClient{client: client}
}
// GetVirtualNetworkConfiguration retreives the current virtual network
// configuration for the currently active subscription. Note that the
// underlying Azure API means that network related operations are not safe
// for running concurrently.
func (c VirtualNetworkClient) GetVirtualNetworkConfiguration() (NetworkConfiguration, error) {
networkConfiguration := c.NewNetworkConfiguration()
response, err := c.client.SendAzureGetRequest(azureNetworkConfigurationURL)
if err != nil {
return networkConfiguration, err
}
err = xml.Unmarshal(response, &networkConfiguration)
return networkConfiguration, err
}
// SetVirtualNetworkConfiguration configures the virtual networks for the
// currently active subscription according to the NetworkConfiguration given.
// Note that the underlying Azure API means that network related operations
// are not safe for running concurrently.
func (c VirtualNetworkClient) SetVirtualNetworkConfiguration(networkConfiguration NetworkConfiguration) (management.OperationID, error) {
networkConfiguration.setXMLNamespaces()
networkConfigurationBytes, err := xml.Marshal(networkConfiguration)
if err != nil {
return "", err
}
return c.client.SendAzurePutRequest(azureNetworkConfigurationURL, "text/plain", networkConfigurationBytes)
}
@@ -0,0 +1,90 @@
package virtualnetwork
import (
"encoding/xml"
"github.com/Azure/azure-sdk-for-go/management"
)
const xmlNamespace = "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration"
const xmlNamespaceXsd = "http://www.w3.org/2001/XMLSchema"
const xmlNamespaceXsi = "http://www.w3.org/2001/XMLSchema-instance"
// VirtualNetworkClient is used to perform operations on Virtual Networks.
type VirtualNetworkClient struct {
client management.Client
}
// NetworkConfiguration represents the network configuration for an entire Azure
// subscription.
type NetworkConfiguration struct {
XMLName xml.Name `xml:"NetworkConfiguration"`
XMLNamespaceXsd string `xml:"xmlns:xsd,attr"`
XMLNamespaceXsi string `xml:"xmlns:xsi,attr"`
XMLNs string `xml:"xmlns,attr"`
Configuration VirtualNetworkConfiguration `xml:"VirtualNetworkConfiguration"`
// TODO: Nicer builder methods for these that abstract away the
// underlying structure.
}
// NewNetworkConfiguration creates a new empty NetworkConfiguration structure
// for further configuration. The XML namespaces are already set correctly.
func (client *VirtualNetworkClient) NewNetworkConfiguration() NetworkConfiguration {
networkConfiguration := NetworkConfiguration{}
networkConfiguration.setXMLNamespaces()
return networkConfiguration
}
// setXMLNamespaces ensure that all of the required namespaces are set. It
// should be called prior to marshalling the structure to XML for use with the
// Azure REST endpoint. It is used internally prior to submitting requests, but
// since it is idempotent there is no harm in repeat calls.
func (n *NetworkConfiguration) setXMLNamespaces() {
n.XMLNamespaceXsd = xmlNamespaceXsd
n.XMLNamespaceXsi = xmlNamespaceXsi
n.XMLNs = xmlNamespace
}
type VirtualNetworkConfiguration struct {
DNS DNS `xml:"Dns,omitempty"`
LocalNetworkSites []LocalNetworkSite `xml:"LocalNetworkSites>LocalNetworkSite"`
VirtualNetworkSites []VirtualNetworkSite `xml:"VirtualNetworkSites>VirtualNetworkSite"`
}
type DNS struct {
DNSServers []DNSServer `xml:"DnsServers>DnsServer,omitempty"`
}
type DNSServer struct {
XMLName xml.Name `xml:"DnsServer"`
Name string `xml:"name,attr"`
IPAddress string `xml:"IPAddress,attr"`
}
type DNSServerRef struct {
Name string `xml:"name,attr"`
}
type VirtualNetworkSite struct {
Name string `xml:"name,attr"`
Location string `xml:"Location,attr"`
AddressSpace AddressSpace `xml:"AddressSpace"`
Subnets []Subnet `xml:"Subnets>Subnet"`
DNSServersRef []DNSServerRef `xml:"DnsServersRef>DnsServerRef,omitempty"`
}
type LocalNetworkSite struct {
Name string `xml:"name,attr"`
VPNGatewayAddress string
AddressSpace AddressSpace
}
type AddressSpace struct {
AddressPrefix []string
}
type Subnet struct {
Name string `xml:"name,attr"`
AddressPrefix string
}