Example #1
0
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.datasource = MagicMock(etcd.Client)
     self.datasource.get = MagicMock(name='get')
     self.datasource.set = MagicMock(name='set')
     self.resource = clusters.ClusterUpgradeResource(self.datasource)
     self.api.add_route('/api/v0/cluster/{name}/upgrade', self.resource)
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.datasource = etcd.Client()
     self.return_value = MagicMock(etcd.EtcdResult)
     self.datasource.get = MagicMock(name='get')
     self.datasource.get.return_value = self.return_value
     self.resource = hosts.HostsResource(self.datasource)
     self.api.add_route('/api/v0/hosts', self.resource)
Example #3
0
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.datasource = MagicMock(etcd.Client)
     self.return_value = MagicMock(etcd.EtcdResult)
     self.datasource.get = MagicMock(name='get')
     self.datasource.get.return_value = self.return_value
     self.datasource.set = MagicMock(name='set')
     self.datasource.set.return_value = self.return_value
     self.resource = clusters.ClusterSingleHostResource(self.datasource)
     self.api.add_route(
         '/api/v0/cluster/{name}/hosts/{address}', self.resource)
Example #4
0
def create_app(ds):  # pragma: no cover
    # TODO: Make this configurable
    try:
        http_auth = httpauth.HTTPBasicAuthByEtcd(ds)
    except etcd.EtcdKeyNotFound:
        # TODO: Fall back to empty users file instead
        http_auth = httpauth.HTTPBasicAuthByFile('./conf/users.json')

    app = falcon.API(middleware=[http_auth, JSONify()])

    app.add_route('/api/v0/status', StatusResource(ds, None))
    app.add_route('/api/v0/host/{address}', HostResource(ds, None))
    app.add_route('/api/v0/hosts', HostsResource(ds, None))
    return app
Example #5
0
def create_app(
        authentication_module_name,
        authentication_kwargs):
    """
    Creates a new WSGI compliant commissaire application.

    :param authentication_module_name: Full name of the authentication module.
    :type authentication_module_name: str
    :param authentication_kwargs: Keyword arguments to pass to the auth mod.
    :type authentication_kwargs: dict
    :returns: The commissaire application.
    :rtype: falcon.API
    """
    try:
        module = importlib.import_module(authentication_module_name)
        authentication_class = getattr(module, 'AuthenticationPlugin')
        authentication = authentication_class(**authentication_kwargs)
    except ImportError:
        raise Exception('Can not import {0} for authentication'.format(
            authentication_module_name))

    app = falcon.API(middleware=[authentication, JSONify()])

    app.add_route('/api/v0/status', StatusResource())
    app.add_route('/api/v0/cluster/{name}', ClusterResource())
    app.add_route(
        '/api/v0/cluster/{name}/hosts',
        ClusterHostsResource())
    app.add_route(
        '/api/v0/cluster/{name}/hosts/{address}',
        ClusterSingleHostResource())
    app.add_route(
        '/api/v0/cluster/{name}/deploy',
        ClusterDeployResource())
    app.add_route(
        '/api/v0/cluster/{name}/restart',
        ClusterRestartResource())
    app.add_route(
        '/api/v0/cluster/{name}/upgrade',
        ClusterUpgradeResource())
    app.add_route('/api/v0/clusters', ClustersResource())
    app.add_route('/api/v0/network/{name}', NetworkResource())
    app.add_route('/api/v0/networks', NetworksResource())
    app.add_route('/api/v0/host', ImplicitHostResource())
    app.add_route('/api/v0/host/{address}', HostResource())
    app.add_route('/api/v0/host/{address}/creds', HostCredsResource())
    app.add_route('/api/v0/host/{address}/status', HostStatusResource())
    app.add_route('/api/v0/hosts', HostsResource())
    return app
Example #6
0
def create_app(
        store,
        authentication_module_name,
        authentication_kwargs,
        users_paths=('/etc/commissaire/users.json', './conf/users.json')):
    """
    Creates a new WSGI compliant commissaire application.

    :param store: The etcd client to for storing/retrieving data.
    :type store: etcd.Client
    :param authentication_module_name: Full name of the authentication module.
    :type authentication_module_name: str
    :param authentication_kwargs: Keyword arguments to pass to the auth mod.
    :type authentication_kwargs: dict
    :returns: The commissaire application.
    :rtype: falcon.API
    """
    try:
        authentication_class = getattr(__import__(
            authentication_module_name, fromlist=["True"]),
            'AuthenticationPlugin')
        authentication = authentication_class(**authentication_kwargs)
    except ImportError:
        raise Exception('Can not import {0} for authentication'.format(
            authentication_module_name))

    app = falcon.API(middleware=[authentication, JSONify()])

    app.add_route('/api/v0/status', StatusResource(store, None))
    app.add_route('/api/v0/cluster/{name}', ClusterResource(store, None))
    app.add_route(
        '/api/v0/cluster/{name}/hosts',
        ClusterHostsResource(store, None))
    app.add_route(
        '/api/v0/cluster/{name}/hosts/{address}',
        ClusterSingleHostResource(store, None))
    app.add_route(
        '/api/v0/cluster/{name}/restart',
        ClusterRestartResource(store, None))
    app.add_route(
        '/api/v0/cluster/{name}/upgrade',
        ClusterUpgradeResource(store, None))
    app.add_route('/api/v0/clusters', ClustersResource(store, None))
    app.add_route('/api/v0/host', ImplicitHostResource(store, None))
    app.add_route('/api/v0/host/{address}', HostResource(store, None))
    app.add_route('/api/v0/hosts', HostsResource(store, None))
    return app
Example #7
0
 def before(self):
     self.api = falcon.API(middleware = [JSONify()])
     self.resource = hosts.HostCredsResource()
     self.api.add_route('/api/v0/host/{address}/creds', self.resource)
Example #8
0
 def before(self):
     self.api = falcon.API(middleware = [JSONify()])
     self.resource = hosts.ImplicitHostResource()
     self.api.add_route('/api/v0/host', self.resource)
Example #9
0
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.resource = clusters.ClusterDeployResource()
     self.api.add_route('/api/v0/cluster/{name}/deploy', self.resource)
Example #10
0
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.resource = clusters.ClusterSingleHostResource()
     self.api.add_route('/api/v0/cluster/{name}/hosts/{address}',
                        self.resource)
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.resource = networks.NetworksResource()
     self.api.add_route('/api/v0/networks', self.resource)
Example #12
0
 def before(self):
     self.api = falcon.API(middleware=[JSONify()])
     self.return_value = MagicMock(etcd.EtcdResult)
     self.resource = status.StatusResource()
     self.api.add_route('/api/v0/status', self.resource)