@@ -11,40 +11,31 @@ import (
1111)
1212
1313var (
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
2223func 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}
0 commit comments