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
|
package vmutils
import (
"fmt"
vm "github.com/Azure/azure-sdk-for-go/management/virtualmachine"
)
// ConfigureWithPublicSSH adds configuration exposing port 22 externally
func ConfigureWithPublicSSH(role *vm.Role) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
return ConfigureWithExternalPort(role, "SSH", 22, 22, vm.InputEndpointProtocolTCP)
}
// ConfigureWithPublicRDP adds configuration exposing port 3389 externally
func ConfigureWithPublicRDP(role *vm.Role) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
return ConfigureWithExternalPort(role, "RDP", 3389, 3389, vm.InputEndpointProtocolTCP)
}
// ConfigureWithPublicPowerShell adds configuration exposing port 5986
// externally
func ConfigureWithPublicPowerShell(role *vm.Role) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
return ConfigureWithExternalPort(role, "PowerShell", 5986, 5986, vm.InputEndpointProtocolTCP)
}
// ConfigureWithExternalPort adds a new InputEndpoint to the Role, exposing a
// port externally
func ConfigureWithExternalPort(role *vm.Role, name string, localport, externalport int, protocol vm.InputEndpointProtocol) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
func(config *vm.ConfigurationSet) {
config.InputEndpoints = append(config.InputEndpoints, vm.InputEndpoint{
LocalPort: localport,
Name: name,
Port: externalport,
Protocol: protocol,
})
})
return nil
}
// ConfigureWithSecurityGroup associates the Role with a specific network security group
func ConfigureWithSecurityGroup(role *vm.Role, networkSecurityGroup string) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
func(config *vm.ConfigurationSet) {
config.NetworkSecurityGroup = networkSecurityGroup
})
return nil
}
// ConfigureWithSubnet associates the Role with a specific subnet
func ConfigureWithSubnet(role *vm.Role, subnet string) error {
if role == nil {
return fmt.Errorf(errParamNotSpecified, "role")
}
role.ConfigurationSets = updateOrAddConfig(role.ConfigurationSets, vm.ConfigurationSetTypeNetwork,
func(config *vm.ConfigurationSet) {
config.SubnetNames = append(config.SubnetNames, subnet)
})
return nil
}
|