Skip to content

Commit 1a574c1

Browse files
authored
Merge pull request #15 from ddebroy/disk-api-1
Disk APIs
2 parents 49547a8 + f221909 commit 1a574c1

File tree

15 files changed

+1247
-5
lines changed

15 files changed

+1247
-5
lines changed

client/api/disk/v1alpha1/api.pb.go

Lines changed: 498 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/disk/v1alpha1/api.proto

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
syntax = "proto3";
2+
3+
package v1alpha1;
4+
5+
service Disk {
6+
// ListDiskLocations returns locations <Adapter, Bus, Target, LUN ID> of all
7+
// disk devices enumerated by the host
8+
rpc ListDiskLocations(ListDiskLocationsRequest) returns (ListDiskLocationsResponse) {}
9+
10+
// PartitionDisk initializes and partitions a disk device (if the disk has not
11+
// been partitioned already) and returns the resulting volume device ID
12+
rpc PartitionDisk(PartitionDiskRequest) returns (PartitionDiskResponse) {}
13+
14+
// Rescan refreshes the host's storage cache
15+
rpc Rescan(RescanRequest) returns (RescanResponse) {}
16+
}
17+
18+
message ListDiskLocationsRequest {
19+
// Intentionally empty
20+
}
21+
22+
message DiskLocation {
23+
string Adapter = 1;
24+
string Bus = 2;
25+
string Target = 3;
26+
string LUNID = 4;
27+
}
28+
29+
message ListDiskLocationsResponse {
30+
// Map of disk device IDs and <adapter, bus, target, lun ID> associated with each disk device
31+
map <string, DiskLocation> disk_locations = 1;
32+
}
33+
34+
message PartitionDiskRequest {
35+
// Disk device ID of the disk to partition
36+
string diskID = 1;
37+
}
38+
39+
message PartitionDiskResponse {
40+
// Intentionally empty
41+
}
42+
43+
message RescanRequest {
44+
// Intentionally empty
45+
}
46+
47+
message RescanResponse {
48+
// Intentionally empty
49+
}

client/groups/disk/v1alpha1/client_generated.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/server/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"flag"
55

6+
diskapi "github.com/kubernetes-csi/csi-proxy/internal/os/disk"
67
filesystemapi "github.com/kubernetes-csi/csi-proxy/internal/os/filesystem"
78
volumeapi "github.com/kubernetes-csi/csi-proxy/internal/os/volume"
89
"github.com/kubernetes-csi/csi-proxy/internal/server"
10+
disksrv "github.com/kubernetes-csi/csi-proxy/internal/server/disk"
911
filesystemsrv "github.com/kubernetes-csi/csi-proxy/internal/server/filesystem"
1012
srvtypes "github.com/kubernetes-csi/csi-proxy/internal/server/types"
1113
volumesrv "github.com/kubernetes-csi/csi-proxy/internal/server/volume"
@@ -44,8 +46,14 @@ func apiGroups() ([]srvtypes.APIGroup, error) {
4446
return []srvtypes.APIGroup{}, err
4547
}
4648

