Skip to content

Commit

Permalink
add inventory package
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Feb 4, 2023
1 parent 4e32c24 commit 0791a7b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY go.sum ./
RUN go mod download

# build an app
COPY *.go ./
RUN go build -v
COPY pkg pkg
RUN go build -v ./...
2 changes: 1 addition & 1 deletion goopicsi.go → pkg/csi/goopicsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2022 Dell Inc, or its subsidiaries.

// Package godpu implements the go library for OPI to be used in CSI drivers
package godpu
package csi

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion goopicsi_test.go → pkg/csi/goopicsi_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022 Dell Inc, or its subsidiaries.

package godpu
package csi

import (
"fmt"
Expand Down
62 changes: 62 additions & 0 deletions pkg/inventory/inventory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022 Dell Inc, or its subsidiaries.

// Package inventory implements the go library for OPI to be used to query inventory
package inventory

import (
"context"
"log"
"time"

pb "github.com/opiproject/opi-api/common/v1/gen/go"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

var (
conn *grpc.ClientConn
address = "localhost:50051"
)

// InventoryGet returns inventory information from DPUs
func InventoryGet() error {
if conn == nil {
err := dialConnection()
if err != nil {
return err
}
}

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

data, err := client.InventoryGet(ctx, &pb.InventoryGetRequest{})
if err != nil {
log.Println(err)
}
log.Println(data)
log.Printf("Remote NVMf controller disconnected successfully: %v", data.Subnqn)
defer disconnectConnection()
return nil
}

func dialConnection() error {
var err error
conn, err = grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Printf("Failed to connect: %v", err)
return err
}
return nil
}

func disconnectConnection() {
err := conn.Close()
if err != nil {
log.Fatalf("Failed to close connection: %v", err)
} else {
log.Println("GRPC connection closed successfully")
}
}
4 changes: 4 additions & 0 deletions pkg/inventory/inventory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022 Dell Inc, or its subsidiaries.

package inventory

0 comments on commit 0791a7b

Please sign in to comment.