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"
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, key_name="keypair-1", nics=nic_d)
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"
network_name = args.network input_file = args.file print("Getting organization id for: {}".format(organization_name)) organization_id = get_org_id(api_key, organization_name) if organization_id: print("Organization id = {}".format(organization_id)) else: print("Unable to find organization: {}".format(organization_name)) print( "Check organization name, ensure you have access to organization, check API key" ) exit() print("Getting network id for: {}".format(network_name)) network_id = get_network_id(api_key, organization_id, network_name) if network_id: print("Network id = {}".format(network_id)) else: print("Unable to find network: {}".format(network_name)) print( "Check network name, ensure network is in organization, check API key" ) exit() print("Opening input file {}".format(input_file)) fh = open(input_file, "r") vlan_details = json.load(fh) if type(vlan_details) is dict: print("Input file only contains one vlan; converting dict to list") new_vlan_details = []
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, key_name="keypair-1", nics=nic_d) print("Sleeping for 5s after create command") time.sleep(5)