Skip to content

Commit

Permalink
Added Get and List RPC
Browse files Browse the repository at this point in the history
Added Get and List RPC

Signed-off-by: harshita Pandey <[email protected]>

Removing proto messages

Signed-off-by: harshita Pandey <[email protected]>
  • Loading branch information
harshitap26 authored and glimchb committed Nov 14, 2022
1 parent d7ae9c7 commit 6f9332a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/opiproject/opi-api v0.0.0-20221109134843-76522ac45e89 h1:yg9wTkuglnqdqMehhQ03o3FpYijUQrSvoWmtJq6+jHw=
github.com/opiproject/opi-api v0.0.0-20221109134843-76522ac45e89/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221109211833-28e180c2b861 h1:nemJXB02Fba6ABy5jLwONhzNhVZZXKQjCp36dzS2vFs=
github.com/opiproject/opi-api v0.0.0-20221109211833-28e180c2b861/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221110142707-ff3fb4ac5d06 h1:TTXcS3FrNS48InPw/f2R/NY6lhSNDqwoYZAzFOvTtEw=
github.com/opiproject/opi-api v0.0.0-20221110142707-ff3fb4ac5d06/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221110181853-70e9b94f0639 h1:mScRVOSk125hN0ml4eUZ1CvDTYn2pBOc5c9l38Bn9DA=
github.com/opiproject/opi-api v0.0.0-20221110181853-70e9b94f0639/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221111162909-12de4dd988a0 h1:mvnXHTF24rE3HYUrKjh6eAyrYbvi2augehpCFKwvaFU=
github.com/opiproject/opi-api v0.0.0-20221111162909-12de4dd988a0/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20221111230258-34e208409ec2 h1:AAgyJQOtuN5+PFajjhLZIVDfaTWZQ8t5u3tqTnK3nzE=
github.com/opiproject/opi-api v0.0.0-20221111230258-34e208409ec2/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
44 changes: 44 additions & 0 deletions goopicsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,50 @@ func NVMeControllerConnect(request *pb.NVMfRemoteController) (*pb.NVMfRemoteCont
return &pb.NVMfRemoteControllerConnectResponse{}, nil
}

// NVMeControllerList lists all the connections to the remote NVMf controller
func NVMeControllerList() error {
if conn == nil {
err := dialConnection()
if err != nil {
return err
}
}

client := pb.NewNVMfRemoteControllerServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

response, err := client.NVMfRemoteControllerList(ctx, &pb.NVMfRemoteControllerListRequest{})
if err != nil {
log.Printf("could not list the connections to Remote NVMf controller: %v", err)
return err
}
log.Printf("Connections: %v", response)
return nil
}

// NVMeControllerGet lists the connection to the remote NVMf controller corresponding to the given ID
func NVMeControllerGet(id int64) error {
if conn == nil {
err := dialConnection()
if err != nil {
return err
}
}

client := pb.NewNVMfRemoteControllerServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

response, err := client.NVMfRemoteControllerGet(ctx, &pb.NVMfRemoteControllerGetRequest{Id: id})
if err != nil {
log.Printf("could not list the connection to Remote NVMf controller corresponding to the given ID: %v", err)
return err
}
log.Printf("Connection corresponding to the given ID: %v", response)
return nil
}

// NVMeControllerDisconnect disconnects remote NVMf controller connection
func NVMeControllerDisconnect(request *pb.NVMfRemoteControllerDisconnectRequest) (*pb.NVMfRemoteControllerDisconnectResponse, error) {
if conn == nil {
Expand Down
14 changes: 14 additions & 0 deletions goopicsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ func TestNVMeControllerConnect(t *testing.T) {
assert.Error(t, err, "connection failed")
}

func TestNVMeControllerList(t *testing.T) {
err := NVMeControllerList()
if err != nil {
log.Println(err)
}
}

func TestNVMeControllerGet(t *testing.T) {
err := NVMeControllerGet(12)
if err != nil {
log.Println(err)
}
}

func TestNVMeControllerDisconnect(t *testing.T) {
resp, err := NVMeControllerDisconnect(&pb.NVMfRemoteControllerDisconnectRequest{Id: 12})
if err != nil {
Expand Down

0 comments on commit 6f9332a

Please sign in to comment.