Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inventory package #103

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ./...
4 changes: 2 additions & 2 deletions goopicsi.go → pkg/csi/goopicsi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// 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 implements the go library for OPI to be used in CSI drivers
package csi

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -32,7 +32,7 @@ func RunServer() {
fmt.Println("RUNNING MOCK SERVER")
const (
csiAddress = "localhost:50051"
defaultStubsPath = "test/mock-server/stubs"
defaultStubsPath = "../../test/mock-server/stubs"
apiPort = "4771"
)

Expand Down
61 changes: 61 additions & 0 deletions pkg/inventory/inventory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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"
)

// Get returns inventory information from DPUs
func Get() 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)
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