示例#1
0
def radosgw_relation(relid=None, unit=None):
    # Install radosgw for admin tools
    apt_install(packages=filter_installed_packages(['radosgw']))
    if not unit:
        unit = remote_unit()
    """Process broker request(s)."""
    if ceph.is_quorum():
        settings = relation_get(rid=relid, unit=unit)
        if 'broker_req' in settings:
            if not ceph.is_leader():
                log("Not leader - ignoring broker request", level=DEBUG)
            else:
                rsp = process_requests(settings['broker_req'])
                unit_id = unit.replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                log('mon cluster in quorum - providing radosgw with keys')
                public_addr = get_public_addr()
                data = {
                    'fsid': leader_get('fsid'),
                    'radosgw_key': ceph.get_radosgw_key(),
                    'auth': config('auth-supported'),
                    'ceph-public-address': public_addr,
                    unit_response_key: rsp,
                }
                relation_set(relation_id=relid, relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
示例#2
0
def radosgw_relation(relid=None, unit=None):
    # Install radosgw for admin tools
    apt_install(packages=filter_installed_packages(['radosgw']))
    if not unit:
        unit = remote_unit()
    """Process broker request(s)."""
    if ceph.is_quorum():
        settings = relation_get(rid=relid, unit=unit)
        if 'broker_req' in settings:
            if not ceph.is_leader():
                log("Not leader - ignoring broker request", level=DEBUG)
            else:
                rsp = process_requests(settings['broker_req'])
                unit_id = unit.replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                log('mon cluster in quorum - providing radosgw with keys')
                public_addr = get_public_addr()
                data = {
                    'fsid': leader_get('fsid'),
                    'radosgw_key': ceph.get_radosgw_key(),
                    'auth': config('auth-supported'),
                    'ceph-public-address': public_addr,
                    unit_response_key: rsp,
                }
                relation_set(relation_id=relid, relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
def assess_status():
    '''Assess status of current unit'''
    application_version_set(get_upstream_version(VERSION_PACKAGE))
    moncount = int(config('monitor-count'))
    units = get_peer_units()
    # not enough peers and mon_count > 1
    if len(units.keys()) < moncount:
        status_set(
            'blocked', 'Insufficient peer units to bootstrap'
            ' cluster (require {})'.format(moncount))
        return

    # mon_count > 1, peers, but no ceph-public-address
    ready = sum(1 for unit_ready in units.itervalues() if unit_ready)
    if ready < moncount:
        status_set('waiting', 'Peer units detected, waiting for addresses')
        return

    # active - bootstrapped + quorum status check
    if ceph.is_bootstrapped() and ceph.is_quorum():
        status_set('active', 'Unit is ready and clustered')
    else:
        # Unit should be running and clustered, but no quorum
        # TODO: should this be blocked or waiting?
        status_set('blocked', 'Unit not clustered (no quorum)')
def mds_relation_joined(relid=None, unit=None):
    if ceph.is_quorum() and related_osds():
        log('mon cluster in quorum and OSDs related'
            '- providing mds client with keys')
        mds_name = relation_get(attribute='mds-name', rid=relid, unit=unit)
        if not unit:
            unit = remote_unit()
        public_addr = get_public_addr()
        data = {
            'fsid': leader_get('fsid'),
            'mds_key': ceph.get_mds_key(name=mds_name),
            'auth': config('auth-supported'),
            'ceph-public-address': public_addr
        }
        settings = relation_get(rid=relid, unit=unit)
        """Process broker request(s)."""
        if 'broker_req' in settings:
            if ceph.is_leader():
                rsp = process_requests(settings['broker_req'])
                unit_id = unit.replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                data[unit_response_key] = rsp
            else:
                log("Not leader - ignoring mds broker request", level=DEBUG)

        relation_set(relation_id=relid, relation_settings=data)
    else:
        log('Waiting on mon quorum or min osds before provisioning mds keys')
def radosgw_relation(relid=None, unit=None):
    # Install radosgw for admin tools
    apt_install(packages=filter_installed_packages(['radosgw']))
    if not unit:
        unit = remote_unit()

    # NOTE: radosgw needs some usage OSD storage, so defer key
    #       provision until OSD units are detected.
    if ceph.is_quorum() and related_osds():
        log('mon cluster in quorum and osds related '
            '- providing radosgw with keys')
        public_addr = get_public_addr()
        data = {
            'fsid': leader_get('fsid'),
            'radosgw_key': ceph.get_radosgw_key(),
            'auth': config('auth-supported'),
            'ceph-public-address': public_addr,
        }

        settings = relation_get(rid=relid, unit=unit)
        """Process broker request(s)."""
        if 'broker_req' in settings:
            if ceph.is_leader():
                rsp = process_requests(settings['broker_req'])
                unit_id = unit.replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                data[unit_response_key] = rsp
            else:
                log("Not leader - ignoring broker request", level=DEBUG)

        relation_set(relation_id=relid, relation_settings=data)
    else:
        log('mon cluster not in quorum or no osds - deferring key provision')
示例#6
0
def client_relation():
    log('Begin client-relation hook.')

    if ceph.is_quorum():
        log('mon cluster in quorum - providing client with keys')
        service_name = remote_unit().split('/')[0]
        relation_set(key=ceph.get_named_key(service_name),
                     auth=config('auth-supported'))
    else:
        log('mon cluster not in quorum - deferring key provision')

    log('End client-relation hook.')
示例#7
0
def osd_relation():
    log('Begin osd-relation hook.')

    if ceph.is_quorum():
        log('mon cluster in quorum - providing fsid & keys')
        relation_set(fsid=config('fsid'),
                     osd_bootstrap_key=ceph.get_osd_bootstrap_key(),
                     auth=config('auth-supported'))
    else:
        log('mon cluster not in quorum - deferring fsid provision')

    log('End osd-relation hook.')
示例#8
0
def osd_relation(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing fsid & keys')
        data = {
            'fsid': leader_get('fsid'),
            'osd_bootstrap_key': ceph.get_osd_bootstrap_key(),
            'auth': config('auth-supported'),
            'ceph-public-address': get_public_addr(),
        }
        relation_set(relation_id=relid,
                     relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring fsid provision')
示例#9
0
def osd_relation(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing fsid & keys')
        public_addr = get_public_addr()
        data = {
            'fsid': leader_get('fsid'),
            'osd_bootstrap_key': ceph.get_osd_bootstrap_key(),
            'auth': config('auth-supported'),
            'ceph-public-address': public_addr,
        }
        relation_set(relation_id=relid, relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring fsid provision')
示例#10
0
def radosgw_relation():
    log('Begin radosgw-relation hook.')

    # Install radosgw for admin tools
    apt_install(packages=filter_installed_packages(['radosgw']))
    if ceph.is_quorum():
        log('mon cluster in quorum - providing radosgw with keys')
        relation_set(radosgw_key=ceph.get_radosgw_key(),
                     auth=config('auth-supported'))
    else:
        log('mon cluster not in quorum - deferring key provision')

    log('End radosgw-relation hook.')
示例#11
0
def osd_relation():
    utils.juju_log('INFO', 'Begin osd-relation hook.')

    if ceph.is_quorum():
        utils.juju_log('INFO',
                       'mon cluster in quorum - providing fsid & keys')
        utils.relation_set(fsid=utils.config_get('fsid'),
                           osd_bootstrap_key=ceph.get_osd_bootstrap_key(),
                           auth=utils.config_get('auth-supported'))
    else:
        utils.juju_log('INFO',
                       'mon cluster not in quorum - deferring fsid provision')

    utils.juju_log('INFO', 'End osd-relation hook.')
def admin_relation_joined(relid=None):
    if ceph.is_quorum():
        name = relation_get('keyring-name')
        if name is None:
            name = 'admin'
        log('mon cluster in quorum - providing client with keys')
        data = {
            'key': ceph.get_named_key(name=name, caps=ceph.admin_caps),
            'fsid': leader_get('fsid'),
            'auth': config('auth-supported'),
            'mon_hosts': config('mon-hosts') or " ".join(get_mon_hosts())
        }
        relation_set(relation_id=relid, relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
示例#13
0
def radosgw_relation(relid=None):
    # Install radosgw for admin tools
    apt_install(packages=filter_installed_packages(['radosgw']))
    if ceph.is_quorum():
        log('mon cluster in quorum - providing radosgw with keys')
        data = {
            'fsid': leader_get('fsid'),
            'radosgw_key': ceph.get_radosgw_key(),
            'auth': config('auth-supported'),
            'ceph-public-address': get_public_addr(),
        }
        relation_set(relation_id=relid,
                     relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
示例#14
0
def client_relation():
    utils.juju_log('INFO', 'Begin client-relation hook.')

    if ceph.is_quorum():
        utils.juju_log('INFO',
                       'mon cluster in quorum - \
                        providing client with keys')
        service_name = os.environ['JUJU_REMOTE_UNIT'].split('/')[0]
        utils.relation_set(key=ceph.get_named_key(service_name),
                           auth=utils.config_get('auth-supported'))
    else:
        utils.juju_log('INFO',
                       'mon cluster not in quorum - deferring key provision')

    utils.juju_log('INFO', 'End client-relation hook.')
示例#15
0
def radosgw_relation():
    utils.juju_log('INFO', 'Begin radosgw-relation hook.')

    utils.install('radosgw')  # Install radosgw for admin tools

    if ceph.is_quorum():
        utils.juju_log('INFO',
                       'mon cluster in quorum - \
                        providing radosgw with keys')
        utils.relation_set(radosgw_key=ceph.get_radosgw_key(),
                           auth=utils.config_get('auth-supported'))
    else:
        utils.juju_log('INFO',
                       'mon cluster not in quorum - deferring key provision')

    utils.juju_log('INFO', 'End radosgw-relation hook.')
def osd_relation(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing fsid & keys')
        public_addr = get_public_addr()
        data = {
            'fsid': leader_get('fsid'),
            'osd_bootstrap_key': ceph.get_osd_bootstrap_key(),
            'auth': config('auth-supported'),
            'ceph-public-address': public_addr,
            'osd_upgrade_key': ceph.get_named_key('osd-upgrade',
                                                  caps=ceph.osd_upgrade_caps),
        }
        relation_set(relation_id=relid,
                     relation_settings=data)
        # NOTE: radosgw key provision is gated on presence of OSD
        #       units so ensure that any deferred hooks are processed
        notify_radosgws()
    else:
        log('mon cluster not in quorum - deferring fsid provision')
示例#17
0
def client_relation_changed():
    """Process broker requests from ceph client relations."""
    if ceph.is_quorum():
        settings = relation_get()
        if 'broker_req' in settings:
            if not ceph.is_leader():
                log("Not leader - ignoring broker request", level=DEBUG)
            else:
                rsp = process_requests(settings['broker_req'])
                unit_id = remote_unit().replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                # broker_rsp is being left for backward compatibility,
                # unit_response_key superscedes it
                data = {
                    'broker_rsp': rsp,
                    unit_response_key: rsp,
                }
                relation_set(relation_settings=data)
    else:
        log('mon cluster not in quorum', level=DEBUG)
示例#18
0
def client_relation_changed():
    """Process broker requests from ceph client relations."""
    if ceph.is_quorum():
        settings = relation_get()
        if 'broker_req' in settings:
            if not ceph.is_leader():
                log("Not leader - ignoring broker request", level=DEBUG)
            else:
                rsp = process_requests(settings['broker_req'])
                unit_id = remote_unit().replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                # broker_rsp is being left for backward compatibility,
                # unit_response_key superscedes it
                data = {
                    'broker_rsp': rsp,
                    unit_response_key: rsp,
                }
                relation_set(relation_settings=data)
    else:
        log('mon cluster not in quorum', level=DEBUG)
示例#19
0
def client_relation(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing client with keys')
        service_name = None
        if relid is None:
            service_name = remote_unit().split('/')[0]
        else:
            units = related_units(relid)
            if len(units) > 0:
                service_name = units[0].split('/')[0]
        if service_name is not None:
            data = {
                'key': ceph.get_named_key(service_name),
                'auth': config('auth-supported'),
                'ceph-public-address': get_public_addr(),
            }
            relation_set(relation_id=relid,
                         relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
def client_relation_joined(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing client with keys')
        service_name = None
        if relid is None:
            units = [remote_unit()]
            service_name = units[0].split('/')[0]
        else:
            units = related_units(relid)
            if len(units) > 0:
                service_name = units[0].split('/')[0]

        if service_name is not None:
            public_addr = get_public_addr()
            data = {'key': ceph.get_named_key(service_name),
                    'auth': config('auth-supported'),
                    'ceph-public-address': public_addr}
            relation_set(relation_id=relid,
                         relation_settings=data)
    else:
        log('mon cluster not in quorum - deferring key provision')
示例#21
0
def assess_status():
    '''Assess status of current unit'''
    moncount = int(config('monitor-count'))
    units = get_peer_units()
    # not enough peers and mon_count > 1
    if len(units.keys()) < moncount:
        status_set('blocked', 'Insufficient peer units to bootstrap'
                              ' cluster (require {})'.format(moncount))
        return

    # mon_count > 1, peers, but no ceph-public-address
    ready = sum(1 for unit_ready in units.itervalues() if unit_ready)
    if ready < moncount:
        status_set('waiting', 'Peer units detected, waiting for addresses')
        return

    # active - bootstrapped + quorum status check
    if ceph.is_bootstrapped() and ceph.is_quorum():
        status_set('active', 'Unit is ready and clustered')
    else:
        # Unit should be running and clustered, but no quorum
        # TODO: should this be blocked or waiting?
        status_set('blocked', 'Unit not clustered (no quorum)')
def osd_relation(relid=None):
    if ceph.is_quorum():
        log('mon cluster in quorum - providing fsid & keys')
        public_addr = get_public_addr()
        data = {
            'fsid':
            leader_get('fsid'),
            'osd_bootstrap_key':
            ceph.get_osd_bootstrap_key(),
            'auth':
            config('auth-supported'),
            'ceph-public-address':
            public_addr,
            'osd_upgrade_key':
            ceph.get_named_key('osd-upgrade', caps=ceph.osd_upgrade_caps),
        }

        unit = remote_unit()
        settings = relation_get(rid=relid, unit=unit)
        """Process broker request(s)."""
        if 'broker_req' in settings:
            if ceph.is_leader():
                rsp = process_requests(settings['broker_req'])
                unit_id = unit.replace('/', '-')
                unit_response_key = 'broker-rsp-' + unit_id
                data[unit_response_key] = rsp
            else:
                log("Not leader - ignoring broker request", level=DEBUG)

        relation_set(relation_id=relid, relation_settings=data)
        # NOTE: radosgw key provision is gated on presence of OSD
        #       units so ensure that any deferred hooks are processed
        notify_radosgws()
        notify_client()
    else:
        log('mon cluster not in quorum - deferring fsid provision')
示例#23
0
 def test_is_quorum_notleader(self):
     self.os.path.exists.return_value = True
     self.get_unit_hostname.return_value = 'myhost'
     self.subprocess.check_output.return_value = '{"state": "notleader"}'
     self.assertEqual(ceph.is_quorum(), False)
示例#24
0
 def test_is_quorum_valerror(self):
     self.os.path.exists.return_value = True
     self.get_unit_hostname.return_value = 'myhost'
     self.subprocess.check_output.return_value = "'state': 'bob'}"
     self.assertEqual(ceph.is_quorum(), False)
示例#25
0
 def test_is_quorum_no_asok(self):
     self.os.path.exists.return_value = False
     self.assertEqual(ceph.is_quorum(), False)