-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_device.go
48 lines (40 loc) · 1.54 KB
/
block_device.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
46
47
48
package main
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/lovi-cloud/go-os-brick/osbrick"
pb "github.com/lovi-cloud/teleskop/protoc/agent"
)
func (a *agent) ConnectBlockDevice(ctx context.Context, req *pb.ConnectBlockDeviceRequest) (*pb.ConnectBlockDeviceResponse, error) {
var deviceName string
var err error
switch len(req.PortalAddresses) {
case 1:
deviceName, err = osbrick.ConnectSinglePathVolume(ctx, req.PortalAddresses[0], int(req.HostLunId))
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to connect block device: %+v", err)
}
default:
deviceName, err = osbrick.ConnectMultipathVolume(ctx, req.PortalAddresses, int(req.HostLunId))
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to connect block device: %+v", err)
}
}
return &pb.ConnectBlockDeviceResponse{
DeviceName: deviceName,
}, nil
}
func (a *agent) DisconnectBlockDevice(ctx context.Context, req *pb.DisconnectBlockDeviceRequest) (*pb.DisconnectBlockDeviceResponse, error) {
switch len(req.PortalAddresses) {
case 1:
if err := osbrick.DisconnectSinglePathVolume(ctx, req.PortalAddresses[0], int(req.HostLunId)); err != nil {
return nil, status.Errorf(codes.Internal, "failed to disconnect block device: %+v", err)
}
default:
if err := osbrick.DisconnectVolume(ctx, req.PortalAddresses, int(req.HostLunId)); err != nil {
return nil, status.Errorf(codes.Internal, "failed to disconnect block device: %+v", err)
}
}
return &pb.DisconnectBlockDeviceResponse{}, nil
}