@@ -11,31 +11,29 @@ import (
11
11
)
12
12
13
13
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
- 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" )
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" )
21
20
)
22
21
23
22
func main () {
24
23
flag .Parse ()
25
- tgtp := strings .Split (* portals , "," )
24
+ tgtps := strings .Split (* portals , "," )
26
25
if * debug {
27
26
iscsi .EnableDebugLogging (os .Stdout )
28
27
}
29
28
30
29
// You can utilize the iscsiadm calls directly if you wish, but by creating a Connector
31
30
// you can simplify interactions to simple calls like "Connect" and "Disconnect"
32
- c := iscsi.Connector {
31
+ c := & iscsi.Connector {
33
32
// Our example uses chap
34
33
AuthType : "chap" ,
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 ,
34
+ // List of targets must be >= 1 (>1 signals multipath/mpio)
35
+ TargetIqn : * iqn ,
36
+ TargetPortals : tgtps ,
39
37
// CHAP can be setup up for discovery as well as sessions, our example
40
38
// device only uses CHAP security for sessions, for those that use Discovery
41
39
// as well, we'd add a DiscoverySecrets entry the same way
@@ -45,8 +43,6 @@ func main() {
45
43
SecretsType : "chap" },
46
44
// Lun is the lun number the devices uses for exports
47
45
Lun : int32 (* lun ),
48
- // Multipath indicates that we want to configure this connection as a multipath device
49
- Multipath : * multipath ,
50
46
// Number of times we check for device path, waiting for CheckInterval seconds inbetween each check (defaults to 10 if omitted)
51
47
RetryCount : 11 ,
52
48
// CheckInterval is the time in seconds to wait inbetween device path checks when logging in to a target
@@ -55,21 +51,21 @@ func main() {
55
51
56
52
// Now we can just issue a connection request using our Connector
57
53
// A succesful connection will include the device path to access our iscsi volume
58
- path , err := iscsi .Connect (c )
54
+ path , err := c .Connect ()
59
55
if err != nil {
60
- log .Printf ("Error returned from iscsi.Connect: %s" , err .Error ())
61
- os .Exit (1 )
62
- }
63
-
64
- if path == "" {
65
- log .Printf ("Failed to connect, didn't receive a path, but also no error!" )
56
+ log .Printf ("Error returned from c.Connect: %s" , err .Error ())
66
57
os .Exit (1 )
67
58
}
68
59
69
60
log .Printf ("Connected device at path: %s\n " , path )
70
61
time .Sleep (3 * time .Second )
71
62
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 )
63
+ // This will disconnect the volume
64
+ if err := c .DisconnectVolume (); err != nil {
65
+ log .Printf ("Error returned from c.DisconnectVolume: %s" , err .Error ())
66
+ os .Exit (1 )
67
+ }
68
+
69
+ // This will disconnect the session as well as clear out the iscsi DB entries associated with it
70
+ c .Disconnect ()
75
71
}
0 commit comments