Ejemplo n.º 1
0
def _get_broker_rid_unit_for_previous_request():
    """Gets the broker rid and unit combination that has a response for the
     previous sent request."""
    broker_key = get_broker_rsp_key()

    log("Broker key is {}.".format(broker_key), level=DEBUG)

    for rid in relation_ids('ceph'):
        previous_request = get_previous_request(rid)
        for unit in related_units(rid):
            rdata = relation_get(rid=rid, unit=unit)
            if rdata.get(broker_key):
                rsp = CephBrokerRsp(rdata.get(broker_key))
                if rsp.request_id == previous_request.request_id:
                    log("Found broker rid/unit: {}/{}".format(rid, unit),
                        level=DEBUG)
                    return rid, unit
    log("There is no broker response for any unit at the moment.", level=DEBUG)
    return None, None
    def create_replicated_pool(self,
                               name,
                               replicas=3,
                               weight=None,
                               pg_num=None,
                               group=None,
                               namespace=None,
                               app_name=None,
                               max_bytes=None,
                               max_objects=None):
        """Request replicated pool setup.

        Refer to charm-helpers ``add_op_create_replicated_pool`` function for
        documentation of parameters.
        """
        # Ensure type of numeric values before sending over the wire
        replicas = int(replicas) if replicas else None
        weight = float(weight) if weight else None
        pg_num = int(pg_num) if pg_num else None
        max_bytes = int(max_bytes) if max_bytes else None
        max_objects = int(max_objects) if max_objects else None

        for relation in self.relations:
            current_request = ch_ceph.get_previous_request(
                relation.relation_id) or ch_ceph.CephBrokerRq()
            for req in current_request.ops:
                if 'op' in req and 'name' in req:
                    if req['op'] == 'create-pool' and req['name'] == name:
                        # request already exists, don't create a new one
                        return
            current_request.add_op_create_replicated_pool(
                name="{}".format(name),
                replica_count=replicas,
                pg_num=pg_num,
                weight=weight,
                group=group,
                namespace=namespace,
                app_name=app_name,
                max_bytes=max_bytes,
                max_objects=max_objects)
            ch_ceph.send_request_if_needed(current_request,
                                           relation=self.endpoint_name)