generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
546 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
return lines[1], nil | ||
} |
Oops, something went wrong.