-
Notifications
You must be signed in to change notification settings - Fork 63
Add v1alpha1 system API #81
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package v1alpha1; | ||
|
|
||
| option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1"; | ||
|
|
||
| service System { | ||
| // GetBIOSSerialNumber returns the device's serial number | ||
| rpc GetBIOSSerialNumber(GetBIOSSerialNumberRequest) returns (GetBIOSSerialNumberResponse) {} | ||
| } | ||
|
|
||
| message GetBIOSSerialNumberRequest { | ||
| // Intentionally empty | ||
| } | ||
|
|
||
| message GetBIOSSerialNumberResponse { | ||
| // Serial number | ||
| string serial_number = 1; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package integrationtests | ||
|
|
||
| import ( | ||
| "context" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" | ||
| v1alpha1client "github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetBIOSSerialNumber(t *testing.T) { | ||
| t.Run("GetBIOSSerialNumber", func(t *testing.T) { | ||
| client, err := v1alpha1client.NewClient() | ||
| require.Nil(t, err) | ||
| defer client.Close() | ||
|
|
||
| request := &v1alpha1.GetBIOSSerialNumberRequest{} | ||
| response, err := client.GetBIOSSerialNumber(context.TODO(), request) | ||
| require.Nil(t, err) | ||
| require.NotNil(t, response) | ||
|
|
||
| result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output() | ||
| require.Nil(t, err) | ||
|
|
||
| t.Logf("The serial number is %s", response.SerialNumber) | ||
|
|
||
| resultString := string(result) | ||
| require.True(t, strings.Contains(resultString, response.SerialNumber)) | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package system | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Implements the System OS API calls. All code here should be very simple | ||
| // pass-through to the OS APIs. Any logic around the APIs should go in | ||
| // internal/server/system/server.go so that logic can be easily unit-tested | ||
| // without requiring specific OS environments. | ||
|
|
||
| type APIImplementor struct{} | ||
|
|
||
| func New() APIImplementor { | ||
| return APIImplementor{} | ||
| } | ||
|
|
||
| func (APIImplementor) GetBIOSSerialNumber() (string, error) { | ||
| // Taken from Kubernetes vSphere cloud provider | ||
| // https://github.com/kubernetes/kubernetes/blob/103e926604de6f79161b78af3e792d0ed282bc06/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere_util_windows.go#L28 | ||
| result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| lines := strings.FieldsFunc(string(result), func(r rune) bool { | ||
| switch r { | ||
| case '\n', '\r': | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| }) | ||
| if len(lines) != 2 { | ||
| return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please remove
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Submitted #94 to address ^ |
||
| } | ||
| return lines[1], nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.