Beispiel #1
0
def script(uuid):
    try:
        params = get_host_params(uuid)
        template = get_template(params["ipxe_script"])
        return render_template_string(template, **params)
    except KeyError:
        return abort(404)
def _render(name, uuid):
    try:
        template = get_template(name)
        params = get_host_params(uuid)
        return render_template_string(template, **params)
    except KeyError:
        return abort(404)
Beispiel #3
0
def power_status(uuid):
    try:
        params = get_host_params(uuid)
        if "power_driver" not in params:
            abort(400)
        return jsonify(power_driver.power_status(**params))
    except KeyError:
        abort(404)
Beispiel #4
0
def module(uuid, module_id):
    params = get_host_params(uuid)
    url = params.get('module%d' % module_id)
    if url is not None:
        return proxy(url, params)
    url = params.get('module')
    if url is not None and module_id == 0:
        return proxy(url, params)
    abort(404)
Beispiel #5
0
def _get(uuid):
    if request.args.get('installed') == 'mark':
        mark_host_installed(uuid)
        return make_response("", 200, [])
    if request.args.get('installed') == 'unmark':
        unmark_host_installed(uuid)
        return make_response("", 200, [])
    if request.args.get('params') == 'all':
        return jsonify(get_host_params(uuid))
    return jsonify(get_host(uuid))
Beispiel #6
0
def power_change(uuid):
    try:
        host_params = get_host_params(uuid)
        if "power_driver" not in host_params:
            abort(400)
        request_params = request.get_json()
        power = request_params.get("power")
        if power == "on":
            power_driver.power_on(**host_params)
        elif power == "off":
            power_driver.power_off(**host_params)
        elif power == "reset":
            power_driver.power_reset(**host_params)
        else:
            abort(400)
        return make_response("", 202, [])
    except KeyError:
        abort(404)
 def test_get_host_params(self):
     expected = {
         u'base_url': u'http://127.0.0.1',
         u'groups': [u'ubuntu', u'default'],
         u'hostname': u'test-200',
         u'image_base_url': u'http://127.0.0.1/images',
         u'ipaddr': u'192.168.10.200',
         u'ipxe_script': u'ubuntu.temp',
         u'kernel': u'http://127.0.0.1/images/linux',
         u'kernel_opts': u'quiet',
         u'mirror_host': u'jp.archive.ubuntu.com',
         u'mirror_path': u'/ubuntu',
         u'mirror_scheme': u'http',
         u'module': u'http://127.0.0.1/images/initrd.gz',
         u'module1': u'http://127.0.0.1/images/initrd1.gz',
         u'test': u'test',
         u'uuid': self.host_id,
         u'power_driver': u'dummy'}
     with self.app.test_request_context('/'):
         result = hosts.get_host_params(self.host_id)
         self.assertEqual(result, expected)
Beispiel #8
0
def kernel(uuid):
    params = get_host_params(uuid)
    url = params.get('kernel')
    if url is None:
        abort(404)
    return proxy(url, params)