Example #1
0
    def run(self):
        nova = Nova()

        node_name = key_name = self.temp_name()
        key_file = nova.create_key(key_name)

        base_image = nova.image_by_regexp(self.opts.base_image)

        s = nova.boot(node_name, nova.flavor('standard.xsmall'), base_image,
                      key_name)
        ip = nova.public_ip(s)

        if self.opts.install_script_url:
            log("fetching " + self.opts.install_script_url)
            self.opts.install_script = "/tmp/" + node_name + '_install'
            run_cmd([
                'curl', '-o', self.opts.install_script,
                self.opts.install_script_url
            ])

        nova.scp(ip, "ubuntu", key_file, self.opts.install_script,
                 '/tmp/novawiz_install')
        nova.run_cmd(ip, key_file,
                     "chmod +x {0}".format("/tmp/novawiz_install"))
        nova.run_cmd(ip, key_file, "/tmp/novawiz_install")

        log("building image")
        nova.build_image(s, self.opts.name)

        log("destroying build node")
        nova.delete_key(key_name)
        log("destroying temp keypair")
        os.remove(key_file)
        nova.delete_server(s)
Example #2
0
def get_nova(req, sect):
    if not cfg.has_section(sect):
        return {
            'status': 500,
            'error': "Internal Server Error: malformed config file",
            'data': None
        }
    auth = check_auth(req.headers)
    if auth['error']:
        return {'status': 401, 'error': auth['error'], 'data': None}
    nova = Nova(auth, cfg.get(sect, "tenant"), cfg.get(sect, "auth_url"))
    if nova.error:
        return nova.error
    return {'status': 200, 'error': None, 'data': nova}
Example #3
0
def api_status_all():
    try_ipydb = get_ipydb(request, True)
    if try_ipydb['status'] != 200:
        return return_json(None, try_ipydb['error'], try_ipydb['status'])
    ipydb = try_ipydb['data']
    all_vm = ipydb.list()
    if not all_vm:
        response = return_json(None,
                               'Internal Server Error: no data available', 500)
    # return list of VM objs from DB
    elif request.method == 'GET':
        response = return_json(all_vm)
    # update 'status' of VM objs in DB from nova-pool
    elif request.method == 'PUT':
        ncfg = dict(cfg.items('nova-pool'))
        nova = Nova({
            'username': ncfg["user"],
            'password': ncfg["password"]
        }, ncfg["tenant"], ncfg["auth_url"])
        if nova.error:
            return return_json(None, nova.error['error'], nova.error['status'])
        data = nova.server()
        if data['status'] == 200:
            updated = []
            servers = dict([(x['id'], x) for x in data['data']])
            for vm in all_vm:
                if vm['id'] in servers:
                    new = ipydb.update(vm['id'],
                                       status=servers[vm['id']]['status'])
                else:
                    new = ipydb.update(vm['id'], status='UNKNOWN')
                updated.append(new)
            response = return_json(updated)
        else:
            response = return_json(all_vm)
    ipydb.exit()
    return response