...

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

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

     1  // +build go1.7
     2  
     3  package vmutils
     4  
     5  // Copyright (c) Microsoft Corporation. All rights reserved.
     6  // Licensed under the MIT License. See License.txt in the project root for license information.
     7  
     8  import (
     9  	"fmt"
    10  
    11  	vm "github.com/Azure/azure-sdk-for-go/services/classic/management/virtualmachine"
    12  )
    13  
    14  // ConfigureWithPublicSSH adds configuration exposing port 22 externally
    15  func ConfigureWithPublicSSH(role *vm.Role) error {
    16  	if role == nil {
    17  		return fmt.Errorf(errParamNotSpecified, "role")
    18  	}
    19  
    20  	return ConfigureWithExternalPort(role, "SSH", 22, 22, vm.InputEndpointProtocolTCP)
    21  }
    22  
    23  // ConfigureWithPublicRDP adds configuration exposing port 3389 externally
    24  func ConfigureWithPublicRDP(role *vm.Role) error {
    25  	if role == nil {
    26  		return fmt.Errorf(errParamNotSpecified, "role")
    27  	}
    28  
    29  	return ConfigureWithExternalPort(role, "RDP", 3389, 3389, vm.InputEndpointProtocolTCP)
    30  }
    31  
    32  // ConfigureWithPublicPowerShell adds configuration exposing port 5986
    33  // externally
    34  func ConfigureWithPublicPowerShell(role *vm.Role) error {
    35  	if role == nil {
    36  		return fmt.Errorf(errParamNotSpecified, "role")
    37  	}
    38  
    39  	return ConfigureWithExternalPort(role, "PowerShell", 5986, 5986, vm.InputEndpointProtocolTCP)
    40  }
    41  
    42  // ConfigureWithExternalPort adds a new InputEndpoint to the Role, exposing a
    43  // port externally
    44  func ConfigureWithExternalPort(role *vm.Role, name string, localport, externalport int, protocol vm.InputEndpointProtocol) error {
    45  	if role == nil {
    46  		return fmt.Errorf(errParamNotSpecified, "role")
    47  	}
    48  
    49  	role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
    50  		func(config *vm.ConfigurationSet) {
    51  			config.InputEndpoints = append(config.InputEndpoints, vm.InputEndpoint{
    52  				LocalPort: localport,
    53  				Name:      name,
    54  				Port:      externalport,
    55  				Protocol:  protocol,
    56  			})
    57  		})
    58  
    59  	return nil
    60  }
    61  
    62  // ConfigureWithSecurityGroup associates the Role with a specific network security group
    63  func ConfigureWithSecurityGroup(role *vm.Role, networkSecurityGroup string) error {
    64  	if role == nil {
    65  		return fmt.Errorf(errParamNotSpecified, "role")
    66  	}
    67  
    68  	role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
    69  		func(config *vm.ConfigurationSet) {
    70  			config.NetworkSecurityGroup = networkSecurityGroup
    71  		})
    72  
    73  	return nil
    74  }
    75  
    76  // ConfigureWithSubnet associates the Role with a specific subnet
    77  func ConfigureWithSubnet(role *vm.Role, subnet string) error {
    78  	if role == nil {
    79  		return fmt.Errorf(errParamNotSpecified, "role")
    80  	}
    81  
    82  	role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
    83  		func(config *vm.ConfigurationSet) {
    84  			config.SubnetNames = append(config.SubnetNames, subnet)
    85  		})
    86  
    87  	return nil
    88  }
    89  

View as plain text