Example #1
0
def register_target(target):
    """ registers a target
    
        target is a Target object
    """
    try:
        command.execute_cmd("%s --op new --tid=\"%s\" --params Name=\"%s\"" % 
                            (get_iscsi_scst_path(), target.tid, target.name())) 
        
        if len(target.params()) > 0:
            params = ["%s=\"%s\"" % (p[0], p[1]) for p in target.params()]
            params = ",".join(params)
            command.execute_cmd("%s --op update --tid=\"%s\" --params %s" % 
                                (get_iscsi_scst_path(), target.tid, params)) 
        
        if target.auth_username() or target.auth_secret_hash():
            try:
                secret = base64.standard_b64decode(target.auth_secret_hash())
                secret = [chr((ord(i) - 13) % 256) for i in secret]
                secret = "".join(secret)
                if secret[-1] == chr(0):
                    secret = secret[:-1]
                if len(secret) < 12 or len(secret) > 256:
                    raise Exception("Invalid secret")
                
                command.execute_cmd("%s --op new --tid=\"%s\" --user --params OutgoingUser=\"%s\",Password=\"%s\"" % (get_iscsi_scst_path(),
                                                                                                                      target.tid, target.auth_username(), secret)) 
            except Exception as e:
                raise ScstException("Failed to add user to target", e) 
    except Exception as e:
        raise ScstException("Failed to register target", e)
Example #2
0
def change_target_auth(target):
    """ Change the target outgoing authentication
    
        target is a Target object
    """
    try:
        secret = base64.standard_b64decode(target.auth_secret_hash())
        secret = [chr((ord(i) - 13) % 256) for i in secret]
        secret = "".join(secret)
        if secret[-1] == chr(0):
            secret = secret[:-1]
        # this is totally a hack, but iscsi-scst-adm doesn't support to update user password
        
        try:
            command.execute_cmd("%s --op delete --tid=\"%s\" --user --params OutgoingUser=\"%s\"" % (get_iscsi_scst_path(), target.tid, target.auth_username())) 
        except:
            pass
        command.execute_cmd("%s --op new --tid=\"%s\" --user --params OutgoingUser=\"%s\",Password=\"%s\"" % (get_iscsi_scst_path(), 
                                                                                                              target.tid, target.auth_username(), secret)) 
    except Exception as e:
        raise ScstException("Failed to update user in target", e)