Пример #1
0
func getAffinityGroupLocation(client management.Client, affinityGroup string) (string, error) {
	const getAffinityGroupProperties = "affinitygroups/%s"
	d, err := client.SendAzureGetRequest(fmt.Sprintf(getAffinityGroupProperties, affinityGroup))
	if err != nil {
		return "", err
	}

	var afGroup struct {
		Location string
	}
	err = xml.Unmarshal(d, &afGroup)

	return afGroup.Location, err
}
Пример #2
0
func checkVirtualNetworkConfiguration(client management.Client, vnetname, subnetname, location string) error {
	const getVNetConfig = "services/networking/media"
	d, err := client.SendAzureGetRequest(getVNetConfig)
	if err != nil {
		return err
	}

	var vnetConfig struct {
		VNets []struct {
			Name          string `xml:"name,attr"`
			AffinityGroup string `xml:",attr"`
			Location      string `xml:",attr"`
			Subnets       []struct {
				Name          string `xml:"name,attr"`
				AddressPrefix string
			} `xml:"Subnets>Subnet"`
		} `xml:"VirtualNetworkConfiguration>VirtualNetworkSites>VirtualNetworkSite"`
	}
	err = xml.Unmarshal(d, &vnetConfig)
	if err != nil {
		return err
	}

	for _, vnet := range vnetConfig.VNets {
		if vnet.Name == vnetname {
			if vnet.AffinityGroup != "" {
				vnet.Location, err = getAffinityGroupLocation(client, vnet.AffinityGroup)
				if err != nil {
					return err
				}
			}
			if vnet.Location != location {
				return fmt.Errorf("VNet %q is not in location %q, but in %q", vnet.Name, location, vnet.Location)
			}

			for _, sn := range vnet.Subnets {
				if sn.Name == subnetname {
					return nil
				}
			}
		}
	}

	return fmt.Errorf("Could not find vnet %q and subnet %q in network configuration: %v", vnetname, subnetname, vnetConfig)
}