Exemplo n.º 1
0
def listWorkflows(
    DomainName: str,
    ServiceName: str,
    Application: str,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None
) -> namedtuple("CmdResult", ['retcode', "stdout", "stderr"]):
    subcmd = "listWorkflows"
    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)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout_formated = stdout.split("\n")
        stdout = stdout_formated[:-1]

    ret = namedtuple("CmdResult", ['retcode', "stdout", "stderr"])
    return ret(res.retcode, stdout, stderr)
Exemplo n.º 2
0
 def update_env(self, node_id: int, env) -> None:
     """更新一个环境变量
     :param node_id: node id
     :param env: 新的环境变量字典
     :return: None
     :exception: ParameterTypeIsInvalidatedException
     """
     if isinstance(env, dict):
         temp_env = copy.deepcopy(env)
         name, value = temp_env.popitem()
         upd_env = self.query.filter(
             self.__class__.name == name,
             self.__class__.node_id == node_id).first()
         mainLogger.debug("INFA_ENV: Old value is {0}".format(upd_env))
         upd_env.value = value
         db.session.commit()
         mainLogger.debug("INFA_ENV: New value is {0}".format(upd_env))
     elif isinstance(env, self.__class__):
         upd_env = self.query.filter(
             self.__class__.node_id == env.node_id,
             self.__class__.name == env.name).first()
         upd_env.value = env.value
         db.session.commit()
     else:
         errmsg = "{0} should be dict or instance of {1}".format(
             env, self.__class__)
         mainLogger.error(errmsg)
         raise ParameterTypeIsInvalidatedException(errmsg)
Exemplo n.º 3
0
def startWorkflow(
    DomainName: str,
    ServiceName: str,
    Application: str,
    Workflow: str,
    Wait: bool = False,
    ParameterFile: str = None,
    ParameterSet: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    ResilienceTimeout: int = None,
    OsProfile: str = None
) -> namedtuple("CmdResult", ['retcode', "stdout", "stderr"]):
    options = [
        "DomainName", "ServiceName", "UserName", "Password", "SecurityDomain",
        "ResilienceTimeout", "Application", "Workflow", "Wait",
        "ParameterFile", "ParameterSet", "OsProfile"
    ]

    subcmd = "startWorkflow"
    cmd = _checking_infacmd_env_and_ret_base_cmd(DomainName, UserName,
                                                 Password, base_cmd, 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)
    stdout = res.stdout
    stderr = res.stderr
    ret = namedtuple("CommandResult", ['retcode', "stdout", "stderr"])
    return ret(res.retcode, stdout, stderr)
Exemplo n.º 4
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.º 5
0
def my_after_request(param):
    endTime = datetime.now()
    delta_time = endTime - g.startTime
    total_seconds = delta_time.total_seconds()
    mainLogger.debug(
        "######  my_after_request is invoked, and total_seconds is {0}, and param is {1}"
        .format(total_seconds, param))
    return param
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
0
 def get_NodeRef_list(self) -> [ds.NodeRef]:
     portals = self.get_NodeConfig().get_portals()
     mainLogger.debug("portals is {0}".format(portals))
     nodeRef_inst_list = list()
     for portal in portals:
         mainLogger.error(dir(portal))
         nodeRefs = portal.NodeRef
         for nodeRef in nodeRefs:  # type: ds.NodeRef
             nodeRef_inst_list.append(nodeRef)
     return nodeRef_inst_list
