Пример #1
0
from utils import get_router_id
from utils import get_network_id

args = sys.argv
args_len = len(sys.argv)

if args_len != 3:
    print("Please provide the vm name on the command line")
    print("format : $python -m neutronsamples.router_add_gateway <router_name> <network_name>")
    sys.exit()

router_name = args[1]
network_name = args[2]

try:
    neutron_credentials = get_credentials_tenant_one("admin", "admin_pass", "admin")
    credentials = get_credentials()
    neutron = client.Client(**neutron_credentials)

    router_id = get_router_id(neutron, router_name)
    network_id = get_network_id(neutron, network_name)
    print router_id
    print network_id
    
    router_dict = {
        'network_id' : network_id,
        'enable_snat' :  True
    }
    neutron.add_gateway_router(router_id, router_dict)
finally:
    print "Execution Completed"
Пример #2
0
from neutronclient.v2_0 import client
from credentials import get_credentials_tenant_one
from utils import print_values

credentials = get_credentials_tenant_one("user1", "user1", "user1-project")
neutron = client.Client(**credentials)
netw = neutron.list_networks()

print_values(netw, 'networks')
Пример #3
0
if args_len != 3:
    print("Please provide the vm name on the command line")
    print(
        "format : $python -m novasamples.create_server_v2 <vm_name> <network_name>"
    )
    sys.exit()

vm_name = args[1]
net_name = args[2]

try:
    username = '******'
    password = '******'
    tenant_name = 'user1-project'
    neutron_credentials = get_credentials_tenant_one(username, password,
                                                     tenant_name)
    neutron_client = client.Client(**neutron_credentials)
    net_id = get_network_id(neutron_client, net_name)
    credentials = get_nova_credentials_tenant(username, password, tenant_name,
                                              '2')
    nova_client = Client(**credentials)
    server_exists = check_vm_name(nova_client, vm_name)
    if server_exists:
        print("Server with name %s already exists" % vm_name)
    else:
        image = nova_client.images.find(name="cirros")
        flavor = nova_client.flavors.find(name="m1.tiny")
        nic_d = [{'net-id': net_id}]
        instance = nova_client.servers.create(name=vm_name,
                                              image=image,
                                              flavor=flavor,
from credentials import get_nova_credentials
from credentials import get_credentials
import sys
from utils import get_router_id
from utils import get_network_id

args = sys.argv
args_len = len(sys.argv)

if args_len != 2:
    print("Please provide the vm name on the command line")
    print(
        "format : $python -m neutronsamples.router_add_gateway <router_name>")
    sys.exit()

router_name = args[1]

try:
    neutron_credentials = get_credentials_tenant_one("admin", "admin_pass",
                                                     "admin")
    credentials = get_credentials()
    neutron = client.Client(**neutron_credentials)

    router_id = get_router_id(neutron, router_name)
    print("router_id:" + router_id)

    response = neutron.remove_gateway_router(router_id)
    print(response)
finally:
    print "Execution Completed"
Пример #5
0
from neutronclient.v2_0 import client
import novaclient.v1_1.client as nvclient
from credentials import get_credentials_tenant_one
from credentials import get_nova_credentials
from utils import print_values_server

credentials = get_credentials_tenant_one('user1', 'user1', 'user1-project')
neutron = client.Client(**credentials)

body_value = {
    'router': {
        'name': 'user2-router',
        'admin_state_up': True,
    }
}
router = neutron.create_router(body=body_value)
print(router)
print("Execution Completed")
Пример #6
0
from neutronclient.v2_0 import client
import novaclient.v1_1.client as nvclient
from credentials import get_credentials_tenant_one
from credentials import get_nova_credentials
from utils import print_values_server

credentials = get_credentials_tenant_one('user1', 'user1', 'user1-project')
neutron = client.Client(**credentials)

body_value = {'router': {
    'name' : 'user1-router',
    'admin_state_up': True,
}}
router = neutron.create_router(body=body_value)
print(router)
print("Execution Completed")
from credentials import get_nova_credentials_tenant
from credentials import get_credentials_tenant_one
import sys

args = sys.argv
args_len = len(sys.argv)

if args_len != 2:
    print ("Please provide the vm name on the command line")
    print ("format : $python -m novasamples.list_ports_server <vm_name>")
    sys.exit()

server_name = args[1]
username = "******"
password = "******"
tenant_name = "user1-project"
credentials = get_nova_credentials_tenant(username, password, tenant_name, "2")
nova_client = Client(**credentials)

server_id_list = get_vm_id(nova_client, server_name)
if len(server_id_list) > 1:
    raise Exception("More than one vm found")
    exit(3)
else:
    server_id = server_id_list[0]
    neutron_credentials = get_credentials_tenant_one(username, password, tenant_name)
    neutron = client.Client(**neutron_credentials)
    ports = neutron.list_ports()

    print print_values_server(ports, server_id, "ports")