...
1
2
3 package vmutils
4
5
6
7
8 import (
9 "fmt"
10
11 vm "github.com/Azure/azure-sdk-for-go/services/classic/management/virtualmachine"
12 )
13
14
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
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
33
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
43
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
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
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