Exemple #1
0
 def _validate_value(self, value, exception=True):
     options = helper.extract_all_dict_values(self.options)
     return helper.validate_param_value(self.name,
                                        value,
                                        self.type,
                                        special_values=options,
                                        exception=exception)
Exemple #2
0
 def _validate_value(self, value, exception=True):
     regex = r"^[1-2][0-9](:[0-5][0-9]){1,2}$"
     return helper.validate_param_value(self.name,
                                        value,
                                        str,
                                        regex=regex,
                                        exception=exception,
                                        valid_example='23:45')
Exemple #3
0
 def _validate_value(self, value, exception=True):
     regex = r"[^@]+@[^@]+\.[^@]+"
     return helper.validate_param_value(self.name,
                                        value,
                                        self.type,
                                        special_values=[''],
                                        regex=regex,
                                        exception=exception,
                                        valid_example='*****@*****.**')
def kill_jobs(
    connection: Connection, jobs: List[Union["Job", str]]
) -> Union[Success, PartialSuccess, MstrException]:
    """Kill existing jobs by Job objects or job ids.

    Args:
        connection(object): MicroStrategy connection object returned by
            'connection.Connection()'
        jobs: List of Job objects or job ids to kill

    Returns:
        Success: object if all jobs were killed
        PartialSuccess: if not all jobs were killed
        MstrException: otherwise
    """
    validate_param_value("jobs", jobs, list)
    jobs = [job.id if isinstance(job, Job) else job for job in jobs]
    return monitors.cancel_jobs(connection, jobs)
Exemple #5
0
    def add_address(self,
                    name: str = None,
                    address: str = None,
                    default: bool = True) -> None:
        """Add new address to the user object.

        Args:
            name: User-specified name for the address
            address: The actual value of the address i.e. email address
                associated with this address name/id
            default: Specifies whether this address is the default address
                (change isDefault parameter).
        """
        helper.validate_param_value('address',
                                    address,
                                    str,
                                    regex=r"[^@]+@[^@]+\.[^@]+",
                                    valid_example="*****@*****.**")
        helper.validate_param_value('name', name, str)
        helper.validate_param_value('default', default, bool)
        body = {
            "name": name,
            "deliveryMode": "EMAIL",
            "device": "GENERIC_EMAIL",
            "value": address,
            "default": default
        }
        response = users.create_address(self.connection, self.id, body)
        if response.ok:
            if config.verbose:
                print("Added address '{}' for user '{}'".format(
                    address, self.name))
            setattr(self, "_addresses", response.json().get('addresses'))
Exemple #6
0
    def update_node_settings(self, node: Union[str, Node],
                             load_balance_factor: int, initial_pool_size: int,
                             max_pool_size: int) -> None:
        """Update I-Server configuration settings for a given server node
        within a cluster.

        Args:
            load_balance_factor: This setting becomes relevant in an environment
                that has a MicroStrategy Intelligence Server cluster. By
                default, the load balance factor is 1. The value can be
                increased on more powerful servers in a cluster to provide an
                appropriate balance. A larger load balance factor means the
                current server consumes a greater load in the server cluster in
                which it resides.
            initial_pool_size: Initial number of connections available.
            max_pool_size: Maximum number of connections available.
        """
        validate_param_value("load_balance_factor", load_balance_factor, int,
                             100, 1)
        validate_param_value("initial_pool_size", initial_pool_size, int, 1024,
                             1)
        validate_param_value("max_pool_size", max_pool_size, int, 1024, 1)

        node_name = node.name if isinstance(node, Node) else node
        body = {
            "loadBalanceFactor": load_balance_factor,
            "initialPoolSize": initial_pool_size,
            "maxPoolSize": max_pool_size
        }
        response = administration.update_iserver_node_settings(
            self.connection, body, node_name)
        if config.verbose and response.ok:
            logger.info(
                f'Intelligence Server configuration updated for {node_name}')
Exemple #7
0
    def update_address(self,
                       id: str,
                       name: Optional[str] = None,
                       address: Optional[str] = None,
                       default: Optional[bool] = None) -> None:
        """Update existing address. The address ID has to be specified
        as the name is not unique.

        Args:
            id: ID of the address
            name: New user-specified name for the address
            address: New address value
            default: Whether the address should be (un)marked as default
        """
        if id is None:
            helper.exception_handler(
                "Please specify 'id' parameter in the method.")
        body = {}
        if name is not None:
            helper.validate_param_value('name', name, str)
            body["name"] = name
        if address is not None:
            helper.validate_param_value('address',
                                        address,
                                        str,
                                        regex=r"[^@]+@[^@]+\.[^@]+",
                                        valid_example="*****@*****.**")
            body["value"] = address
        if default is not None:
            helper.validate_param_value('default', default, bool)
        response = users.update_address(self.connection, self.id, id, body)
        if response.ok:
            if config.verbose:
                logger.info(
                    f"Updated address with ID '{id}' for user '{self.name}'")
            self.fetch("addresses")
Exemple #8
0
 def _validate_value(self, value, exception=True):
     return helper.validate_param_value(self.name,
                                        value,
                                        self.type,
                                        exception=exception)