Exemple #1
0
    def run(self):
        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={"message": "Checking if update parameters are valid"},
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            ))

        if 'Pool.pg_num' in self.parameters:
            fetched_pool = Pool(pool_id=self.parameters['Pool.pool_id']).load()
            if self.parameters['Pool.pg_num'] <= int(fetched_pool.pg_num):
                Event(
                    Message(
                        priority="error",
                        publisher=NS.publisher_id,
                        payload={
                            "message":
                            "New pg-num cannot be less than "
                            "existing value"
                        },
                        job_id=self.parameters['job_id'],
                        flow_id=self.parameters['flow_id'],
                        cluster_id=NS.tendrl_context.integration_id,
                    ))
                raise AtomExecutionFailedError(
                    "New pg-num cannot be less than existing value")

        return True
Exemple #2
0
    def run(self):
        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={"message": "Checking if update parameters are valid"},
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            ))

        if 'Pool.poolname' in self.parameters and \
            ('Pool.pg_num' in self.parameters or
             'Pool.size' in self.parameters or
             'Pool.pg_num' in self.parameters or
             'Pool.min_size' in self.parameters or
             'Pool.quota_enabled' in self.parameters):
            Event(
                Message(
                    priority="info",
                    publisher=NS.publisher_id,
                    payload={
                        "message":
                        "Invalid combination of pool update parameters. "
                        "Pool name shouldnt be updated with other parameters."
                    },
                    job_id=self.parameters['job_id'],
                    flow_id=self.parameters['flow_id'],
                    cluster_id=NS.tendrl_context.integration_id,
                ))
            raise AtomExecutionFailedError(
                "Invalid combination of pool update parameters. "
                "Pool name shoulnt be update with other parameters.")

        if 'Pool.pg_num' in self.parameters:
            fetched_pool = Pool(pool_id=self.parameters['Pool.pool_id']).load()
            if self.parameters['Pool.pg_num'] <= fetched_pool.pg_num:
                Event(
                    Message(
                        priority="info",
                        publisher=NS.publisher_id,
                        payload={
                            "message":
                            "New pg-num cannot be less than "
                            "existing value"
                        },
                        job_id=self.parameters['job_id'],
                        flow_id=self.parameters['flow_id'],
                        cluster_id=NS.tendrl_context.integration_id,
                    ))
                raise AtomExecutionFailedError(
                    "New pg-num cannot be less than existing value")

        return True
    def run(self):
        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={
                    "message": "Checking if pool with name %s doesnt exist" %
                    self.parameters['Pool.poolname']
                },
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            )
        )

        try:
            pools = NS.etcd_orm.client.read(
                "clusters/%s/Pools" % NS.tendrl_context.integration_id
            )
        except etcd.EtcdKeyNotFound:
            # No pools available in cluster, return True
            return True

        for pool in pools._children:
            fetched_pool = Pool(
                pool_id=pool['key'].split('/')[-1]
            ).load()
            if fetched_pool.pool_name == \
                self.parameters['Pool.poolname']:
                Event(
                    Message(
                        priority="info",
                        publisher=NS.publisher_id,
                        payload={
                            "message": "Pool with name %s already exists" %
                            self.parameters['Pool.poolname']
                        },
                        job_id=self.parameters['job_id'],
                        flow_id=self.parameters['flow_id'],
                        cluster_id=NS.tendrl_context.integration_id,
                    )
                )
                return False

        return True
