def discover_vm_on_network(tenant_name):
    """
    This method is used to discover instances per tenant
    """
    name=None
    status=None
    try:
        tenant_credentials = get_tenant_nova_credentials(tenant_name)
        nova = nvclient.Client(**tenant_credentials)
        instance_list=nova.servers.list()
        #instance = nova.servers.find(name=vm_name)
        if instance_list > 0:
         
            for inst in instance_list:
            
                instance_id = inst.id
                name=inst.name
                inst_find=nova.servers.find(id=instance_id)
                print('   - Instance %s Discovered' % inst.name)
                print('   - Instance ID %s Discovered' % instance_id)
                print('   - Instance %s Status' % inst.status)
                status=inst.status
    except Exception:
        print('   - Instance Not Found')
        status = False

    ins_data = {'instance_name': name, 
                                'status': status }
    return ins_data
Exemplo n.º 2
0
def add_floating_ip_for_vm(tenant_name, instance):
    """
    This method is used to allocate & associate floating IP to the given VM\
    based on the availability from the defined pool.
    """
    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    nova = nvclient.Client(**tenant_credentials)
    floating_ip = nova.floating_ips.create(FLOATING_IP_POOL)
    instance.add_floating_ip(floating_ip)
    print "   - Assigned Floating IP: " + str(floating_ip.ip)
    return True
def launch_vm_on_network(tenant_name, vm_name, network_id):
    """
    This method is to launch VM on the given network & VM Name.
    """
    #pdb.set_trace()
    instance=None 
    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    
    nova = nvclient.Client(**tenant_credentials)
    nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
    with open('user.txt') as userdata:
        user_data = userdata.read()
    try:
	image_list=nova.images.find(name="ubuntu")
    except NotFound:
	upload_image_glance()

    #for img in image:
        #if img.name == 'ubuntu':
            #print "image found"
    try:

        flavor = nova.flavors.find(name='traffic')
    except:
        flavor = nova.flavors.create(name="traffic",ram="2048",vcpus="1",disk="10")

      
    try:
        
        instance = nova.servers.create(name=vm_name, image=image_list,
                                       flavor=flavor,
                                       key_name="admin",
                                       availability_zone="compute:openstack-aio",
                                       nics=[{'net-id': network_id}],userdata=user_data)
    except Exception:
        pass

    # Poll at 15 second intervals, until the status is no longer 'BUILD'
    print "  * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
    status = instance.status
    while status == 'BUILD':
        time.sleep(15)
        # Retrieve the instance again so the status field updates
        instance = nova.servers.get(instance.id)
        status = instance.status

    print "   - Current status: %s" % status
    if FLOATING_IP_CREATION:
        add_floating_ip_for_vm(tenant_name, instance)

    ins_data = {'instance_name': vm_name, 'status': status}
    return ins_data
def launch_vm_on_network(tenant_name, vm_name, network_id):
    """
    This method is to launch VM on the given network & VM Name.
    """
    pdb.set_trace()

    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    
    nova = nvclient.Client(**tenant_credentials)
    nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
    with open('user.txt') as userdata:
        user_data = userdata.read()
    try:
	image_list=nova.images.find(name="cirros-0.3.4-x86_64-uec")
    except NotFound:
	upload_image_glance()

    #for img in image:
        #if img.name == 'ubuntu':
            #print "image found"
    try:

        flavor = nova.flavors.find(name='traffic')
    except:
        flavor = nova.flavors.create(name="traffic",ram="512",vcpus="1",disk="1")
    instance=None
      
    try:
        pdb.set_trace()
        instance = nova.servers.create(name=vm_name, image=image_list,
                                       flavor=flavor,
                                       availability_zone="compute:compute",
                                       nics=[{'net-id': network_id}],userdata=user_data)
    except Exception:
        pass

    # Poll at 15 second intervals, until the status is no longer 'BUILD'
    print "  * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
    status = instance.status
    while status == 'BUILD':
        time.sleep(15)
        # Retrieve the instance again so the status field updates
        instance = nova.servers.get(instance.id)
        status = instance.status

    print "   - Current status: %s" % status
    if FLOATING_IP_CREATION:
        add_floating_ip_for_vm(tenant_name, instance)

    ins_data = {'instance_name': vm_name, 'status': status}
    return ins_data
