Exemplo n.º 1
0
def listMappings(
    ServiceName: str,
    Application: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None
) -> namedtuple("listMappingsResult", ["retcode", 'stdout', 'stderr']):
    """ list all mappings under the application

    if retcode equals 0, then stdout returns a list of mappings

    else: stderr will return the error message

    :param ServiceName: Data Integration Service
    :param Application:
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param ResilienceTimeout:
    :return: namedtuple("listMappingsResult", ["retcode", 'stdout', 'stderr'])
    """
    subcmd = "ListMappings"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "ResilienceTimeout",
        "ServiceName",
        "Application",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        # format the stdout
        stdout = strip_ignored_cmd_messages(stdout)
        stdout = stdout.split("\n")[:-1]
    else:
        stderr += stdout

    ret = namedtuple("ListMappingsResult", ["retcode", 'stdout', 'stderr'])
    return ret(res.retcode, stdout, stderr)
Exemplo n.º 2
0
 def __init__(self, nodemeta_xml_file):
     mainLogger.info(
         "invoking the Nodemeta class to parse the nodemeta.xml( {0} )".
         format(nodemeta_xml_file))
     self.node_xml_file = nodemeta_xml_file
     doc = ds.parsexml_(self.node_xml_file)
     self.rootNode = doc.getroot()
     doc = None
Exemplo n.º 3
0
def getServiceStatus(
    ServiceName: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None
) -> namedtuple("GetServiceStatusResult", ['retcode', 'stdout', 'stderr']):
    """Get the service's Status

    True stands for it's enabled

    False stands for it's disabled

    :param ServiceName:
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return:
    """
    subcmd = "GetServiceStatus"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceName",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = True if stdout.upper().startswith("ENABLED") else False
    else:
        stderr += stdout

    getServiceStatusResult = namedtuple("GetServiceStatusResult",
                                        ['retcode', 'stdout', 'stderr'])
    return getServiceStatusResult(res.retcode, stdout, stderr)
