示例#1
0
 def manage_flags(self):
     toggle_flag(
         self.expand_name('{endpoint_name}.available'),
         all([self.key(),
              self.fsid(),
              self.auth(),
              self.mon_hosts()]))
示例#2
0
def get_creds():
    prev_creds = layer.openstack.get_credentials()
    credentials_exist = layer.openstack.update_credentials()
    toggle_flag('charm.openstack.creds.set', credentials_exist)
    creds = layer.openstack.get_credentials()
    if creds != prev_creds:
        set_flag('charm.openstack.creds.changed')
示例#3
0
def restart():
    helpers.status_set('maintenance', 'Stopping Cassandra')
    if not cassandra.stop():
        helpers.status_set('blocked', 'Failed to stop Cassandra')
        return False

    auth_enabled = cassandra.config()['authenticator'] != 'allowallauthenticator'
    reactive.toggle_flag('cassandra.auth.enabled', auth_enabled)
    # cassandra.remount() # TODO: Storage support
    cassandra.ensure_all_database_directories()

    helpers.status_set('maintenance', 'Starting Cassandra')
    if not cassandra.start():
        helpers.status_set('blocked', 'Failed to start Cassandra')
        return False

    timeout = time.time() + 300
    for _ in cassandra.backoff("Cassandra to startup"):
        if cassandra.is_cassandra_running():
            reactive.clear_flag('cassandra.needs_restart')
            return True
        if time.time() > timeout:
            break
    helpers.status_set('blocked', 'Cassandra failed to startup')
    return False
示例#4
0
def check_refresh_available():
    # Do nothing if we don't have kernel support yet
    if not kernel_supported():
        return

    available_refreshes = snap.get_available_refreshes()
    for snapname in snap.get_installed_snaps():
        toggle_flag(snap.get_refresh_available_flag(snapname), snapname in available_refreshes)
 def manage_flags(self):
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
     toggle_flag(self.expand_name('{endpoint_name}.available'),
                 self.config_available())
     if is_flag_set(self.expand_name('endpoint.{endpoint_name}.changed')):
         clear_flag(self.expand_name('{endpoint_name}.configured'))
         clear_flag(self.expand_name('endpoint.{endpoint_name}.changed'))
示例#6
0
 def check_ready(self):
     # My middle name is ready. No, that doesn't sound right.
     # I eat ready for breakfast.
     was_ready = is_flag_set(self.expand_name('ready'))
     toggle_flag(self.expand_name('ready'), self.is_ready)
     if self.is_ready and was_ready and self.is_changed:
         set_flag(self.expand_name('ready.changed'))
     clear_flag(self.expand_name('changed'))
示例#7
0
 def manage_flags(self):
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
     toggle_flag(self.expand_name('{endpoint_name}.available'),
                 all([self.is_joined,
                      self.unit_role_id,
                      self.unit_token,
                      self.vault_url]))
 def check_ready(self):
     completed = self._received.get('completed', {})
     actual_hash = completed.get(self.instance_id)
     # My middle name is ready. No, that doesn't sound right.
     # I eat ready for breakfast.
     toggle_flag(self.expand_name('ready'), self._requested
                 and actual_hash == self._expected_hash)
     clear_flag(self.expand_name('changed'))
示例#9
0
def change_snapd_refresh():
    """Set the system refresh.timer option"""
    ensure_snapd_min_version("2.31")
    timer = hookenv.config()["snapd_refresh"]
    was_set = reactive.is_flag_set("snap.refresh.was-set")
    if timer or was_set:
        snap.set_refresh_timer(timer)
    reactive.toggle_flag("snap.refresh.was-set", timer)
    reactive.set_flag("snap.refresh.set")
示例#10
0
 def manage_flags(self):
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
     toggle_flag(self.expand_name('{endpoint_name}.gpu.available'),
                 self.is_joined and self._get_gpu())
     requests_data_id = self.expand_name('{endpoint_name}.requests')
     requests = self.auth_user()
     if data_changed(requests_data_id, requests):
         set_flag(self.expand_name('{endpoint_name}.requests.changed'))
