Skip to content

Commit d7b7d59

Browse files
authored
Merge pull request #3 from Seagate/feat/iscsi-resync
feat(iscsi-resync): v0.5.2 resync to kubernetes-csi/csi-lib-iscsi
2 parents c004506 + 760493c commit d7b7d59

File tree

9 files changed

+456
-1377
lines changed

9 files changed

+456
-1377
lines changed

example/main.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,31 @@ import (
1111
)
1212

1313
var (
14-
portals = flag.String("portals", "192.168.1.112:3260", "Comma delimited. Eg: 1.1.1.1,2.2.2.2")
15-
iqn = flag.String("iqn", "iqn.2010-10.org.openstack:volume-95739000-1557-44f8-9f40-e9d29fe6ec47", "")
16-
username = flag.String("username", "3aX7EEf3CEgvESQG75qh", "")
17-
password = flag.String("password", "eJBDC7Bt7WE3XFDq", "")
18-
lun = flag.Int("lun", 1, "")
19-
debug = flag.Bool("debug", false, "enable logging")
14+
portals = flag.String("portals", "192.168.1.112:3260", "Comma delimited. Eg: 1.1.1.1,2.2.2.2")
15+
iqn = flag.String("iqn", "iqn.2010-10.org.openstack:volume-95739000-1557-44f8-9f40-e9d29fe6ec47", "")
16+
multipath = flag.Bool("multipath", false, "")
17+
username = flag.String("username", "3aX7EEf3CEgvESQG75qh", "")
18+
password = flag.String("password", "eJBDC7Bt7WE3XFDq", "")
19+
lun = flag.Int("lun", 1, "")
20+
debug = flag.Bool("debug", false, "enable logging")
2021
)
2122

2223
func main() {
2324
flag.Parse()
24-
tgtps := strings.Split(*portals, ",")
25+
tgtp := strings.Split(*portals, ",")
2526
if *debug {
2627
iscsi.EnableDebugLogging(os.Stdout)
2728
}
2829

29-
var targets []iscsi.TargetInfo
30-
31-
for _, tgtp := range tgtps {
32-
parts := strings.Split(tgtp, ":")
33-
targets = append(targets, iscsi.TargetInfo{
34-
// Specify the target iqn we're dealing with
35-
Iqn: *iqn,
36-
Portal: parts[0],
37-
Port: parts[1],
38-
})
39-
}
40-
4130
// You can utilize the iscsiadm calls directly if you wish, but by creating a Connector
4231
// you can simplify interactions to simple calls like "Connect" and "Disconnect"
43-
c := &iscsi.Connector{
32+
c := iscsi.Connector{
4433
// Our example uses chap
4534
AuthType: "chap",
46-
// List of targets must be >= 1 (>1 signals multipath/mpio)
47-
Targets: targets,
35+
// Specify the target iqn we're dealing with
36+
TargetIqn: *iqn,
37+
// List of portals must be >= 1 (>1 signals multipath/mpio)
38+
TargetPortals: tgtp,
4839
// CHAP can be setup up for discovery as well as sessions, our example
4940
// device only uses CHAP security for sessions, for those that use Discovery
5041
// as well, we'd add a DiscoverySecrets entry the same way
@@ -54,6 +45,8 @@ func main() {
5445
SecretsType: "chap"},
5546
// Lun is the lun number the devices uses for exports
5647
Lun: int32(*lun),
48+
// Multipath indicates that we want to configure this connection as a multipath device
49+
Multipath: *multipath,
5750
// Number of times we check for device path, waiting for CheckInterval seconds inbetween each check (defaults to 10 if omitted)
5851
RetryCount: 11,
5952
// CheckInterval is the time in seconds to wait inbetween device path checks when logging in to a target
@@ -62,21 +55,21 @@ func main() {
6255

6356
// Now we can just issue a connection request using our Connector
6457
// A succesful connection will include the device path to access our iscsi volume
65-
path, err := c.Connect()
58+
path, err := iscsi.Connect(c)
6659
if err != nil {
67-
log.Printf("Error returned from c.Connect: %s", err.Error())
60+
log.Printf("Error returned from iscsi.Connect: %s", err.Error())
6861
os.Exit(1)
6962
}
7063

71-
log.Printf("Connected device at path: %s\n", path)
72-
time.Sleep(3 * time.Second)
73-
74-
// This will disconnect the volume
75-
if err := c.DisconnectVolume(); err != nil {
76-
log.Printf("Error returned from c.DisconnectVolume: %s", err.Error())
64+
if path == "" {
65+
log.Printf("Failed to connect, didn't receive a path, but also no error!")
7766
os.Exit(1)
7867
}
7968

80-
// This will disconnect the session as well as clear out the iscsi DB entries associated with it
81-
c.Disconnect()
69+
log.Printf("Connected device at path: %s\n", path)
70+
time.Sleep(3 * time.Second)
71+
72+
// Disconnect is easy as well, we don't need the full Connector any more, just the Target IQN and the Portals
73+
/// this should disconnect the volume as well as clear out the iscsi DB entries associated with it
74+
iscsi.Disconnect(c.TargetIqn, c.TargetPortals)
8275
}

go.mod

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
module github.com/kubernetes-csi/csi-lib-iscsi
22

3-
go 1.15
4-
5-
require (
6-
github.com/prashantv/gostub v1.0.0
7-
github.com/stretchr/testify v1.7.0
8-
)
3+
go 1.16

go.sum

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/prashantv/gostub v1.0.0 h1:wTzvgO04xSS3gHuz6Vhuo0/kvWelyJxwNS0IRBPAwGY=
6-
github.com/prashantv/gostub v1.0.0/go.mod h1:dP1v6T1QzyGJJKFocwAU0lSZKpfjstjH8TlhkEU0on0=
7-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
9-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
11-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
13-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)