-
Notifications
You must be signed in to change notification settings - Fork 19
/
addAddress.go
45 lines (41 loc) · 1.12 KB
/
addAddress.go
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
package main
import (
"fmt"
"net"
"github.com/Symantec/Dominator/lib/errors"
"github.com/Symantec/Dominator/lib/log"
"github.com/Symantec/Dominator/lib/srpc"
proto "github.com/Symantec/Dominator/proto/hypervisor"
)
func addAddressSubcommand(args []string, logger log.DebugLogger) error {
var ipAddr string
if len(args) > 1 {
ipAddr = args[1]
}
err := addAddress(args[0], ipAddr, logger)
if err != nil {
return fmt.Errorf("Error adding address: %s", err)
}
return nil
}
func addAddress(macAddr, ipAddr string, logger log.DebugLogger) error {
address := proto.Address{MacAddress: macAddr}
if ipAddr != "" {
address.IpAddress = net.ParseIP(ipAddr)
}
address.Shrink()
request := proto.ChangeAddressPoolRequest{
AddressesToAdd: []proto.Address{address}}
var reply proto.ChangeAddressPoolResponse
clientName := fmt.Sprintf("%s:%d", *hypervisorHostname, *hypervisorPortNum)
client, err := srpc.DialHTTP("tcp", clientName, 0)
if err != nil {
return err
}
defer client.Close()
err = client.RequestReply("Hypervisor.ChangeAddressPool", request, &reply)
if err != nil {
return err
}
return errors.New(reply.Error)
}