Exemplo n.º 1
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
Exemplo n.º 2
0
    def basic(self):
        data = self.init()

        if env.host != env.hosts[0]:
            return

        keystone = Keystone()
        keystone.create_user(data["user"], data["password"], [["admin", "admin"]], False)

        glance = Glance()
        image_id = glance.create_image(data["image"]["name"], data["image"]["src_url"])

        net_id = utils.oscmd(
            "neutron net-list | grep ' {0} ' | awk '{{print $2}}'".format(env.cluster["neutron"]["test_net"])
        )

        nova = Nova()
        nova.create_flavor("test-flavor", 62, 2, 1)

        test_stack = {"image_id": image_id, "net_id": net_id, "flavor": "test-flavor"}

        filer.template("/tmp/stack-nova.yml", src="stack/stack-nova.yml", data=test_stack)
        filer.template("/tmp/autoscale.yml", src="stack/autoscale.yml", data=test_stack)

        with api.warn_only():
            result = utils.oscmd("heat stack-list | grep stack-nova")
            if result.return_code == 0:
                utils.oscmd("heat stack-delete -y stack-nova")
                time.sleep(3)
            utils.oscmd("heat stack-create -f /tmp/stack-nova.yml stack-nova")
Exemplo n.º 3
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}
Exemplo n.º 4
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
	def populate_endpoint(self):
		endPointObj = Endpoint()
		for module in self.jsonOfLogin['access']['serviceCatalog'] :
			if "glance" == module['name']: 
				glanceObj = Glance(self)
				glanceObj.set_endpoint_values(module['endpoints'][0]['adminURL'],module['endpoints'][0]['internalURL'],module['endpoints'][0]['publicURL'], module['endpoints'][0]['region'], module['endpoints'][0]['id'])
				endPointObj.glance = glanceObj
			if "nova" == module['name'] :
				novaObj = Nova()
				novaObj.set_endpoint_values(module['endpoints'][0]['adminURL'],module['endpoints'][0]['internalURL'],module['endpoints'][0]['publicURL'], module['endpoints'][0]['region'], module['endpoints'][0]['id'])
				endPointObj.nova = novaObj
			if "quantum" == module['name']:
				quantumObj = Quantum()
				quantumObj.set_endpoint_values(module['endpoints'][0]['adminURL'],module['endpoints'][0]['internalURL'],module['endpoints'][0]['publicURL'], module['endpoints'][0]['region'], module['endpoints'][0]['id'])
				endPointObj.quantum = quantumObj
			if "cinder" == module['name']:
				cinderObj = Cinder()
				cinderObj.set_endpoint_values(module['endpoints'][0]['adminURL'],module['endpoints'][0]['internalURL'],module['endpoints'][0]['publicURL'], module['endpoints'][0]['region'], module['endpoints'][0]['id'])
				endPointObj.cinder = cinderObj
			if "keystone" == module['name']:
				keystoneObj = Keystone()
				keystoneObj.set_endpoint_values(module['endpoints'][0]['adminURL'],module['endpoints'][0]['internalURL'],module['endpoints'][0]['publicURL'], module['endpoints'][0]['region'], module['endpoints'][0]['id'])
				endPointObj.keystone = keystoneObj
		return endPointObj
    def __init__(self):
        self.__config = Config('config.ini')

        server = self.__config.get_server()
        domain = self.__config.get_domain()
        username = self.__config.get_username()
        password = self.__config.get_password()
        self.__network_name = self.__config.get_internal_network()

        auth = Auth(server, 5000, username, password, domain)
        auth_token = auth.get_auth_token()
        tenant_id = auth.get_tenant_id()

        self.__nova = Nova(server, 8774, auth_token, tenant_id)
        self.__glance = Glance(server, 9292, auth_token)
        self.__network = Network(server, 9696, auth_token)

        self.__key_pair = self.__config.get_key_pair()
        self.__user_vm = self.__config.get_user_vm()
Exemplo n.º 7
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)
Exemplo n.º 8
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)
class OpenStack(Cal):

    def __init__(self):
        self.__config = Config('config.ini')

        server = self.__config.get_server()
        domain = self.__config.get_domain()
        username = self.__config.get_username()
        password = self.__config.get_password()
        self.__network_name = self.__config.get_internal_network()

        auth = Auth(server, 5000, username, password, domain)
        auth_token = auth.get_auth_token()
        tenant_id = auth.get_tenant_id()

        self.__nova = Nova(server, 8774, auth_token, tenant_id)
        self.__glance = Glance(server, 9292, auth_token)
        self.__network = Network(server, 9696, auth_token)

        self.__key_pair = self.__config.get_key_pair()
        self.__user_vm = self.__config.get_user_vm()

    def start(self, name='test'):
        image_name = self.__config.get_image_name()
        key_name = self.__config.get_key_name()
        flavor = self.__config.get_flavor()

        image_ref = self.__glance.get_image_ref(image_name)
        network_id = self.__network.get_network_id(self.__network_name)
        server_id = self.__nova.create(image_ref, name, flavor, network_id=network_id, key_name=key_name)
        return server_id

    def stop(self):
        ret = self.__nova.delete()
        return ret

    def status(self):
        return self.__nova.show_details()

    def associate_floating_ip(self):
        return self.__nova.add_floating_ip()

    def execute(self, command):
        ip = self.__nova.get_floating_ip()
        cmd = 'ssh -i ' + self.__key_pair + ' ' + self.__user_vm + '@' + ip + ' ' + command
        cmd_run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        return cmd_run.communicate()

    def put_data(self, source, destination):
        ip = self.__nova.get_floating_ip()
        cmd = 'ssh-keygen -R ' + ip
        subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        cmd = 'scp -i ' + self.__key_pair + ' -r ' + source + ' ' + self.__user_vm + '@' + ip + ':' + destination
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        proc.communicate()

    def get_data(self, source, destination):
        ip = self.__nova.get_floating_ip()
        cmd = 'ssh-keygen -R ' + ip
        subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        cmd = 'scp -i ' + self.__key_pair + ' -r ' + self.__user_vm + '@' + ip + ':' + destination + ' ' + source
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        proc.communicate()

    def backup(self, name='backup'):
        return self.__nova.backup(name)

    def restore(self):
        return self.__nova.restore()

    def get_system_info(self):
        absolute = self.__nova.get_system_info()
        print
        print 'maxTotalInstances: %d' % absolute['maxTotalInstances']
        print 'totalInstancesUsed: %d' % absolute['maxTotalCores']
        print
        print 'maxTotalRAMSize: %d' % absolute['maxTotalRAMSize']
        print 'totalRAMUsed: %d' % absolute['totalRAMUsed']
        print
        print 'maxTotalCores: %d' % absolute['maxTotalCores']
        print 'totalCoresUsed: %d' % absolute['totalCoresUsed']
        print
        print 'maxTotalFloatingIps: %d' % absolute['maxTotalFloatingIps']
        print 'totalFloatingIpsUsed: %d' % absolute['totalFloatingIpsUsed']
        print