def add_acl(target_name, acl): try: if not target_name: raise Exception('No Target Specified') if not acl: raise Exception('No ACL specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') acls = target['acl'] # First remove ALL from the ACL list if acls and 'ALL' in acls: cmd = 'tgtadm --lld iscsi --mode target --op unbind --tid %d -I ALL' % target['tid'] (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception('Error removind wildcard ACL : %s' % err) cmd = 'tgtadm --lld iscsi --mode target --op bind --tid %d -I %s' % ( target['tid'], acl) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error adding ACL: %s' % str(e)
def delete_target(name): try: target, err = get_target(name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') cmd = 'tgtadm --lld iscsi --mode target --op delete --tid %d' % target['tid'] (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error deleting target : %s' % str(e)
def delete_target(name): try: target, err = get_target(name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') cmd = 'tgtadm --lld iscsi --mode target --op delete --tid %d' % target[ 'tid'] (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error deleting target : %s' % str(e)
def create_target(name): try: targets, err = get_targets() if err: raise Exception(err) highest_tid = 0 if targets: for t in targets: if int(t['tid']) > highest_tid: highest_tid = int(t['tid']) new_tid = highest_tid + 1 target_name = 'com.fractalio.integralstor:%s' % name cmd = 'tgtadm --lld iscsi --mode target --op new --tid %d -T %s' % ( new_tid, target_name) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error creating target : %s' % str(e)
def get_service_status(service): d = {} try: (ret, rc), err = command.execute_with_rc( 'service %s status' % service[0]) if err: raise Exception(err) d['status_code'] = rc if rc == 0: d['status_str'] = 'Running' elif rc == 3: d['status_str'] = 'Stopped' elif rc == 1: d['status_str'] = 'Error' d['output_str'] = '' out, err = command.get_output_list(ret) if err: raise Exception(err) if out: d['output_str'] += ','.join(out) err, e = command.get_error_list(ret) if e: raise Exception(e) if err: d['output_str'] += ','.join(err) except Exception, e: return None, 'Error retrieving service status : %s' % str(e)
def get_all_disks_by_name(): """Get all disks by their sd* names Returns a list of all disks by name (sda/sbd, etc) in the sytem """ dl = [] try: cmd_dl = "/usr/sbin/smartctl --scan" (ret, rc), err = command.execute_with_rc(cmd_dl) if err: raise Exception(err) disk_list, err = command.get_output_list(ret) if err: raise Exception(err) if ret: # Regex to capture "/dev/sdX" reg_exp_dl = re.compile("(/dev/[a-z]+)") for line in disk_list: d = {} if reg_exp_dl.search(line): result_dl = re.search(r'/dev/sd[a-z]+', line) result_dl1 = re.search(r'/dev/(sd[a-z]+)', line) if result_dl: d["full_path"] = result_dl.group() dname = result_dl1.groups()[0] r = re.match('^sd[a-z]+', dname) d["name"] = r.group() dl.append(d) # print "disk list info: ", dl except Exception, e: return None, "Error retrieving disks by name : %s" % str(e)
def generate_disks_status_section(f): try: disk_names, err = disks.get_all_disks_by_name() if err: raise Exception(err) # print audit_list f.write( '--------------------- Disk status BEGIN ------------------------\n\n' ) for dn_dict in disk_names: cmd = 'smartctl --all %s' % dn_dict['full_path'] # print cmd ret, err = command.execute(cmd) if err: raise Exception(err) lines, err = command.get_output_list(ret) if err: raise Exception(err) f.write('\n'.join(lines)) f.write('\n') f.write( '--------------------- Disk status END ------------------------\n\n' ) except Exception, e: return False, 'Error generating disk status section: %s' % str(e)
def change_password(username, pswd): try: if not username: raise Exception('No username specified') d, err = get_local_user(username) if not d: if err: raise Exception('Error locating user : %s' % err) else: raise Exception('Error locating user') lines, err = command.get_command_output(r'echo %s:%s|chpasswd' % (username, pswd), shell=True) if err: raise Exception(err) if 'smb_user' in d and d['smb_user']: #lines, err = command.get_command_output(r'smbpasswd -s %s'%(username), "%s\n%s"%(pswd, pswd)) (ret, rc), err = command.execute_with_conf_and_rc( r'smbpasswd -s %s' % (username), "%s\n%s" % (pswd, pswd)) if rc == 0: lines, er = command.get_output_list(ret) if er: raise Exception(er) else: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) except Exception, e: return False, 'Error changing local user password : %s' % str(e)
def delete_lun(target_name, backing_store): try: if not target_name: raise ('No target name specified') if not backing_store: raise ('No backing store path specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found.') luns = target['luns'] if not luns: raise Exception('Specified target does not have any LUNs.') lun = None for tl in luns: if tl['path'] == backing_store: lun = tl if not lun: raise Exception('Specified LUN not found.') cmd = 'tgtadm --lld iscsi --mode logicalunit --op delete --tid %d --lun %d' % ( target['tid'], lun['id']) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error Deleting Logical Unit: %s' % str(e)
def change_password(username, pswd): try: if not username: raise Exception('No username specified') d, err = get_local_user(username) if not d: if err: raise Exception('Error locating user : %s' % err) else: raise Exception('Error locating user') lines, err = command.get_command_output( r'echo %s:%s|chpasswd' % (username, pswd), shell=True) if err: raise Exception(err) if 'smb_user' in d and d['smb_user']: #lines, err = command.get_command_output(r'smbpasswd -s %s'%(username), "%s\n%s"%(pswd, pswd)) (ret, rc), err = command.execute_with_conf_and_rc( r'smbpasswd -s %s' % (username), "%s\n%s" % (pswd, pswd)) if rc == 0: lines, er = command.get_output_list(ret) if er: raise Exception(er) else: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) except Exception, e: return False, 'Error changing local user password : %s' % str(e)
def remove_acl(target_name, acl): try: if not target_name: raise Exception('No Target Specified') if not acl: raise Exception('No ACL specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') acls = target['acl'] if not acls: raise Exception('No ACLs found') if acl not in acls: raise Exception('Specified ACL not found') cmd = 'tgtadm --lld iscsi --mode target --op unbind --tid %d -I %s' % ( target['tid'], acl) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: # Could be an initiator name so try this.. cmd = 'tgtadm --lld iscsi --mode target --op unbind --tid %d --initiator-name %s' % ( target['tid'], acl) ret, rc = command.execute_with_rc(cmd) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error removing ACL: %s' % str(e)
def create_lun(target_name, backing_store): try: if not target_name: raise Exception('No Target Specified') if not backing_store: raise Exception('No backing storage volume specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') luns = target['luns'] if not luns: raise Exception('Error retrieving LUN list') highest_lun_id = 0 for lun in luns: if lun['id'] > highest_lun_id: highest_lun_id = lun['id'] new_lun_id = highest_lun_id + 1 cmd = 'tgtadm --lld iscsi --mode logicalunit --op new --tid %d --lun %d --backing-store %s' % ( int(target['tid']), new_lun_id, backing_store) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error creating LUN : %s' % str(e)
def remove_user_authentication(target_name, username, authentication_type): try: if not target_name: raise "Target Not Specified" if not username: raise "Username Not Specified" target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found.') cmd = 'tgtadm --lld iscsi --mode account --op unbind --tid %d --user %s' % ( target['tid'], username) if authentication_type == 'outgoing': cmd += ' --outgoing' (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error removing user autentication: %s' % str(e)
def create_local_user(username, name, pswd, gid=None, smb_user=True): try: # First check if user exists. if so kick out ul, err = get_local_users() if ul: for ud in ul: if ud["username"] == username: raise Exception( "Error creating user. The user \"%s\" already exists. " % username) elif err: raise Exception("Error retrieving user list : %s" % err) enc_pswd = crypt.crypt(pswd, "28") use_salt, err = config.use_salt() if err: raise Exception(err) if use_salt: import salt.client client = salt.client.LocalClient() if gid: rc = client.cmd('*', 'user.add', [username, None, gid]) else: rc = client.cmd('*', 'user.add', [username]) # print rc if not rc: error_list.append("Error creating the username") for hostname, status in rc.items(): if not status: error_list.append("Error creating the username on node" % hostname) rc = client.cmd('*', 'shadow.set_password', [username, enc_pswd]) for hostname, status in rc.items(): if not status: error_list.append( "Error setting the password for username on GRIDCell %s" % hostname) rc = client.cmd('*', 'user.chfullname', [username, "integralstor_user_%s" % name]) for hostname, status in rc.items(): if not status: error_list.append( "Error setting the name for username on node %s" % hostname) else: # print '1' if gid: cmd_to_run = 'useradd -g %s -p %s -c integralstor_user_%s %s' % ( gid, enc_pswd, name, username) else: cmd_to_run = 'useradd -p %s -c integralstor_user_%s %s' % ( enc_pswd, name, username) lines, err = command.get_command_output(cmd_to_run) # print '2' # print lines, err if err: raise Exception(err) if smb_user: # print '/usr/bin/pdbedit -d 1 -t -a -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd) # Now all set to create samba user # print '3' #lines, err = command.get_command_output(r'/usr/bin/pdbedit -d 1 -t -a -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd)) (ret, rc), err = command.execute_with_conf_and_rc( r'/usr/bin/pdbedit -d 1 -t -a -u %s -f %s' % (username, name), "%s\n%s" % (pswd, pswd)) if rc == 0: lines, er = command.get_output_list(ret) if er: raise Exception(er) else: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) # print '4' # print lines, err except Exception, e: return False, 'Error creating local user : %s' % str(e)
def generate_targets_conf(new_user=None): try: targets, err = get_targets() if err: raise Exception(err) config_targets, err = load_targets_conf() if err: raise Exception(err) with open('/tmp/targets.conf', 'w') as f: f.write('default-driver iscsi\n') for target in targets: f.write('\n<target %s>\n' % target['iqn']) for lun in target['luns']: if lun['path'] and lun['path'] != 'None': f.write(' backing-store %s\n' % lun['path']) for acl in target['acl']: if acl != 'ALL': f.write(' initiator-address %s\n' % acl) config_target = None # First process new users if any if new_user and new_user['iqn'] == target['iqn']: if new_user['type'] == 'incoming': f.write(' incominguser %s %s\n' % (new_user['username'], new_user['pswd'])) else: f.write(' outgoinguser %s %s\n' % (new_user['username'], new_user['pswd'])) for account in target['accounts']: # Now process existing users. Take the list from tgtadm, # get pswds from existing config file and write it out # again for ct in config_targets: if ct['iqn'] == target['iqn']: config_target = ct break if account['type'] == 'incoming': for ctiu in config_target['incoming_users']: if ctiu['username'] == account['user']: f.write(' incominguser %s %s\n' % (account['user'], ctiu['pswd'])) else: for ctiu in config_target['outgoing_users']: if ctiu['username'] == account['user']: f.write(' outgoinguser %s %s\n' % (account['user'], ctiu['pswd'])) f.write('</target>\n\n') f.flush() f.close() shutil.move('/tmp/targets.conf', '/etc/tgt/targets.conf') cmd = 'tgt-admin -e' (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) except Exception, e: return False, 'Error generating ISCSI config file: %s' % str(e)
def get_sysd_service_status(service): d = {} d['status'] = {} d['status']['rc'] = '' d['status']['status_str'] = '' d['status']['output_str'] = '' d['is_active'] = {} d['is_active']['rc'] = '' d['is_active']['status_str'] = '' d['is_active']['output_str'] = '' d['is_failed'] = {} d['is_failed']['rc'] = '' d['is_failed']['status_str'] = '' d['is_failed']['output_str'] = '' d['is_enabled'] = {} d['is_enabled']['rc'] = '' d['is_enabled']['status_str'] = '' d['is_enabled']['output_str'] = '' try: (ret, rc), err = command.execute_with_rc( 'systemctl status %s' % service[0]) if err: raise Exception(err) d['status']['rc'] = rc out, err1 = command.get_output_list(ret) if err1: raise Exception(err1) if out: d['status']['output_str'] += ','.join(out) err2, e = command.get_error_list(ret) if e: raise Exception(e) if err2: d['status']['output_str'] += ','.join(err2) if not err: (ret, rc), err = command.execute_with_rc( 'systemctl is-failed %s' % service[0]) if err: raise Exception(err) d['is_failed']['rc'] = rc out, err = command.get_output_list(ret) if err: raise Exception(err) if out: d['is_failed']['output_str'] += ','.join(out) if rc == 0: d['is_failed']['status_str'] = "Failed" d['status']['status_str'] = "Failed" d['status']['output_str'] += ','.join(out) else: (ret, rc), err = command.execute_with_rc( 'systemctl is-active %s' % service[0]) if err: raise Exception(err) d['is_active']['rc'] = rc out, err = command.get_output_list(ret) if err: raise Exception(err) if out: d['is_active']['output_str'] += ','.join(out) if rc == 0: d['is_active']['status_str'] = "Active" d['status']['status_str'] = "Active" d['status']['output_str'] += ','.join(out) elif rc == 3: d['is_active']['status_str'] = "Inactive" d['status']['status_str'] = "Inactive" d['status']['output_str'] += ','.join(out) else: d['status']['status_str'] = "Unknown State" (ret, rc), err = command.execute_with_rc( 'systemctl is-enabled %s' % service[0]) if err: raise Exception(err) d['is_enabled']['rc'] = rc out, err = command.get_output_list(ret) if err: raise Exception(err) if out: d['is_enabled']['output_str'] += ','.join(out) if not rc: d['is_enabled']['status_str'] = "Enabled" else: d['is_enabled']['status_str'] = "Disabled" except Exception, e: return None, 'Error retrieving service status : %s' % str(e)
def display_status(): try: hostname = socket.gethostname() use_salt, err = config.use_salt() if err: raise Exception(err) if use_salt: print "Salt master service status :", (r, rc), err = command.execute_with_rc( 'service salt-master status') if err: raise Exception(err) l, err = command.get_output_list(r) if err: raise Exception(err) if l: print '\n'.join(l) else: l, err = command.get_error_list(r) if err: raise Exception(err) if l: print '\n'.join(l) print "Salt minion service status :", (r, rc), err = command.execute_with_rc( 'service salt-minion status') if err: raise Exception(err) l, err = command.get_output_list(r) if err: raise Exception(err) if l: print '\n'.join(l) else: l, err = command.get_error_list(r) if err: raise Exception(err) print l if l: print '\n'.join(l) print "Samba service status :", (r, rc), err = command.execute_with_rc('service smb status') if err: raise Exception(err) l, err = command.get_output_list(r) if err: raise Exception(err) if l: print '\n'.join(l) else: l, err = command.get_error_list(r) if err: raise Exception(err) if l: print '\n'.join(l) print "Winbind service status :", (r, rc), err = command.execute_with_rc('service winbind status') if err: raise Exception(err) l, err = command.get_output_list(r) if err: raise Exception(err) if l: print '\n'.join(l) else: l, err = command.get_error_list(r) if err: raise Exception(err) if l: print '\n'.join(l) except Exception, e: print "Error displaying system status : %s" % e return -1
def add_user_authentication(target_name, authentication_type, username, password): try: tid = -1 if not authentication_type: raise Exception('No authentication type specified') if not target_name: raise Exception('No target specified') if not username: raise Exception('No username specified') if not password: raise Exception('No password specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found.') cmd1 = 'tgtadm --lld iscsi --mode account --op new --user %s --password %s' % ( username, password) (ret, rc), err = command.execute_with_rc(cmd1) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) cmd2 = 'tgtadm --lld iscsi --mode account --op bind --tid %d --user %s' % ( target['tid'], username) if authentication_type == 'outgoing': cmd2 += ' --outgoing' (ret, rc), err = command.execute_with_rc(cmd2) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) new_user_dict = {} new_user_dict['iqn'] = target['iqn'] new_user_dict['username'] = username new_user_dict['type'] = authentication_type new_user_dict['pswd'] = password conf, err = generate_targets_conf(new_user_dict) if err: raise Exception(err) except Exception, e: return False, 'Error Adding User: %s' % str(e)
def create_local_user(username, name, pswd, gid=None, smb_user=True): try: # First check if user exists. if so kick out ul, err = get_local_users() if ul: for ud in ul: if ud["username"] == username: raise Exception( "Error creating user. The user \"%s\" already exists. " % username) elif err: raise Exception("Error retrieving user list : %s" % err) enc_pswd = crypt.crypt(pswd, "28") use_salt, err = config.use_salt() if err: raise Exception(err) if use_salt: import salt.client client = salt.client.LocalClient() if gid: rc = client.cmd('*', 'user.add', [username, None, gid]) else: rc = client.cmd('*', 'user.add', [username]) # print rc if not rc: error_list.append("Error creating the username") for hostname, status in rc.items(): if not status: error_list.append( "Error creating the username on node" % hostname) rc = client.cmd('*', 'shadow.set_password', [username, enc_pswd]) for hostname, status in rc.items(): if not status: error_list.append( "Error setting the password for username on GRIDCell %s" % hostname) rc = client.cmd('*', 'user.chfullname', [username, "integralstor_user_%s" % name]) for hostname, status in rc.items(): if not status: error_list.append( "Error setting the name for username on node %s" % hostname) else: # print '1' if gid: cmd_to_run = 'useradd -g %s -p %s -c integralstor_user_%s %s' % ( gid, enc_pswd, name, username) else: cmd_to_run = 'useradd -p %s -c integralstor_user_%s %s' % ( enc_pswd, name, username) lines, err = command.get_command_output(cmd_to_run) # print '2' # print lines, err if err: raise Exception(err) if smb_user: # print '/usr/bin/pdbedit -d 1 -t -a -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd) # Now all set to create samba user # print '3' #lines, err = command.get_command_output(r'/usr/bin/pdbedit -d 1 -t -a -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd)) (ret, rc), err = command.execute_with_conf_and_rc( r'/usr/bin/pdbedit -d 1 -t -a -u %s -f %s' % (username, name), "%s\n%s" % (pswd, pswd)) if rc == 0: lines, er = command.get_output_list(ret) if er: raise Exception(er) else: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) # print '4' # print lines, err except Exception, e: return False, 'Error creating local user : %s' % str(e)
def add_acl(target_name, acl): try: if not target_name: raise Exception('No Target Specified') if not acl: raise Exception('No ACL specified') target, err = get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') acls = target['acl'] # First remove ALL from the ACL list if acls and 'ALL' in acls: cmd = 'tgtadm --lld iscsi --mode target --op unbind --tid %d -I ALL' % target[ 'tid'] (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception('Error removind wildcard ACL : %s' % err) cmd = 'tgtadm --lld iscsi --mode target --op bind --tid %d -I %s' % ( target['tid'], acl) (ret, rc), err = command.execute_with_rc(cmd) if err: raise Exception(err) if rc != 0: err = '' tl, er = command.get_output_list(ret) if er: raise Exception(er) if tl: err = ','.join(tl) tl, er = command.get_error_list(ret) if er: raise Exception(er) if tl: err = err + ','.join(tl) raise Exception(err) conf, err = generate_targets_conf() if err: raise Exception(err) except Exception, e: return False, 'Error adding ACL: %s' % str(e)