-
Notifications
You must be signed in to change notification settings - Fork 19
/
moveIpAddress.go
42 lines (38 loc) · 1.09 KB
/
moveIpAddress.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
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/fleetmanager"
)
func moveIpAddressSubcommand(args []string, logger log.DebugLogger) error {
if err := moveIpAddress(args[0], logger); err != nil {
return fmt.Errorf("Error moving IP address: %s", err)
}
return nil
}
func moveIpAddress(addr string, logger log.DebugLogger) error {
ipAddr := net.ParseIP(addr)
if len(ipAddr) < 4 {
return fmt.Errorf("invalid IP address: %s", addr)
}
request := proto.MoveIpAddressesRequest{
HypervisorHostname: *hypervisorHostname,
IpAddresses: []net.IP{ipAddr},
}
var reply proto.MoveIpAddressesResponse
clientName := fmt.Sprintf("%s:%d",
*fleetManagerHostname, *fleetManagerPortNum)
client, err := srpc.DialHTTPWithDialer("tcp", clientName, rrDialer)
if err != nil {
return err
}
defer client.Close()
err = client.RequestReply("FleetManager.MoveIpAddresses", request, &reply)
if err != nil {
return err
}
return errors.New(reply.Error)
}