示例#11
0
 def manage_flags(self):
     """
     Set states corresponding to the data we have.
     """
     toggle_flag(
         self.expand_name('{endpoint_name}.connected'),
         self.is_joined)
     toggle_flag(
         self.expand_name('{endpoint_name}.cohorts.ready'),
         self.is_joined and self._peers_have_cohorts())
 def check_ready(self):
     """
     Manage flags to signal when the endpoint is ready as well as noting
     if changes have been made since it became ready.
     """
     was_ready = is_flag_set(self.expand_name('ready'))
     toggle_flag(self.expand_name('ready'), self.is_ready)
     if self.is_ready and was_ready and self.is_changed:
         set_flag(self.expand_name('ready.changed'))
     clear_flag(self.expand_name('changed'))
示例#13
0
 def manage_flags(self):
     # we want to make sure all the templates and stuff are written
     # and pods started before we switch the API server over to
     # use the webhook. This is critical for the webhook template
     # since the API server will crash if the file isn't there.
     toggle_flag(self.expand_name('endpoint.{endpoint_name}.available'),
                 self.is_joined)
     toggle_flag(self.expand_name('endpoint.{endpoint_name}.ready'),
                 self.is_joined and all(unit.received['webhook_status']
                                        for unit in self.all_joined_units))
示例#14
0
 def manage_flags(self):
     any_fields_changed = False
     for field in ('access_address', 'secret_backend', 'hostname',
                   'isolated'):
         flag = self.expand_name('endpoint.{endpoint_name}.'
                                 'changed.{}').format(field)
         any_fields_changed = any_fields_changed or is_flag_set(flag)
         clear_flag(flag)
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
     toggle_flag(self.expand_name('endpoint.{endpoint_name}.new-request'),
                 any_fields_changed)
示例#15
0
 def joined(self):
     set_flag(self.expand_name('{endpoint_name}.available'))
     toggle_flag(self.expand_name('{endpoint_name}.certs.requested'),
                 self.new_requests)
     toggle_flag(self.expand_name('{endpoint_name}.server.certs.requested'),
                 self.new_server_requests)
     toggle_flag(self.expand_name('{endpoint_name}.client.certs.requested'),
                 self.new_client_requests)
     # For backwards compatibility, set the old "cert" flags as well
     toggle_flag(self.expand_name('{endpoint_name}.server.cert.requested'),
                 self.new_server_requests)
     toggle_flag(self.expand_name('{endpoint_name}.client.cert.requested'),
                 self.new_client_requests)
 def check_requests(self):
     unfulfilled_requests = False
     for request in self.all_requests:
         if request.changed:
             hookenv.log(
                 f'Marking request for processing for {request.unit_name} from {request.instance_id}'
             )
             unfulfilled_requests = True
         elif not request.is_completed and request.completed_for_instance:
             request.mark_completed()
             hookenv.log(
                 f'Marking request as completed for {request.unit_name} from {request.instance_id}'
             )
     toggle_flag(self.expand_name('requested'), unfulfilled_requests)
     clear_flag(self.expand_name('changed'))
示例#17
0
def join_cohort_snapshot(snapname, cohort_key):
    '''Refresh the snap into the given cohort.

    If the snap was previously in a cohort, this will update the revision
    to that of the new cohort snapshot. Note that this does not change the
    channel that the snap is in, only the revision within that channel.
    '''
    if is_local(snapname):
        # joining a cohort can override a locally installed snap
        hookenv.log('Skipping joining cohort for local snap: '
                    '{}'.format(snapname))
        return
    subprocess.check_output(['snap', 'refresh', snapname,
                             '--cohort', cohort_key])
    # even though we just refreshed to the latest in the cohort, it's
    # slightly possible that there's a newer rev available beyond the cohort
    reactive.toggle_flag(get_refresh_available_flag(snapname),
                         _check_refresh_available(snapname))
