def shut_down(uuid, domain, username, project_domain_name, project_name, password, ip): nova = client.Client(2, session=get_session( domain=domain, username=username, project_domain_name=project_domain_name, project_name=project_name, password=password, ip=ip)) servers_list = nova.servers.list() server_del = uuid server_exists = False for s in servers_list: if s.id == server_del: print("This server %s exists" % server_del) server_exists = True break if not server_exists: print("server %s does not exist" % server_del) else: print("deleting server..........") nova.servers.delete(s) print("server %s deleted" % server_del)
def get_flavors(nvf, vim): nova = client.Client(2, session=get_session( domain=vim.domain, username=vim.username, project_domain_name=vim.project_domain, project_name=vim.project, password=vim.decrypt(), ip=vim.ip)) try: flavor = nova.flavors.find(vcpus=nvf.vnf.cpu, ram=nvf.vnf.ram, disk=nvf.vnf.disc) except: flavor = nova.flavors.create(name=str(uuid.uuid4()), ram=nvf.vnf.ram, vcpus=nvf.vnf.cpu, disk=nvf.vnf.disc, flavorid='auto', ephemeral=0, swap=0, rxtx_factor=1.0, is_public=True) flavor.set_keys(nvf.vnf.extra_spec()) return flavor.name
def get_hypervisors(vim): nova = client.Client(2, session=get_session( domain=vim.domain, username=vim.username, project_domain_name=vim.project_domain, project_name=vim.project, password=vim.decrypt(), ip=vim.ip)) return nova.hypervisors.list()
def create_snapshot(vnf, vim): nova = client.Client(2, session=get_session( domain=vim.domain, username=vnf.operator.name, project_domain_name=vim.project_domain, project_name=vnf.operator.name, password=vnf.operator.decrypt(), ip=vim.ip)) server = nova.servers.find(name=vnf.name) nova.servers.create_image(server, vnf.name) print "Snapshot created!!"
def console(name, domain, username, project_domain_name, project_name, password, ip): nova = client.Client(2, session=get_session( domain=domain, username=username, project_domain_name=project_domain_name, project_name=project_name, password=password, ip=ip)) server = nova.servers.find(name=name) return nova.servers.get_vnc_console(server, "novnc")
def del_key(key, vim): nova = client.Client(2, session=get_session( domain=vim.domain, username=key.operator.name, project_domain_name=vim.project_domain, project_name=key.operator.name, password=key.operator.decrypt(), ip=vim.ip)) try: nova.keypairs.delete(key.name) except: print "cannot add key"
def log(name, domain, username, project_domain_name, project_name, password, ip): nova = client.Client(2, session=get_session( domain=domain, username=username, project_domain_name=project_domain_name, project_name=project_name, password=password, ip=ip)) server = nova.servers.find(name=name) return nova.servers.get_console_output(server)
def get_public_network(vim): session = get_session(domain=vim.domain, username=vim.username, project_domain_name=vim.project_domain, project_name=vim.project, password=vim.decrypt(), ip=vim.ip) neutron = client.Client(session=session) networks = neutron.list_networks() for net in networks['networks']: if net['router:external'] is True: return net['id']
def node_state(vim, node, state): nova = client.Client(2, session=get_session( domain=vim.domain, username=vim.username, project_domain_name=vim.project_domain, project_name=vim.project, password=vim.decrypt(), ip=vim.ip)) node = nova.host.get(host_name=node) if state == "up": node.startup elif state == "down": node.shutdown
def delete_image(vnf): vims = Vim.objects.all() vim = vims[0] glance = client.Client(2, session=get_session( domain=vim.domain, username=vnf.operator.name, project_domain_name=vim.project_domain, project_name=vnf.operator.name, password=vnf.operator.password, ip=vim.ip)) print glance.images.list() # .delete("aleee") print "delete Image!"
def launch(name, domain, username, project_domain_name, project_name, password, ip): try: nova = client.Client(2, session=get_session( domain=domain, username=username, project_domain_name=project_domain_name, project_name=project_name, password=password, ip=ip)) image = nova.images.find(name=name) flavor = nova.flavors.find(name="small") net = nova.networks.find(label="network") nics = [{'net-id': net.id}] nova.servers.create(name="vm2", image=image, flavor=flavor, nics=nics) finally: print("Execution Completed")