...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/virtualnetwork/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management/virtualnetwork

     1  // +build go1.7
     2  
     3  // Package virtualnetwork provides a client for Virtual Networks.
     4  package virtualnetwork
     5  
     6  // Copyright (c) Microsoft Corporation. All rights reserved.
     7  // Licensed under the MIT License. See License.txt in the project root for license information.
     8  
     9  import (
    10  	"encoding/xml"
    11  
    12  	"github.com/Azure/azure-sdk-for-go/services/classic/management"
    13  )
    14  
    15  const (
    16  	azureNetworkConfigurationURL = "services/networking/media"
    17  )
    18  
    19  // NewClient is used to return new VirtualNetworkClient instance
    20  func NewClient(client management.Client) VirtualNetworkClient {
    21  	return VirtualNetworkClient{client: client}
    22  }
    23  
    24  // GetVirtualNetworkConfiguration retreives the current virtual network
    25  // configuration for the currently active subscription. Note that the
    26  // underlying Azure API means that network related operations are not safe
    27  // for running concurrently.
    28  func (c VirtualNetworkClient) GetVirtualNetworkConfiguration() (NetworkConfiguration, error) {
    29  	networkConfiguration := c.NewNetworkConfiguration()
    30  	response, err := c.client.SendAzureGetRequest(azureNetworkConfigurationURL)
    31  	if err != nil {
    32  		return networkConfiguration, err
    33  	}
    34  
    35  	err = xml.Unmarshal(response, &networkConfiguration)
    36  	return networkConfiguration, err
    37  
    38  }
    39  
    40  // SetVirtualNetworkConfiguration configures the virtual networks for the
    41  // currently active subscription according to the NetworkConfiguration given.
    42  // Note that the underlying Azure API means that network related operations
    43  // are not safe for running concurrently.
    44  func (c VirtualNetworkClient) SetVirtualNetworkConfiguration(networkConfiguration NetworkConfiguration) (management.OperationID, error) {
    45  	networkConfiguration.setXMLNamespaces()
    46  	networkConfigurationBytes, err := xml.Marshal(networkConfiguration)
    47  	if err != nil {
    48  		return "", err
    49  	}
    50  
    51  	return c.client.SendAzurePutRequest(azureNetworkConfigurationURL, "text/plain", networkConfigurationBytes)
    52  }
    53  

View as plain text