def terminate_vm_on_network(tenant_name, vm_name, network_name):
    """
    This method is to terminate VM on the given network & VM Name.
    """
    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    nova = nvclient.Client(**tenant_credentials)
    nova.quotas.delete(tenant_name)
    try:
        instance = nova.servers.find(name=vm_name)
        nova.servers.delete(instance.id)
        print "  * Instance terminated on network: " + str(vm_name)
    except Exception:
        print "  * Instance Not Found on network: " + str(vm_name)
        pass
    return True
def terminate_vm_on_network(tenant_name, vm_name, network_id):
    """
    This method is to terminate VM on the given network & VM Name.
    """
    pdb.set_trace()  
    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    nova = nvclient.Client(**tenant_credentials)
    nova.quotas.delete(tenant_name)
    try:
        instance = nova.servers.find(name=vm_name)
        nova.servers.delete(instance.id)
        print "  * Instance terminated on network: " + str(network_id)
    except Exception:
        print "  * Instance Not Found on network: " + str(network_id)
        pass
    return True
def discover_vm_on_network(tenant_name, vm_name, network_id):
    """
    This method is used to discover instances per tenant
    """
    try:
        tenant_credentials = get_tenant_nova_credentials(tenant_name)
        nova = nvclient.Client(**tenant_credentials)
        instance = nova.servers.find(name=vm_name)
        instance_id = nova.servers.get(instance.id)
        print('   - Instance %s Discovered' % vm_name)
        print('   - Instance ID %s Discovered' % instance_id)
        status = True
    except Exception:
        print('   - Instance %s Not Found' % vm_name)
        status = False

    ins_data = {'instance_name': vm_name, 'status': status}
    return ins_data
def vm_endpoint_discovery(tenant_name):
    pdb.set_trace()

    name = None
    status = None
    try:
        tenant_credentials = get_tenant_nova_credentials(tenant_name)
        nova = nvclient.Client(**tenant_credentials)
        instance_list = nova.servers.list()
        #instance = nova.servers.find(name=vm_name)
        if instance_list > 0:

            for inst in instance_list:

                instance_id = inst.id
                name = inst.name
                networks = inst.networks

    except Exception:
        print('   - Instance Not Found')
def launch_vm_on_network(tenant_name, vm_name, network_id):
    """
    This method is to launch VM on the given network & VM Name.
    """
    tenant_credentials = get_tenant_nova_credentials(tenant_name)
    nova = nvclient.Client(**tenant_credentials)
    nova.quotas.update(tenant_name,
                       instances=-1,
                       cores=-1,
                       ram=-1,
                       fixed_ips=-1,
                       floating_ips=-1)
    image = nova.images.find(name=IMAGE_NAME)
    flavor = nova.flavors.find(name=FLAVOUR_NAME)
    try:
        instance = nova.servers.create(name=vm_name,
                                       image=image,
                                       flavor=flavor,
                                       key_name="admin",
                                       nics=[{
                                           'net-id': network_id
                                       }])
    except Exception:
        pass

    # Poll at 25 second intervals, until the status is no longer 'BUILD'
    print "  * Instance created on network: " + str(vm_name)
    status = instance.status
    while status == 'BUILD':
        time.sleep(25)
        # Retrieve the instance again so the status field updates
        instance = nova.servers.get(instance.id)
        status = instance.status

    print "   - Current status: %s" % status
    if FLOATING_IP_CREATION:
        add_floating_ip_for_vm(tenant_name, instance)

    ins_data = {'instance_name': vm_name, 'status': status}
    return ins_data
def vm_endpoint_discovery(tenant_name):
    pdb.set_trace()

    name=None
    status=None
    try:
        tenant_credentials = get_tenant_nova_credentials(tenant_name)
        nova = nvclient.Client(**tenant_credentials)
        instance_list=nova.servers.list()
        #instance = nova.servers.find(name=vm_name)
        if instance_list > 0:

            for inst in instance_list:

                instance_id = inst.id
                name=inst.name
                networks=inst.networks
              

               
    except Exception:
        print('   - Instance Not Found')
Exemplo n.º 11
0
def get_instance_detail(tenant, instance):

    tenant_credentials = get_tenant_nova_credentials(tenant)
    nova = nvclient.Client(**tenant_credentials)
    return nova.servers.get(instance)
def get_instance_detail(tenant,instance):

    tenant_credentials = get_tenant_nova_credentials(tenant)
    nova = nvclient.Client(**tenant_credentials)
    return nova.servers.get(instance)