22
22
# check input params
23
23
$dev_string = untaint(shift @ARGV);
25
($euca_home, $ip, $store, $encrypted_password) = parse_devstring($dev_string);
25
($euca_home, $ip, $store, $encrypted_password, $lun, $auth_mode) = parse_devstring($dev_string);
27
if(length($euca_home) <= 0) {
28
if (length($euca_home) <= 0) {
28
29
print STDERR "EUCALYPTUS path is not defined.\n";
32
33
$KEY_PATH = $euca_home."/var/lib/eucalyptus/keys/node-pk.pem";
34
$password = decrypt_password($encrypted_password);
36
login_target($ip, $store, $password);
38
#wait for device to be ready
42
print get_device_name($store);
35
if ((length($lun) > 0) && ($lun > -1)) {
36
# check if a session corresponding to the store exists
37
if (get_session($ARGV[0]) == 1) {
41
# else login to session
42
if(length($auth_mode) > 0) {
43
$password = "not_required";
45
$password = decrypt_password($encrypted_password);
47
if(length($password) <= 0) {
48
print STDERR "Unable to decrypt target password. Aborting.\n";
50
login_target($ip, $store, $password, $auth_mode);
54
$localdevname = get_device_name_from_lun($store, $lun);
55
print "$localdevname";
57
# make sure device exists on the filesystem
58
for ($trycount=0; $trycount < 12; $trycount++) {
59
if ( -e "$localdevname" ) {
66
$password = decrypt_password($encrypted_password);
68
if(length($password) <= 0) {
69
print STDERR "Unable to decrypt target password. Aborting.\n";
71
login_target($ip, $store, $password);
72
#wait for device to be ready
74
$localdevname = get_device_name($store);
75
print "$localdevname";
77
# make sure device exists on the filesystem
78
for ($trycount=0; $trycount < 12; $trycount++) {
79
if ( -e "$localdevname" ) {
44
87
sub parse_devstring {
45
88
my ($dev_string) = @_;
56
99
while(<DISCOVERY>) {};
58
if(!open USERNAME, "iscsiadm -m node -T $store --op=update --name node.session.auth.username --value=$ISCSI_USER |") {
101
if($password ne "not_required") {
102
if(!open USERNAME, "iscsiadm -m node -T $store --op=update --name node.session.auth.username --value=$ISCSI_USER |") {
59
103
print "Could not update target username";
65
if(!open PASSWD, "iscsiadm -m node -T $store --op=update --name node.session.auth.password --value=$passwd |") {
107
while(<USERNAME>) {};
109
if(!open PASSWD, "iscsiadm -m node -T $store --op=update --name node.session.auth.password --value=$passwd |") {
66
110
print "Could not update target password";
72
118
if(!open LOGIN, "iscsiadm -m node -T $store -l |") {
73
119
print "Could not login to target";
124
while(<LOGIN>) {$login = $login.$_;};
125
if(length($login) <= 0) {
126
print STDERR "Unable to login to target. Aborting.\n";
80
131
sub decrypt_password {
201
sub get_device_name_from_lun {
202
my ($store, $lun) = @_;
205
for ($i = 0; $i < $num_retries; ++$i) {
206
if(!open GETSESSION, "iscsiadm -m session -P 3 |") {
207
print STDERR "Could not get iscsi session information";
214
while (<GETSESSION>) {
215
if ($_ =~ /Target: (.*)\n/) {
216
last if $attach_seen == 0;
217
$found_target = 1 if $1 eq $store;
220
} elsif ($_ =~ /.*Attached scsi disk ([a-zA-Z0-9]+).*\n/) {
221
if ($found_target == 1 && $found_lun == 1) {
225
} elsif ($_ =~ /.*Lun: (.*)\n/) {
226
$found_lun = 1 if $1 eq $lun;
235
if(!open GETSESSION, "iscsiadm -m session -R |") {
236
print STDERR "Could not get iscsi session information";