def configure_resources(*args):
    """Create/discover resources for management of load balancer instances."""
    if not reactive.is_flag_set('leadership.is_leader'):
        return ch_core.hookenv.action_fail('action must be run on the leader '
                                           'unit.')
    if not reactive.all_flags_set(
            'identity-service.available', 'neutron-api.available',
            'sdn-subordinate.available', 'amqp.available'):
        return ch_core.hookenv.action_fail('all required relations not '
                                           'available, please defer action'
                                           'until deployment is complete.')
    identity_service = reactive.endpoint_from_flag(
        'identity-service.available')
    try:
        (network, secgrp) = api_crud.get_mgmt_network(
            identity_service,
            create=reactive.is_flag_set('config.default.create-mgmt-network'),
        )
    except api_crud.APIUnavailable as e:
        ch_core.hookenv.action_fail(
            'Neutron API not available yet, deferring '
            'network creation/discovery. ("{}")'.format(e))
        return
    if network and secgrp:
        leadership.leader_set({
            'amp-boot-network-list': network['id'],
            'amp-secgroup-list': secgrp['id']
        })
    if reactive.is_flag_set('config.default.custom-amp-flavor-id'):
        # NOTE(fnordahl): custom flavor provided through configuration is
        # handled in the charm class configuration property.
        try:
            flavor = api_crud.get_nova_flavor(identity_service)
        except api_crud.APIUnavailable as e:
            ch_core.hookenv.action_fail('Nova API not available yet, '
                                        'deferring flavor '
                                        'creation. ("{}")'.format(e))
            return
        else:
            leadership.leader_set({'amp-flavor-id': flavor.id})

    amp_key_name = ch_core.hookenv.config('amp-ssh-key-name')
    if amp_key_name:
        identity_service = reactive.endpoint_from_flag(
            'identity-service.available')
        api_crud.create_nova_keypair(identity_service, amp_key_name)

    # Set qutotas to unlimited
    try:
        api_crud.set_service_quotas_unlimited(identity_service)
    except api_crud.APIUnavailable as e:
        ch_core.hookenv.action_fail(
            'Unbable to set quotas to unlimited: {}'.format(e))

    # execute port setup for leader, the followers will execute theirs on
    # `leader-settings-changed` hook
    with charm.provide_charm_instance() as octavia_charm:
        api_crud.setup_hm_port(identity_service, octavia_charm)
        octavia_charm.render_all_configs()
        octavia_charm._assess_status()
    def changed(self):
        flags = (
            self.expand_name(
                'endpoint.{endpoint_name}.changed.cluster-address'),
            self.expand_name('endpoint.{endpoint_name}.changed.cluster-user'),
            self.expand_name(
                'endpoint.{endpoint_name}.changed.cluster-password'),
            # Optimizers
            self.expand_name(
                'endpoint.{endpoint_name}.changed.unit-configure-ready'),
            self.expand_name(
                'endpoint.{endpoint_name}.changed.unit-clustered'),
        )
        if reactive.all_flags_set(*flags):
            for flag in flags:
                reactive.clear_flag(flag)

        if self.available():
            reactive.set_flag(self.expand_name('{endpoint_name}.available'))
        else:
            reactive.clear_flag(self.expand_name('{endpoint_name}.available'))

        if self.clustered():
            reactive.set_flag(self.expand_name('{endpoint_name}.clustered'))
        else:
            reactive.clear_flag(self.expand_name('{endpoint_name}.clustered'))
 def changed(self):
     flags = (
         self.expand_name('endpoint.{endpoint_name}.changed.hostname'),
         self.expand_name('endpoint.{endpoint_name}.changed.port'),
         self.expand_name('endpoint.{endpoint_name}.changed.tls-enabled'),
     )
     if all_flags_set(*flags):
         for flag in flags:
             clear_flag(flag)
         set_flag(self.expand_name('{endpoint_name}.available'))
 def changed(self):
     flags = (
         self.expand_name('endpoint.{endpoint_name}.changed.auth'),
         self.expand_name('endpoint.{endpoint_name}.changed.' +
                          self.key_name),
         self.expand_name(
             'endpoint.{endpoint_name}.changed.ceph-public-address'),
     )
     if all_flags_set(*flags):
         for flag in (flags):
             clear_flag(flag)
         set_flag(self.expand_name('{endpoint_name}.available'))
Exemple #5
0
 def test_all_flags(self):
     reactive.set_flag('foo')
     reactive.set_flag('bar')
     assert reactive.all_flags_set('foo')
     assert reactive.all_flags_set('bar')
     assert reactive.all_flags_set('foo', 'bar')
     assert not reactive.all_flags_set('foo', 'bar', 'qux')
     assert not reactive.all_flags_set('foo', 'qux')
     assert not reactive.all_flags_set('bar', 'qux')
     assert not reactive.all_flags_set('qux')
Exemple #6
0
    def changed(self):
        flags = (
            self.expand_name('endpoint.{endpoint_name}.changed.database'),
            self.expand_name('endpoint.{endpoint_name}.changed.username'),
            self.expand_name('endpoint.{endpoint_name}.changed.hostname'),
        )
        if reactive.all_flags_set(*flags):
            for flag in flags:
                reactive.clear_flag(flag)

        if self.available():
            reactive.set_flag(self.expand_name('{endpoint_name}.available'))
        else:
            reactive.clear_flag(self.expand_name('{endpoint_name}.available'))
Exemple #7
0
def remove_certs():
    '''Remove cert data from our configured paths when a tls provider is gone.'''
    # Remove cert data prior to reconfiguring/starting.
    layer.docker_registry.stop_registry()
    layer.docker_registry.remove_tls()

    # NB: remove the tls flag prior to calling configure
    clear_flag('charm.docker-registry.tls-enabled')
    layer.docker_registry.configure_registry()
    layer.docker_registry.start_registry()

    # If we have clients, let them know our tls data has changed
    if all_flags_set('charm.docker-registry.client-configured',
                     'endpoint.docker-registry.joined'):
        configure_client()
    report_status()