Example #1
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)
Example #2
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
Example #3
0
 def insert_node(self, node: dict) -> None:
     if isinstance(node, dict):
         new_node = Node()
         for key, value in node.items():
             if hasattr(new_node, key):
                 setattr(new_node, key, value)
             else:
                 mainLogger.warn(
                     "During the insert, the {0}={1} is not for Node".
                     format(key, value))
     elif isinstance(node, self.__class__):
         new_node = node
     else:
         mainLogger.error("the node {0} is not supported".format(node))
     db.session.add(new_node)
     db.session.commit()
Example #4
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)
Example #5
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)
Example #6
0
def pmpasswd(
    passwd: str,
    encrypt_type: str = None
) -> namedtuple("pmpasswdResult", ['retcode', 'stdout']):
    """
    You can encrypt passwords to create an environment variable to use with infacmd, 
    infasetup, pmcmd, and pmrep or to define a password in a parameter file. 
    For example, you can encrypt the repository and database passwords for pmrep to maintain
    security when using pmrep in scripts. Then you can create an environment variable to store the 
    encrypted password. Or, you can define a password for a relational database connection object in 
    a parameter file.

    :param passwd: to be encrypted password
    :param encrypt_type: CRYPT_DATA | CRYPT_SYSTEM
    :return: encrypted password
    """
    infa_home_key = Config.PREDEFINED_ENV_VARIABLES_ATTRIBUTE.INFA_HOME
    infa_home = os.environ.get(infa_home_key)
    if is_none(infa_home):
        raise MissingEnvironmentVariable(
            "the {0} is not set".format(infa_home_key))

    ld_lib_path_name = get_LIBRARY_PATH_NAME()
    if ld_lib_path_name:
        existing_ld_lib_path_value = os.environ.get(ld_lib_path_name)
        infa_ld_lib_path = "{0}/server/bin:{1}/services/shared/bin".format(
            infa_home, infa_home)
        os.environ.update({
            ld_lib_path_name:
            "{0}:{1}".format(infa_ld_lib_path, existing_ld_lib_path_value)
        })

    if is_none(encrypt_type):
        command = "{infa_home}/server/bin/pmpasswd {passwd} ".format(
            infa_home=infa_home, passwd=passwd)
    elif encrypt_type is not None and encrypt_type.upper() in ('CRYPT_DATA',
                                                               'CRYPT_SYSTEM'):
        command = "{infa_home}/server/bin/pmpasswd {passwd} -e {encrypt_type}".format(
            infa_home=infa_home,
            passwd=passwd,
            encrypt_type=encrypt_type.upper())
    else:
        errmsg = "{0} is not supported in pmpasswd command".format(
            encrypt_type)
        mainLogger.error(errmsg)
        raise UnsupportedEncryptionType(errmsg)

    mainLogger.debug(os.environ)
    mainLogger.info(command)

    cmd_result = run_cmd(command, env=os.environ)
    mainLogger.debug(cmd_result)

    stdout = cmd_result.stdout  # type: str
    stderr = cmd_result.stderr  # type: str
    msg = None
    if cmd_result.retcode == 0:
        msg = stdout[stdout.index("-->") + 3:stdout.index("<--")]
    else:
        msg = stderr + " " + stdout[stdout.index("usage:"):]

    pmpasswdResult = namedtuple("pmpasswdResult", ['retcode', 'stdout'])

    return pmpasswdResult(cmd_result.retcode, msg)