49+
disksrv, err := disksrv.NewServer(diskapi.New())
50+
if err != nil {
51+
return []srvtypes.APIGroup{}, err
52+
}
53+
4754
return []srvtypes.APIGroup{
4855
fssrv,
56+
disksrv,
4957
volumesrv,
5058
}, nil
5159
}

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ replace (
1414

1515
require (
1616
github.com/Microsoft/go-winio v0.4.14
17-
github.com/golang/protobuf v1.3.2
17+
github.com/golang/protobuf v1.3.3
1818
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
1919
github.com/kubernetes-csi/csi-proxy/client v0.0.0-00010101000000-000000000000
2020
github.com/pkg/errors v0.8.1
2121
github.com/sergi/go-diff v1.0.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/stretchr/testify v1.4.0
24-
google.golang.org/grpc v1.24.0
24+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
25+
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
26+
golang.org/x/text v0.3.2 // indirect
27+
google.golang.org/genproto v0.0.0-20200205142000-a86caf926a67 // indirect
28+
google.golang.org/grpc v1.27.1
2529
k8s.io/gengo v0.0.0-00010101000000-000000000000
2630
k8s.io/klog v1.0.0
2731
)

go.sum

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
44
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
5+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
56
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
67
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
89
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
11+
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
912
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
13+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
1014
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
1115
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
16+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1217
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
1318
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
19+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
20+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
1421
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
1522
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 h1:ECW73yc9MY7935nNYXUkK7Dz17YuSUI9yqRqYS8aBww=
1623
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
@@ -19,6 +26,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
1926
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2027
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2128
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
29+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
2230
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
2331
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
2432
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
@@ -29,34 +37,61 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
2937
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
3038
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
3139
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
32-
github.com/wk8/gengo v0.0.0-20191001015530-3d2530bfe606ffd99a90d70ef781861042e23a6f h1:X1xLpnAmbCIKjEbdexqRY7H8H7qQFtZ9dPUvDRXb/V0=
33-
github.com/wk8/gengo v0.0.0-20191001015530-3d2530bfe606ffd99a90d70ef781861042e23a6f/go.mod h1:7+jn4yanRF/Ylvd5qyNPUq0VhvOMDhjXrViFtHMcHxI=
3440
github.com/wk8/gengo v0.0.0-20191007012548-3d2530bfe606 h1:i5JAp+X9ISMaGt0R/9nsiFuNyYN0hXSK9KtphOk/r94=
3541
github.com/wk8/gengo v0.0.0-20191007012548-3d2530bfe606/go.mod h1:7+jn4yanRF/Ylvd5qyNPUq0VhvOMDhjXrViFtHMcHxI=
36-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
3742
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
43+
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
44+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
45+
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
3846
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
47+
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
48+
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
49+
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
3950
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
4051
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
52+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
53+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
4154
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
55+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
56+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4257
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
58+
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4359
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4460
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4561
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
4662
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
63+
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
64+
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4765
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
4866
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
67+
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
68+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
69+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
70+
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
71+
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
4972
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
5073
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
5174
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
5275
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
76+
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
5377
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
5478
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
79+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
80+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
81+
google.golang.org/genproto v0.0.0-20200205142000-a86caf926a67 h1:MBO9fkVSrTpJ8vgHLPi5gb+ZWXEy7/auJN8yqyu9EiE=
82+
google.golang.org/genproto v0.0.0-20200205142000-a86caf926a67/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
83+
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
84+
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
5585
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
5686
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
87+
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
88+
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
89+
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
90+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5791
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5892
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
5993
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
94+
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
6095
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
6196
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
6297
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=

internal/os/disk/api.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package disk
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os/exec"
7+
"strings"
8+
9+
shared "github.com/kubernetes-csi/csi-proxy/internal/shared/disk"
10+
"k8s.io/klog"
11+
)
12+
13+
// Implements the OS API calls related to Disk Devices. All code here should be very simple
14+
// pass-through to the OS APIs or cmdlets. Any logic around the APIs/cmdlet invocation
15+
// should go in internal/server/filesystem/disk.go so that logic can be easily unit-tested
16+
// without requiring specific OS environments.
17+
type APIImplementor struct{}
18+
19+
func New() APIImplementor {
20+
return APIImplementor{}
21+
}
22+
23+
// ListDiskLocations - constructs a map with the disk number as the key and the DiskLocation structure
24+
// as the value. The DiskLocation struct has various fields like the Adapter, Bus, Target and LUNID.
25+
func (APIImplementor) ListDiskLocations() (map[string]shared.DiskLocation, error) {
26+
cmd := fmt.Sprintf("Get-Disk | select number, location | ConvertTo-Json")
27+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
var getDisk []map[string]interface{}
33+
err = json.Unmarshal(out, &getDisk)
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
m := make(map[string]shared.DiskLocation)
39+
for _, v := range getDisk {
40+
str := v["location"].(string)
41+
num := fmt.Sprintf("%d", int(v["number"].(float64)))
42+
43+
found := false
44+
s := strings.Split(str, ":")
45+
if len(s) >= 5 {
46+
var d shared.DiskLocation
47+
for _, item := range s {
48+
item = strings.TrimSpace(item)
49+
itemSplit := strings.Split(item, " ")
50+
if len(itemSplit) == 2 {
51+
found = true
52+
switch strings.TrimSpace(itemSplit[0]) {
53+
case "Adapter":
54+
d.Adapter = strings.TrimSpace(itemSplit[1])
55+
case "Target":
56+
d.Target = strings.TrimSpace(itemSplit[1])
57+
case "LUN":
58+
d.LUNID = strings.TrimSpace(itemSplit[1])
59+
default:
60+
klog.Warningf("Got unknown field : %s=%s", itemSplit[0], itemSplit[1])
61+
}
62+
}
63+
}
64+
65+
if found {
66+
m[num] = d
67+
}
68+
}
69+
}
70+
return m, nil
71+
}
72+
73+
func (APIImplementor) Rescan() error {
74+
cmd := "Update-HostStorageCache"
75+
_, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
76+
if err != nil {
77+
return fmt.Errorf("error updating host storage cache %v", err)
78+
}
79+
return nil
80+
}
81+
82+
func (APIImplementor) IsDiskInitialized(diskID string) (bool, error) {
83+
cmd := fmt.Sprintf("Get-Disk -Number %s | Where partitionstyle -eq 'raw'", diskID)
84+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
85+
if err != nil {
86+
return false, fmt.Errorf("error checking initialized status of disk %s: %v, %v", diskID, out, err)
87+
}
88+
if len(out) == 0 {
89+
// disks with raw initialization not detected
90+
return true, nil
91+
}
92+
return false, nil
93+
}
94+
95+
func (APIImplementor) InitializeDisk(diskID string) error {
96+
cmd := fmt.Sprintf("Initialize-Disk -Number %s -PartitionStyle MBR", diskID)
97+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
98+
if err != nil {
99+
return fmt.Errorf("error initializing disk %s: %v, %v", diskID, out, err)
100+
}
101+
return nil
102+
}
103+
104+
func (APIImplementor) PartitionsExist(diskID string) (bool, error) {
105+
cmd := fmt.Sprintf("Get-Partition | Where DiskNumber -eq %s", diskID)
106+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
107+
if err != nil {
108+
return false, fmt.Errorf("error checking presence of partitions on disk %s: %v, %v", diskID, out, err)
109+
}
110+
if len(out) > 0 {
111+
// disk has paritions in it
112+
return true, nil
113+
}
114+
return false, nil
115+
}
116+
117+
func (APIImplementor) CreatePartition(diskID string) error {
118+
cmd := fmt.Sprintf("New-Partition -DiskNumber %s -UseMaximumSize", diskID)
119+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
120+
if err != nil {
121+
return fmt.Errorf("error creating parition on disk %s: %v, %v", diskID, out, err)
122+
}
123+
return nil
124+
}

0 commit comments

Comments
 (0)