Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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!!"
Ejemplo n.º 6
0
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")
Ejemplo n.º 7
0
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!!"
Ejemplo n.º 8
0
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"
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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"
Ejemplo n.º 11
0
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']
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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!"
Ejemplo n.º 14
0
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!"
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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")
Ejemplo n.º 18
0
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")
Ejemplo n.º 19
0
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)