Exemplo n.º 10
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.º 11
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.º 12
0
 def get_envs(self, node_id: int) -> dict:
     """
     获取节点所有环境变量设置
     :param node_id: node id
     :return: 环境变量字典
     """
     my_envs = self.query.filter(self.__class__.node_id == node_id).all()
     envs_dict = dict()
     for env in my_envs:  # type: self.__class__
         envs_dict.setdefault(env.name, env.value)
     mainLogger.debug(envs_dict)
     return envs_dict
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.debug("## args =  {0}".format(args))
        if is_none(args.get("ServiceName")) or is_none(args.get("Application")) or is_none(args.get("Workflow")):
            raise MissingRequiredParametersException(" ServiceName and  Application and  Workflow  are/is requried")
        # return serilization type
        ret_type = args.get("RT")
        if ret_type is None:
            ret_type = "JSON"

        # current_node_envs = infa_env.get_envs(current_node.id)  # type: dict
        current_node_envs = get_current_node_infa_envs()
        os.environ.update(current_node_envs)
        mainLogger.debug("environment variables is {0}".format(current_node_envs))
        args.pop("RT")

        res = startWorkflow(**args)
        mainLogger.debug(res)
        stdout = str(res.stdout)
        if ret_type.upper() == "PROTOBUF":
            proto_resp = infaCliResponse_pb2.InfaCliResponse()
            proto_resp.retcode = res.retcode
            proto_resp.stdout = stdout
            res = proto_resp.SerializeToString()
            mainLogger.debug("protobuf: the result is {0}".format(res))
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("PROTOBUF")
        else:
            output_dict = {"retcode": res.retcode,
                           "stdout": stdout
                           }
            res = json.dumps(output_dict)
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("JSON")
        response = make_response(res)
        response.headers["Content-Type"] = content_type
        return response
Exemplo n.º 19
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.º 20
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.º 21
0
    def get_env(self, node_id: int, env_name: str) -> dict:
        """
        获取一个环境变量值
        :param node_id: node id
        :param env: 环境变量名
        :return: 环境变量字典|None
        """

        my_env = self.query.filter(self.__class__.name == env_name,
                                   self.__class__.node_id == node_id).first()
        mainLogger.debug(my_env)
        out_dict = dict()
        if my_env is not None:
            out_dict.setdefault(my_env.name, my_env.value)
        return out_dict
Exemplo n.º 22
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.º 23
0
    def post(self):
        args = self.parser.parse_args()

        mainLogger.debug("the AddInfaEnvs args is {0}".format(args))
        mainLogger.debug("the AddInfaEnvs locals is {0}".format(locals()))
        infa_envs_args = args.get("Envs")  # type: str
        infa_envs_dict = dict()

        try:
            envs_list = infa_envs_args.split(",")
            for env in envs_list:
                env_list = env.split("=", maxsplit=1)
                if len(env_list) < 2:
                    raise WrongEnvrionmentFormatException(
                        "{0} is not right, the standard format is env_name=env_value"
                        .format(env))
                infa_envs_dict.setdefault(env_list[0], env_list[1])
            current_node = get_current_node()
            infa_env_inst = INFA_ENV()
            ## upsert
            for key, value in infa_envs_dict.items():
                env_dict = {key: value}
                try:
                    infa_env_inst.update_env(current_node.id, env_dict)
                except Exception as e:
                    mainLogger.exception(
                        "Updating {0} with error: {1}, and now try to insert it"
                        .format(env_dict, str(e)))
                    infa_env_inst.insert_env(current_node.id, env_dict)
            ret_message = {
                "retcode": 0,
                "stdout": infa_envs_dict,
                "stderr": None
            }
        except Exception as e:
            mainLogger.exception(str(e))

            ret_message = ({
                "retcode":
                1,
                "stdout":
                None,
                "stderr":
                "Error {0} when upserting {1} into inner database.".format(
                    str(e.args), infa_envs_dict)
            }, 404)
        return ret_message