Exemplo n.º 4
0
def listNodes(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
    NodeRole: str = "Service_compute",
) -> namedtuple("ListNodesResult", ['retcode', 'stdout', 'stderr']):
    """ list nodes of specified NodeRole
    retcode is int, 0 represents success, otherwise failure
    if retcode requals 0, the stdout will a list of nodes, and it must have one node, like [node1, node2].
    otherwise, the stderr will show the details of error

    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :param NodeRole: (Service_compute|Service|Compute) default is Service_compute
    :return: namedtuple("ListNodesResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "ListNodes "
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "NodeRole",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        stdout = stdout.splitlines()
    else:
        stderr += stdout

    listNodesResult = namedtuple("ListNodesResult",
                                 ['retcode', 'stdout', 'stderr'])
    return listNodesResult(res.retcode, stdout, stderr)
Exemplo n.º 5
0
def stopBlazeService(
    ServiceName: str,
    HadoopConnection: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None,
) -> namedtuple("stopBlazeServiceResult", ['retcode', 'stdout', 'stderr']):
    """ stop the Blaze Service

    if retcode equals 0, then it stops the Blaze Service successfully.

    otherwise, it fails to stop the Blaze Service.

    :param ServiceName: Data Integration Service
    :param HadoopConnection:  HADOOP [or using connectiontype_namedtupe.HADOOP]
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param ResilienceTimeout:
    :return: namedtuple("stopBlazeServiceResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "stopBlazeService"
    options = [
        "DomainName",
        "ServiceName",
        "UserName",
        "Password",
        "SecurityDomain",
        "ResilienceTimeout",
        "HadoopConnection",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        pass
    else:
        stderr += stdout
    stopBlazeServiceResult = namedtuple("stopBlazeServiceResult",
                                        ['retcode', 'stdout', 'stderr'])
    return stopBlazeServiceResult(res.retcode, stdout, stderr)
Exemplo n.º 6
0
def deployApplication(
    RepositoryService: str,
    OutputDirectory: str,
    ApplicationPath: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
) -> namedtuple("DeployApplicationResult", ['retcode', 'stdout', 'stderr']):
    """ deploy the application to .iar file

    if retcode equals 0, then the stdout returns the .iar file

    otherwise, the stderr returns the error message.

    :param RepositoryService: Model Repository Service
    :param OutputDirectory:
    :param ApplicationPath: "Project/Folder/application"
    :param DomainName:
    :param UserName:
    :param Password:
    :return: namedtuple("DeployApplicationResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "DeployApplication"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "RepositoryService",
        "OutputDirectory",
        "ApplicationPath",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        stdout = stdout[stdout.index("File [") +
                        6:stdout.index("] has been generate")]
    else:
        stderr += stdout
    deployApplicationResult = namedtuple("DeployApplicationResult",
                                         ['retcode', 'stdout', 'stderr'])
    return deployApplicationResult(res.retcode, stdout, stderr)
Exemplo n.º 7
0
def enableService(
    ServiceName: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None
) -> namedtuple("EnableServiceResult", ['retcode', 'stdout', 'stderr']):
    """ enable the service

    if retcode is 0, then it enables the service, otherwise, it will raise stderr.

    :param ServiceName:
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return:
    """
    subcmd = "EnableService"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceName",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)

    stderr = res.stderr
    stdout = res.stdout
    if res.retcode != 0:
        stderr += stdout

    mainLogger.info(res)
    enableServiceResult = namedtuple("EnableServiceResult",
                                     ['retcode', 'stdout', 'stderr'])
    return enableServiceResult(res.retcode, stdout, stderr)
Exemplo n.º 8
0
 def delete_node(self, node: dict) -> None:
     del_node = self.query.filter(
         self.__class__.id == node.get("id")).first()
     if del_node is not None:
         db.session.delete(del_node)
         db.session.commit()
         mainLogger.info("Delete the node: {0} successful".format(del_node))
     else:
         mainLogger.warn(
             "this node {0} is not existing, so couldn't delete it".format(
                 node))
Exemplo n.º 9
0
def startApplication(
    ServiceName: str,
    Application: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None
) -> namedtuple("StartApplicationResult", ['retcode', 'stdout', 'stderr']):
    """
    if retcode equals 0, then it stops the application successfully
    otherwise, it fails to stop it.

    :param ServiceName: Data Integration Service
    :param Application:
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param ResilienceTimeout:
    :return: namedtuple("StartApplicationResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "StartApplication"
    options = [
        "DomainName",
        "ServiceName",
        "UserName",
        "Password",
        "SecurityDomain",
        "ResilienceTimeout",
        "Application",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode != 0:
        stderr += stdout
    startApplicationResult = namedtuple("StartApplicationResult",
                                        ['retcode', 'stdout', 'stderr'])
    return startApplicationResult(res.retcode, stdout, stderr)
Exemplo n.º 10
0
def listServiceLevels(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ListServiceLevelsResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "ListServiceLevels"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        serviceLevels = stdout.split("\n\n")
        listServiceLevels_list = list()
        for serviceLevel in serviceLevels:
            stdout = serviceLevel.split("\n")
            listServiceLevels_dict = dict()
            for item in stdout:  # type: str
                a = re.split("[:=]", item, maxsplit=1)
                listServiceLevels_dict.setdefault(
                    a[0].lstrip().rstrip(), a[1].lstrip().rstrip().rstrip(":"))
            listServiceLevels_list.append(listServiceLevels_dict)
        stdout = listServiceLevels_list
    else:
        stderr += stdout

    listServiceLevelsResult = namedtuple("ListServiceLevelsResult",
                                         ['retcode', 'stdout', 'stderr'])
    return listServiceLevelsResult(res.retcode, stdout, stderr)
Exemplo n.º 11
0
def resetPassword(
    ResetUserName: str,
    ResetUserPassword: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ResetPasswordResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "ResetPassword"

    options = [
        "DomainName", "UserName", "Password", "SecurityDomain", "Gateway",
        "ResilienceTimeout", "ResetUserName"
    ]
    # for security reason, the ResetUserPassword will be set by the INFA_PASSWORD environment
    # options = ["DomainName", "UserName", "Password", "SecurityDomain", "Gateway", "ResilienceTimeout", "ResetUserName",
    #            "ResetUserPassword", ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    encrypted_password_Result = pmpasswd(passwd=ResetUserPassword)
    resetPasswordResult = namedtuple("ResetPasswordResult",
                                     ['retcode', 'stdout', 'stderr'])
    if encrypted_password_Result.retcode == 0:
        os.environ.setdefault("INFA_PASSWORD",
                              encrypted_password_Result.stdout)
    else:
        return resetPasswordResult(
            encrypted_password_Result.retcode, "",
            "Couldn't to generate the encrypted password. for {0}".format(
                encrypted_password_Result.stdout))
    mainLogger.debug(os.environ)
    res = run_cmd(cmd, env=os.environ)
    os.environ.pop("INFA_PASSWORD")
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode != 0:
        stderr += stdout

    return resetPasswordResult(res.retcode, stdout, stderr)
Exemplo n.º 12
0
def listConnectionOptions(
    ConnectionName: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None,
) -> namedtuple("ListConnectionOptionsResult", ['retcode', 'stdout', 'stderr'
                                                ]):
    subcmd = "ListConnectionOptions"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "ResilienceTimeout",
        "ConnectionName",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)

    stdout = res.stdout  # type: str
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        conn_options = stdout.split("\n")  # type: list
        stdout = dict()
        for option in conn_options:  # type: str
            option_name_value = option.split(":", maxsplit=1)
            option_name = option_name_value[0]
            option_value = option_name_value[1].lstrip().rstrip()
            if option_value.startswith("[") and option_value.endswith("]"):
                option_value = option_value[1:-1]
            stdout.setdefault(option_name, option_value)
    else:
        stderr += stdout
    listConnectionOptionsResult = namedtuple("ListConnectionOptionsResult",
                                             ['retcode', 'stdout', 'stderr'])

    return listConnectionOptionsResult(res.retcode, stdout, stderr)
Exemplo n.º 13
0
 def update_node(self, node: dict) -> None:
     upd_node = self.query.filter(
         self.__class__.id == node.get("id")).first()
     for key, value in node.items():
         if hasattr(upd_node, key):
             setattr(upd_node, key, value)
         else:
             mainLogger.warn(
                 "During the update, the {0}={1} is not for Node".format(
                     key, value))
     db.session.update(upd_node)
     db.session.commit()
     mainLogger.info("Updated the node: {0}".format(upd_node))
Exemplo n.º 14
0
def listLicenses(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ListLicensesResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "ListLicenses"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        mainLogger.info(stdout)
        licenses = stdout.split("\n")
        stdout = list()
        for license in licenses:
            name_sid = license.split(" ")
            licenseResult = namedtuple("LicenseResult",
                                       ["Name", "SerialNumber"])
            stdout.append(
                licenseResult(name_sid[0],
                              name_sid[1].lstrip("(").rstrip(")")))
    else:
        stderr += stdout

    listLicensesResult = namedtuple("ListLicensesResult",
                                    ['retcode', 'stdout', 'stderr'])
    return listLicensesResult(res.retcode, stdout, stderr)
Exemplo n.º 15
0
def disableService(
    ServiceName: str,
    Mode: str = "Complete",
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("DisableServiceResult", ['retcode', 'stdout', 'stderr']):
    """ disable the Service

    if retcode is 0, then it's disabled successfully, otherwise it will raise stderr

    :param ServiceName:
    :param Mode: (Complete|Abort|Stop) default is Complete
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return:
    """
    subcmd = "DisableService"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceName",
        "Mode",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    return res
Exemplo n.º 16
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.info("the Nodemeta_XML args is {0}".format(args))

        nodemeta_xml_file = args.get("Nodemeta_XML")

        output = {"retcode": 0, "stdout": "success"}
        try:
            load_metadata(nodemeta_xml_file=nodemeta_xml_file)
        except Exception as e:
            mainLogger.exception(str(e))
            messages = str(e.args)
            output = {"retcode": 1, "stdout": messages}
        return output
Exemplo n.º 17
0
def ping(
    ServiceName: str,
    NodeName: str = None,
    DomainName: str = None,
    GatewayAddress: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("PingResult", ['retcode', 'stdout', 'stderr']):
    """

    :param ServiceName:
    :param NodeName:
    :param DomainName:
    :param GatewayAddress:
    :param ResilienceTimeout:
    :return:
    """
    subcmd = "Ping"
    options = [
        "DomainName",
        "ServiceName",
        "GatewayAddress",
        "NodeName",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(
        domainname=DomainName,
        username=None,
        password=None,
        cmd=base_cmd,
        subcmd=subcmd,
        verify_username_password=False)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
    else:
        stderr += stdout

    pingResult = namedtuple("PingResult", ['retcode', 'stdout', 'stderr'])
    return pingResult(res.retcode, stdout, stderr)
Exemplo n.º 18
0
def backupContents(
    ServiceName: str,
    OutputFileName: str,
    DomainName: str = None,
    SecurityDomain: str = "Native",
    UserName: str = None,
    Password: str = None,
    OverwriteFile: False = None,
    Description: str = None,
    BackupSearchIndices: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("BackupContentsResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "BackupContents"
    options = [
        "DomainName",
        "SecurityDomain",
        "UserName",
        "Password",
        "ServiceName",
        "OutputFileName",
        "OverwriteFile",
        "Description",
        "BackupSearchIndices",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
    else:
        stderr += stdout
    backupContentsResult = namedtuple("BackupContentsResult",
                                      ['retcode', 'stdout', 'stderr'])
    return backupContentsResult(res.retcode, stdout, stderr)
Exemplo n.º 19
0
def listUserPrivileges(
    ServiceName: str,
    ExistingUserName: str,
    ExistingUserSecurityDomain: str = "Native",
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ListUserPrivilegesResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "ListUserPrivileges"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ExistingUserName",
        "ExistingUserSecurityDomain",
        "ServiceName",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        stdout = stdout.splitlines()
    else:
        stderr += stdout
    listUserPrivilegesResult = namedtuple("ListUserPrivilegesResult",
                                          ['retcode', 'stdout', 'stderr'])
    return listUserPrivilegesResult(res.retcode, stdout, stderr)
Exemplo n.º 20
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.info("the pmpasswd args is {0}".format(args))
        encrypt_type = args.get("EncryptType")
        passwd = args.get("Passwd")
        if encrypt_type is None or encrypt_type not in (
                'CRYPT_DATA', 'CRYPT_SYSTEM') or passwd is None:
            abort(401)
        ret_type = args.get('RT')  # type: str

        if ret_type is None:
            ret_type = "JSON"

        # node = Node()
        # current_node = node.get_current_node()  # type: Node
        #
        # infa_env = INFA_ENV()
        #
        # set_task_envs = infa_env.get_envs(current_node.id)
        set_task_envs = get_current_node_infa_envs()
        print("############## os.environ is {0}".format(os.environ))
        os.environ.update(set_task_envs)

        commandResult = pmpasswd(
            passwd,
            encrypt_type=encrypt_type)  # type: namedtuple("pmpasswdResult",
        #  ['retcode', 'stdout'])
        content_type = None
        if ret_type.upper() == "PROTOBUF":
            pmpasswd_resp = infaCliResponse_pb2.InfaCliResponse()
            pmpasswd_resp.retcode = commandResult.retcode
            pmpasswd_resp.stdout = commandResult.stdout
            commandResult = pmpasswd_resp.SerializeToString()
            mainLogger.debug(
                "protobuf: the result is {0}".format(commandResult))
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("PROTOBUF")
        else:
            commandResult = json.dumps(commandResult._asdict())
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("JSON")
        response = make_response(commandResult)
        response.headers["Content-Type"] = content_type
        return response
Exemplo n.º 21
0
 def get_exiting_types(self) -> dict:
     output_dict = dict()
     t_c_n = namedtuple("nodeInfo", ["nodeClass", "node"])
     nodeAddress_list = list()
     for node in self.rootNode.getchildren():
         rootTag, rootClass = ds.get_root_tag(node)  # type: str, str
         mainLogger.debug(
             "tag is {0} and class is {1}, the node is {2}".format(
                 rootTag, rootClass, node))
         # NodeAddress will be multiple entries
         if rootTag == Config.PRED_METADATA_SCHEMA_TYPES.NodeAddress:
             nodeAddress_list.append(t_c_n(rootClass, node))
         else:
             output_dict.setdefault(rootTag, t_c_n(rootClass, node))
     if len(nodeAddress_list) != 0:
         output_dict.setdefault(
             Config.PRED_METADATA_SCHEMA_TYPES.NodeAddress,
             nodeAddress_list)
     mainLogger.info(output_dict)
     return output_dict
Exemplo n.º 22
0
    def __get_defined_type_inst(self, tag, nodeClass=None, node=None):
        nodeInfo = namedtuple("nodeInfo", ["nodeClass", "node"])
        if nodeClass is not None and node is not None:
            mainLogger.debug("the nodeClass {0} and node {1}".format(
                nodeClass, node))
            nodeInfo = nodeInfo(nodeClass, node)
        else:
            exiting_types = self.get_exiting_types()
            nodeInfo = exiting_types.get(
                tag)  # type: namedtuple("nodeInfo", ["nodeClass", "node"])
            if nodeInfo is None:
                raise NodeTagNotExistingException(
                    "The node tag {0} is not exiting in the nodemeta.xml file".
                    format(tag))

        mainLogger.info(nodeInfo)
        rootClazz = nodeInfo.nodeClass
        rootObj = rootClazz.factory()
        mainLogger.debug("the tag is {0} and the node is {1}".format(
            tag, nodeInfo.node))
        rootObj.build(nodeInfo.node)
        return rootObj
Exemplo n.º 23
0
def listApplications(
    servicename: str,
    domainname: str = None,
    username: str = None,
    password: str = None,
    securitydomain: str = "Native",
    resiliencetimeout: int = None
) -> namedtuple("ListApplicationsResult", ['retcode', "stdout", "stderr"]):
    sub_cmd = "listapplications"
    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname, username,
                                                 password, base_cmd, sub_cmd)
    options = [
        "domainname", "servicename", "username", "password", "securitydomain",
        "resiliencetimeout"
    ]

    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)

    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0 and not is_none(res.stdout):
        # format the stdout
        stdout_formated = stdout.split("\n")  # type: list
        stdout = stdout_formated[:-1]
    else:
        stderr += stdout

    ret = namedtuple("ListApplicationsResult", ['retcode', "stdout", "stderr"])
    return ret(res.retcode, stdout, stderr)
Exemplo n.º 24
0
def enableServiceProcess(
    ServiceName: str,
    NodeName: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("EnableServiceProcessResult", ['retcode', 'stdout', 'stderr']):
    subcmd = "EnableServiceProcess"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceName",
        "NodeName",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    return res
Exemplo n.º 25
0
def listNodeResources(
    NodeName: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
    ResourceCategory: str = "PCIS",
) -> namedtuple("ListNodeResourcesResult", ['retcode', 'stdout', 'stderr']):
    """ list the resources of the node
    if

    :param NodeName:
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :param ResourceCategory:
    :return:
    """
    subcmd = "ListNodeResources"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "NodeName",
        "ResourceCategory",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        entrys = stdout.splitlines()
        stdout = list()
        for entry in entrys:  # type: str
            entry_dict = dict()
            entry_list = entry.split(";")
            name = entry_list[0]
            name = name[name.index("[") + 1:-1]
            entry_dict.setdefault("name", name)
            type = entry_list[1]
            type = type[type.index("[") + 1:-1]
            entry_dict.setdefault("type", type)
            available = entry_list[2]
            available = available[available.index("[") + 1:-2]
            entry_dict.setdefault(
                "available", True if available.upper() == "TRUE" else False)
            stdout.append(entry_dict)
    else:
        stderr += stdout
    listNodeResourcesResult = namedtuple("ListNodeResourcesResult",
                                         ['retcode', 'stdout', 'stderr'])
    return listNodeResourcesResult(res.retcode, stdout, stderr)
Exemplo n.º 26
0
def listConnections(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    ConnectionType: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None,
) -> namedtuple("ListConnectionsResult", ['retcode', 'stdout', 'stderr']):
    """ list all connections (Administrator Console)
    if retcode requals 0, then stdout returns a dict which contains Connection_Type and its list of connection(id: name)
    like, {CONN_TYPE_1: [{id: CONN_1_ID, name: CONN_1_NAME}, {id: CONN_2_ID, name: CONN_2_NAME}, ....], CONN_TYPE_2: [], .....}

    :param DomainName:
    :param UserName:
    :param Password:
    :param ConnectionType: refer to the octopus.infa.infacmd.connectiontype_namedtupe
    :param SecurityDomain:
    :param ResilienceTimeout:
    :return: namedtuple("ListConnectionsResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "ListConnections  "
    options = [
        "DomainName",
        "UserName",
        "Password",
        "ConnectionType",
        "SecurityDomain",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)

    stdout = res.stdout  # type: str
    stderr = res.stderr

    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        stdout = stdout.split("\n")  # type: list
        stdout.reverse()
        conns_dict = dict()
        conns_list = list()
        for conn_val in stdout:
            if not conn_val.startswith("\t"):
                if len(conns_list) > 0:
                    conns_dict.setdefault(conn_val, conns_list)
                conns_list = list()
            else:
                # '\tINFA_102_DIS_PWD_210 - [ID: INFA_102_DIS_PWD_210
                conn_val = conn_val.lstrip("\t").rstrip("]").split(" - [ID: ")
                conns_list.append({"id": conn_val[1], "name": conn_val[0]})
                continue

        stdout = conns_dict
    else:
        stderr += stdout

    listConnectionsResult = namedtuple("ListConnectionsResult",
                                       ['retcode', 'stdout', 'stderr'])
    return listConnectionsResult(res.retcode, stdout, stderr)
Exemplo n.º 27
0
def listAllUsers(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ListAllUsersResult", ['retcode', 'stdout', 'stderr']):
    """
    list all users

    if retcode is 0, then stdout returns a list of users' dict,
    like [{securityDomain: securityDomainName_1, userName: userName_1}, ....]
    for example: [{'securityDomain': 'Native', 'userName': '******'}]

    else: return the stderr

    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return: namedtuple("ListAllUsersResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "ListAllUsers "
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        usersList = stdout.split("\n")
        stdout = list()
        for user in usersList:
            userinfo = user.split("/")
            user_dict = dict()
            user_dict.setdefault("securityDomain", userinfo[0])
            user_dict.setdefault("userName", userinfo[1])
            stdout.append(user_dict)
    else:
        stderr += stdout

    listAllUsersResult = namedtuple("ListAllUsersResult",
                                    ['retcode', 'stdout', 'stderr'])
    return listAllUsersResult(res.retcode, stdout, stderr)
Exemplo n.º 28
0
def listServices(
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
    ServiceType: str = None,
) -> namedtuple("ListServicesResult", ['retcode', 'stdout', 'stderr']):
    """ list all services or services of specified Service Type

    retcode: 0 stands for success, otherwise failure

    stdout: list(str) like [service_name1, service_name2, .....] if retcode equals 0

    stderr: str

    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :param ServiceType: refer to the octopus.infa.infacmd.servicetype_namedtupe
    :return: namedtuple("ListServicesResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "ListServices"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceType",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type:  str
    stderr = res.stderr
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        stdout = stdout.split("\n")
    else:
        stderr += stdout

    listServicesResult = namedtuple("ListServicesResult",
                                    ['retcode', 'stdout', 'stderr'])
    return listServicesResult(res.retcode, stdout, stderr)
Exemplo n.º 29
0
def listUserPermissions(
    ExistingUserName: str,
    ExistingUserSecurityDomain: str = "Native",
    ObjectType: str = None,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("ListUserPermissionsResult", ['retcode', 'stdout', 'stderr']):
    """ list user's permissions on these Object types

        if retcode equals 0, then stdout returns a dict with Object Types and its list of values. dict(list)

        otherwise, stderr will show the error messages.

        here is a sample of success:
         {
            'Folder': ['/System_Services',
                        '/'],
            'Grid': ['INFA210_GRID'],
            'License': ['dd',
                        'EndApr1'],
            'Node': ['ND_NoExisting',
                     'ND_INFA210'],
            'OS Profile': ['BDM_OS_Profile'],
            'Service': [
                 'Scheduler_Service',
                 'Email_Service',
                 'Resource_Manager_Service',
                 'IS_ASCII',
                 'D102_INFA210',
                 'M102_INFA210',
                 'R102_PRD_INFA210',
                 'IS_UNICODE',
                 'R102_INFA210']
        }

    :param ExistingUserName:
    :param ExistingUserSecurityDomain:
    :param ObjectType: (Service|License|Node|Grid|Folder|OSProfile) default is None which represents all
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return:
    """
    subcmd = "ListUserPermissions"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ExistingUserName",
        "ExistingUserSecurityDomain",
        "ObjectType",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        stdout = strip_ignored_cmd_messages(stdout)
        userPermissionsList = stdout.splitlines()
        userPermissionsList.reverse()
        stdout = dict()
        everyPermissionList = list()
        for entry in userPermissionsList:  # type: str
            if not entry.endswith(":"):
                entry = entry.strip(" ")
                if entry:
                    everyPermissionList.append(entry)
                continue
            else:
                stdout.setdefault(
                    entry.rstrip(":").rstrip(" "), everyPermissionList)
                everyPermissionList = list()
    else:
        stderr += stdout

    listUserPermissionsResult = namedtuple("ListUserPermissionsResult",
                                           ['retcode', 'stdout', 'stderr'])
    return listUserPermissionsResult(res.retcode, stdout, stderr)
Exemplo n.º 30
0
def disableServiceProcess(
    ServiceName: str,
    NodeName: str,
    Mode: str = "Complete",
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None
) -> namedtuple("DisableServiceProcessResult", ['retcode', 'stdout', 'stderr'
                                                ]):
    """
    Disable the Service process on a specified node


    :param ServiceName:
    :param NodeName:
    :param Mode: default is Complete, (Complete|Abort|Stop)
    :param DomainName: optional
    :param UserName: optional
    :param Password: optional
    :param SecurityDomain: default is Native
    :param Gateway: optional
    :param ResilienceTimeout: optional
    :return: namedtuple("DisableServiceProcessResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "DisableServiceProcess"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "ServiceName",
        "NodeName",
        "Mode",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        pass
    else:
        stderr += stdout
    disableServiceProcessResult = namedtuple("DisableServiceProcessResult",
                                             ['retcode', 'stdout', 'stderr'])
    return disableServiceProcessResult(res.retcode, stdout, stderr)