Example #1
0
def prepare_broker_config():
    client = get_rest_client(tenant='default_tenant',
                             api_token=get_admin_api_token())
    brokers = client.manager.get_brokers().items
    config_path = broker_config.get_config_path()
    cert_path = os.path.join(os.path.dirname(config_path), 'broker_cert.pem')
    with open(cert_path, 'w') as f:
        f.write('\n'.join(broker.ca_cert_content for broker in brokers
                          if broker.ca_cert_content))
    broker_addrs = [
        broker.networks.get('default') for broker in brokers
        if broker.networks.get('default')
    ]
    config = {
        'broker_ssl_enabled': True,
        'broker_cert_path': cert_path,
        'broker_username': brokers[0].username,
        'broker_password': brokers[0].password,
        'broker_vhost': '/',
        'broker_management_hostname': brokers[0].management_host,
        'broker_hostname': broker_addrs
    }
    with open(config_path, 'w') as f:
        json.dump(config, f)
    broker_config.load_broker_config()
Example #2
0
 def db_updated(self):
     logger.info('DB nodes were updated in the cluster, '
                 'updating cluster monitoring')
     rest_client = get_rest_client(tenant='default_tenant',
                                   api_token=get_admin_api_token())
     db_hosts = list(get_db_hosts(rest_client.manager))
     update_db_targets(db_hosts)
     update_db_alerts(db_hosts)
 def manager_removed(self):
     logger.info('A manager has been removed from the cluster, updating '
                 'Syncthing')
     syncthing_utils.mgmtworker_update_devices(
         rest_client=get_rest_client(
             tenant='default_tenant',
             api_token=get_admin_api_token()
         ))
Example #4
0
 def broker_removed(self):
     logger.info('A broker has been removed from the cluster, '
                 'updating cluster monitoring')
     rest_client = get_rest_client(tenant='default_tenant',
                                   api_token=get_admin_api_token())
     broker_hosts = list(get_broker_hosts(rest_client.manager))
     update_broker_targets(broker_hosts)
     update_broker_alerts(broker_hosts)
Example #5
0
 def manager_removed(self):
     logger.info('A manager has been removed from the cluster, updating '
                 'Cluster (Syncthing and Monitoring)')
     rest_client = get_rest_client(tenant='default_tenant',
                                   api_token=get_admin_api_token())
     syncthing_utils.mgmtworker_update_devices(rest_client=rest_client)
     manager_hosts = list(get_manager_hosts(rest_client.manager))
     update_manager_targets(manager_hosts)
     update_manager_alerts(manager_hosts)
Example #6
0
    def can_scheduled_execution_start(execution_id, tenant):
        """
        This method checks whether or not a scheduled execution can currently
        start running. If it can't - it changes the executions status to
        QUEUED (so that it will automatically start running when possible)
        """
        api_token = get_admin_api_token()
        tenant_client = get_rest_client(tenant=tenant, api_token=api_token)
        if tenant_client.executions.should_start(execution_id):
            return True

        tenant_client.executions.update(execution_id, ExecutionState.QUEUED)
        return False
Example #7
0
    def can_scheduled_execution_start(execution_id, tenant):
        """
        This method checks if a scheduled execution can currently start. If it
        wasn't cancelled but can't currently start - it changes the executions
        status to QUEUED (so it will automatically start when possible).
        """
        api_token = get_admin_api_token()
        tenant_client = get_rest_client(tenant=tenant, api_token=api_token)
        execution = tenant_client.executions.get(execution_id)
        if execution['status'] == ExecutionState.CANCELLED:
            return False
        if tenant_client.executions.should_start(execution_id):
            return True

        tenant_client.executions.update(execution_id, ExecutionState.QUEUED)
        return False
Example #8
0
    def _get_plugin(self, tenant_name, implementation):
        package_name = implementation.split('.')[0]
        filter_plugin = {'package_name': package_name}
        admin_api_token = get_admin_api_token()
        rest_client = get_rest_client(tenant=tenant_name,
                                      api_token=admin_api_token)
        plugins = rest_client.plugins.list(**filter_plugin)
        if not plugins:
            return {}

        plugins.sort(key=lambda p: StrictVersion(p.package_version),
                     reverse=True)
        return {
            'package_name': package_name,
            'package_version': plugins[0]['package_version'],
            'visibility': plugins[0]['visibility']
        }
Example #9
0
    def _get_plugin(self, tenant_name, implementation):
        package_name = implementation.split('.')[0]
        filter_plugin = {'package_name': package_name}
        admin_api_token = get_admin_api_token()
        rest_client = get_rest_client(tenant=tenant_name,
                                      api_token=admin_api_token)
        plugins = rest_client.plugins.list(**filter_plugin)
        if not plugins:
            return {}

        plugins.sort(key=lambda p: StrictVersion(p.package_version),
                     reverse=True)
        return {
            'package_name': package_name,
            'package_version': plugins[0]['package_version'],
            'visibility': plugins[0]['visibility']
        }
Example #10
0
def prepare_broker_config():
    client = get_rest_client(
        tenant='default_tenant', api_token=get_admin_api_token())
    brokers = client.manager.get_brokers().items
    config_path = broker_config.get_config_path()
    cert_path = os.path.join(os.path.dirname(config_path), 'broker_cert.pem')
    with open(cert_path, 'w') as f:
        f.write('\n'.join(broker.ca_cert_content for broker in brokers
                if broker.ca_cert_content))
    broker_addrs = [broker.networks.get('default') for broker in brokers
                    if broker.networks.get('default')]
    config = {
        'broker_ssl_enabled': True,
        'broker_cert_path': cert_path,
        'broker_username': brokers[0].username,
        'broker_password': brokers[0].password,
        'broker_vhost': '/',
        'broker_management_hostname': brokers[0].management_host,
        'broker_hostname': broker_addrs
    }
    with open(config_path, 'w') as f:
        json.dump(config, f)
    broker_config.load_broker_config()
 def manager_removed(self):
     logger.info('A manager has been removed from the cluster, updating '
                 'Syncthing')
     syncthing_utils.mgmtworker_update_devices(rest_client=get_rest_client(
         tenant='default_tenant', api_token=get_admin_api_token()))