Exemplo n.º 24
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.º 25
0
def listTasks(
    DomainName: str,
    ServiceName: str,
    UserName: str = None,
    Password: str = None,
    MaxTasks: int = None,
    FilterByOwner: str = None,
    FilterByStatus: str = None,
    FilterByCreationDate: str = None,
    FilterByType: str = None,
    FilterByDueDate: str = None,
    FilterByID: str = None,
    FilterByName: str = None,
    FilterByNameLike: str = None,
    TasksOffset: str = None,
    Role: str = "ALL",
    SecurityDomain: str = None,
    ResilienceTimeout: str = None,
) -> namedtuple("CmdResult", ['retcode', "stdout", "stderr"]):
    options = [
        "DomainName", "ServiceName", "UserName", "Password", "MaxTasks",
        "FilterByOwner", "FilterByStatus", "FilterByCreationDate",
        "FilterByType", "FilterByDueDate", "FilterByID", "FilterByName",
        "FilterByNameLike", "TasksOffset", "Role", "SecurityDomain",
        "ResilienceTimeout"
    ]
    subcmd = "listTasks"
    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)
    stdout = res.stdout
    stderr = res.stderr
    if res.retcode == 0:
        stdout_formated = stdout.split("\n")
        stdout = stdout_formated[:-1]

    ret = namedtuple("CmdResult", ['retcode', "stdout", "stderr"])
    return ret(res.retcode, stdout, stderr)
Exemplo n.º 26
0
 def insert_envs(self, node_id: int, envs: dict) -> None:
     """插入多条环境变量信息
     :param node_id: node id
     :param envs: 环境变量字典
     :return: None
     :exception: ParameterTypeIsInvalidatedException
     """
     if isinstance(envs, dict):
         for name, value in envs.items():
             db.session.add(
                 self.__class__(name=name, value=value, node_id=node_id))
         db.session.commit()
         mainLogger.debug("insert {0} into infa_env".format(envs))
     else:
         errmsg = "{0} should be dict".format(envs)
         mainLogger.error(errmsg)
         raise ParameterTypeIsInvalidatedException(errmsg)
Exemplo n.º 27
0
 def __parse(self):
     tree = ET.parse(self.domains_infa)
     root = tree.getroot()
     mainLogger.debug("root.tag = {0}, root.text={1}, root.attrib={2}".format(root.tag, root.text, root.attrib))
     vector_dict = dict()
     vector_list = list()
     for vectors in root:
         for vector in vectors:
             tag = vector.tag  # type: str
             text = vector.text  # type: str
             if tag.lower() == 'address':
                 for addr in vector:
                     tag = addr.tag
                     text = addr.text
                     vector_dict.setdefault(tag, text)
             else:
                 vector_dict.setdefault(tag, text)
         vector_list.append(vector_dict)
     return vector_list
Exemplo n.º 28
0
 def delele_env(self, node_id: int, env) -> None:
     """
     删除一个环境变量
     :param node_id: node_id
     :param env: 环境变量字典
     :type env: str | dict
     :return: None
     :exception: ParameterTypeIsInvalidatedException
     """
     if isinstance(env, dict):
         temp_env = copy.deepcopy(env)
         name, value = temp_env.popitem()
     else:
         name = env
     del_env = self.query.filter(self.__class__.name == name,
                                 self.__class__.node_id == node_id).first()
     mainLogger.debug("{0} This will be deleted".format(del_env))
     db.session.delete(del_env)
     db.session.commit()
Exemplo n.º 29
0
 def insert_env(self, node_id: int, env: dict):
     """插入一条环境变量信息
     :param node_id: node id
     :param env: 环境变量字典
     :return: 如果成功为None,否者,抛出异常
     :rtype: None|ParameterTypeIsInvalidatedException
     """
     if isinstance(env, dict):
         tmp_env = copy.deepcopy(env)
         name, value = tmp_env.popitem()
         new_env = self.__class__(name=name, value=value, node_id=node_id)
         db.session.add(new_env)
         db.session.commit()
         mainLogger.debug("Insert the {0} into infa_env".format(new_env))
         return new_env
     else:
         errmsg = "{0} should be dict".format(env)
         mainLogger.error(errmsg)
         raise ParameterTypeIsInvalidatedException(errmsg)
Exemplo n.º 30
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