File: entities.go

package info (click to toggle)
golang-github-azure-azure-sdk-for-go 68.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556,256 kB
  • sloc: javascript: 196; sh: 96; makefile: 7
file content (95 lines) | stat: -rw-r--r-- 3,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// +build go1.7

package virtualnetwork

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import (
	"encoding/xml"

	"github.com/Azure/azure-sdk-for-go/services/classic/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
}