Exemple #4
0
    def run(self):
        retry_count = 0
        while True:
            pools = None
            try:
                pools = NS._int.client.read("clusters/%s/Pools" %
                                            NS.tendrl_context.integration_id)
            except etcd.EtcdKeyNotFound:
                pass

            if pools:
                for entry in pools.leaves:
                    try:
                        pool = Pool(
                            pool_id=entry.key.split("Pools/")[-1]).load()
                        if pool.pool_name == self.parameters['Pool.poolname']:
                            return True
                    except etcd.EtcdKeyNotFound:
                        continue

            retry_count += 1
            gevent.sleep(1)
            if retry_count == 600:
                Event(
                    Message(
                        priority="error",
                        publisher=NS.publisher_id,
                        payload={
                            "message":
                            "Pool %s not reflected in tendrl yet. Timing out" %
                            self.parameters['Pool.pool_name']
                        },
                        job_id=self.parameters['job_id'],
                        flow_id=self.parameters['flow_id'],
                        cluster_id=NS.tendrl_context.integration_id,
                    ))
                raise AtomExecutionFailedError(
                    "Pool %s not reflected in tendrl yet. Timing out" %
                    self.parameters['Pool.pool_name'])
    def _get_pool_id(self, pool_name):
        try:
            pools = NS._int.client.read("clusters/%s/Pools" %
                                        NS.tendrl_context.integration_id)
        except etcd.EtcdKeyNotFound:
            return False

        for pool in pools.leaves:
            fetched_pool = Pool(pool_id=pool.key.split("Pools/")[-1]).load()
            if fetched_pool.pool_name == pool_name:
                Event(
                    Message(
                        priority="info",
                        publisher=NS.publisher_id,
                        payload={
                            "message":
                            "Found pool_id with pool_name %s" % pool_name
                        },
                        job_id=self.parameters['job_id'],
                        flow_id=self.parameters['flow_id'],
                        cluster_id=NS.tendrl_context.integration_id,
                    ))
                return fetched_pool.pool_id
Exemple #6
0
    def run(self):
        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={
                    "message": "Checking if pool-id %s doesnt exist" %
                    self.parameters['Pool.pool_id']
                },
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            )
        )

        try:
            Pool(
                pool_id=self.parameters['Pool.pool_id']
            ).load()
        except etcd.EtcdKeyNotFound:
            return True

        return False
Exemple #7
0
    def run(self):
        pool_id = self.parameters['Pool.pool_id']
        attrs = {}
        if 'Pool.pg_num' in self.parameters:
            fetched_obj = Pool(pool_id=self.parameters['Pool.pool_id']).load()
            attrs['pg_num'] = self.parameters.get('Pool.pg_num')
            if attrs['pg_num'] <= int(fetched_obj.pg_num):
                raise AtomExecutionFailedError(
                    "New pg-num cannot be less than existing value")
        if 'Pool.size' in self.parameters:
            attrs['size'] = self.parameters.get('Pool.size')
        if 'Pool.min_size' in self.parameters:
            attrs['min_size'] = self.parameters.get('Pool.min_size')
        if 'Pool.quota_enabled' in self.parameters and \
            self.parameters['Pool.quota_enabled'] is True:
            attrs['quota_max_objects'] = \
                self.parameters.get('Pool.quota_max_objects')
            attrs['quota_max_bytes'] = \
                self.parameters.get('Pool.quota_max_bytes')
        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={
                    "message":
                    "Updating details for pool-id %s."
                    " Attributes: %s" %
                    (self.parameters['Pool.pool_id'], str(attrs))
                },
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            ))

        crud = Crud()
        resp = crud.update("pool", pool_id, attrs)
        try:
            crud.sync_request_status(resp['request'])
        except RequestStateError as ex:
            Event(
                Message(
                    priority="info",
                    publisher=NS.publisher_id,
                    payload={
                        "message":
                        "Failed to update pool %s."
                        " Error: %s" % (self.parameters['Pool.pool_id'], ex)
                    },
                    job_id=self.parameters['job_id'],
                    flow_id=self.parameters['flow_id'],
                    cluster_id=NS.tendrl_context.integration_id,
                ))
            return False

        Event(
            Message(
                priority="info",
                publisher=NS.publisher_id,
                payload={
                    "message":
                    "Pool %s successfully updated" %
                    (self.parameters['Pool.pool_id'])
                },
                job_id=self.parameters['job_id'],
                flow_id=self.parameters['flow_id'],
                cluster_id=NS.tendrl_context.integration_id,
            ))

        return True