def _fetch():
    should_set_status = layer.options.get('docker-resource', 'set-status')
    queue = unitdata.kv().get('layer.docker-resource.pending', [])
    failed = []
    for res_name in queue:
        prefix = 'layer.docker-resource.{}'.format(res_name)
        if should_set_status:
            layer.status.maintenance('fetching resource: {}'.format(res_name))
        try:
            image_info_filename = hookenv.resource_get(res_name)
            if not image_info_filename:
                raise ValueError('no filename returned')
            image_info = yaml.safe_load(Path(image_info_filename).read_text())
            if not image_info:
                raise ValueError('no data returned')
        except Exception as e:
            hookenv.log(
                'unable to fetch docker resource {}: {}'.format(res_name, e),
                level=hookenv.ERROR)
            failed.append(res_name)
            set_flag('{}.failed'.format(prefix))
            clear_flag('{}.available'.format(prefix))
            clear_flag('{}.changed'.format(prefix))
        else:
            unitdata.kv().set('{}.image-info'.format(prefix), image_info)
            was_available = is_flag_set('{}.available'.format(prefix))
            is_changed = data_changed(prefix, image_info)
            set_flag('{}.available'.format(prefix))
            clear_flag('{}.failed'.format(prefix))
            toggle_flag('{}.changed'.format(prefix),
                        was_available and is_changed)
    if failed:
        if should_set_status:
            pl = 's' if len(failed) > 1 else ''
            layer.status.blocked(
                'unable to fetch resource{}: {}'.format(
                    pl, ', '.join(failed)
                )
            )
        unitdata.kv().set('layer.docker-resource.pending', failed)
        set_flag('layer.docker-resource.pending')
    else:
        unitdata.kv().set('layer.docker-resource.pending', [])
        clear_flag('layer.docker-resource.pending')
示例#19
0
 def check_requests(self):
     toggle_flag(self.expand_name('requests-pending'),
                 len(self.requests) > 0)
     clear_flag(self.expand_name('changed'))
示例#20
0
 def manage_flags(self):
     toggle_flag(self.expand_name('{endpoint_name}.available'),
                 len(self.get_addresses_ports()) > 0)
示例#21
0
 def manage_flags(self):
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
示例#22
0
 def manage_flags(self):
     """
     Set states corresponding to the data we have.
     """
     toggle_flag(self.expand_name('{endpoint_name}.connected'),
                 self.is_joined)
     toggle_flag(self.expand_name('{endpoint_name}.dns.available'),
                 self.is_joined and self.dns_ready())
     toggle_flag(self.expand_name('{endpoint_name}.auth.available'),
                 self.is_joined and self._has_auth_credentials())
     toggle_flag(self.expand_name('{endpoint_name}.cluster_tag.available'),
                 self.is_joined and self.get_cluster_tag())
     toggle_flag(
         self.expand_name('{endpoint_name}.registry_location.available'),
         self.is_joined and self.get_registry_location())
     toggle_flag(self.expand_name('{endpoint_name}.cohort_keys.available'),
                 self.is_joined and self.cohort_keys)
     toggle_flag(self.expand_name('{endpoint_name}.default_cni.available'),
                 self.is_joined and self.get_default_cni() is not None)
     toggle_flag(
         self.expand_name('{endpoint_name}.api_endpoints.available'),
         self.is_joined and self.get_api_endpoints())
示例#23
0
 def check_requests(self):
     requests = self.requests
     toggle_flag(self.expand_name('requested'), len(requests) > 0)
     clear_flag(self.expand_name('changed'))
示例#24
0
def get_creds():
    reactive.toggle_flag('charm.openstack.creds.set',
                         nodepool.get_credentials())
示例#25
0
 def manage_flags(self):
     toggle_flag(self.expand_name("{endpoint_name}.connected"),
                 self.is_joined)
     toggle_flag(self.expand_name("{endpoint_name}.available"),
                 self.config_available())
     clear_flag(self.expand_name("endpoint.{endpoint_name}.changed"))
 def check_ready(self):
     toggle_flag(self.expand_name("ready"), self.is_ready)
     clear_flag(self.expand_name("changed"))
示例#27
0
 def manage_flags(self):
     toggle_flag(self.expand_name('endpoint.{endpoint_name}.available'),
                 self.is_joined)
def get_creds():
    toggle_flag("charm.azure.creds.set", get_credentials())
示例#29
0
 def manage_flags(self):
     super().manage_flags()
     toggle_flag(self.expand_name('endpoint.{endpoint_name}.failed'),
                 self.is_joined and self.failed_imports)
def get_creds():
    toggle_flag('charm.openstack.creds.set', layer.openstack.get_credentials())
def get_creds():
    toggle_flag('charm.azure.creds.set', layer.azure.get_credentials())