def network_create_net(destination, network): # print network neutron = get_neutron(destination) bonds = None tenant_info = keystone_common.find_opposite_project_id(network['tenant_id']) if network['provider:physical_network']: if network['provider:physical_network'] == 'bond0': bonds = 'datacentre' else: bonds = 'storage' new_network = {'network': {'name': network['name'], 'tenant_id': tenant_info['to_id'], 'admin_state_up': network['admin_state_up'], 'provider:network_type': network['provider:network_type'], 'provider:segmentation_id': network['provider:segmentation_id'], #todo: check on this 'provider:physical_network': bonds, 'router:external': network['router:external'], 'shared': network['shared']}} else: new_network = {'network': {'name': network['name'], 'tenant_id': tenant_info['to_id'], 'admin_state_up': network['admin_state_up'], 'provider:network_type': network['provider:network_type'], 'provider:segmentation_id': network['provider:segmentation_id'], # todo: check on this 'router:external': network['router:external'], 'shared': network['shared']}} # physical = network['provider:physical_network'] # if physical is not None: # new_network['network'].update({'provider:physical_network': physical}) new_net = neutron.create_network(body=new_network) return new_net
def compare_and_report_quotas(): from_tenants = keystone_common.get_from_project_list() print "Differences in individual quotas for each project:" for from_tenant in from_tenants: from_quotas = get_quotas('from', from_tenant.id) to_tenant = keystone_common.find_opposite_project_id(from_tenant.id) to_quotas = get_quotas('to', to_tenant['to_id']) print "\nFrom project id:", from_tenant.id, "To project id:", to_tenant['to_id'] compare_quotas(from_quotas, to_quotas)
def compare_and_update_quotas(): from_tenants = keystone_common.get_from_project_list() for from_tenant in from_tenants: print "from tenant id " print from_tenant.id from_quotas = get_quotas('from', from_tenant.id) to_tenant = keystone_common.find_opposite_project_id(from_tenant.id) print "to tenant_id" print to_tenant['to_id'] to_quotas = get_quotas('to', to_tenant['to_id']) # print to_quotas update_quotas(from_tenant, from_quotas, to_tenant, to_quotas)
def create_router(destination, router): neutron = get_neutron(destination) #todo: fix ['external_gateway_info']['external_fixed_ips'][0] to have multiples, rather than single #though i dont think routers can have two external gateway IPs... matching_network = find_corresponding_network_name_by_id(router['external_gateway_info']['network_id']) matching_subnet = find_corresponding_subnet_name_by_id(router['external_gateway_info']['network_id'], matching_network['id'], router['external_gateway_info']['external_fixed_ips'][0]['subnet_id']) matching_tenant = keystone_common.find_opposite_project_id(router['tenant_id']) body = {'router': { 'name': router['name'], 'tenant_id': matching_tenant['to_id'] }} new_router = neutron.create_router(body=body) print "New Router created:", new_router add_router_gateway(destination, new_router['router'], router, matching_network, matching_subnet) return new_router
def create_flavor(destination, flavor): nova = get_nova(destination) swap = 0 if isinstance(flavor.swap, (int, long)): swap = flavor.swap new_flavor = nova.flavors.create(name=flavor.name, ram=flavor.ram, vcpus=flavor.vcpus, disk=0, flavorid=flavor.id, ephemeral=flavor.ephemeral, swap=swap, rxtx_factor=flavor.rxtx_factor, is_public=flavor.is_public) if flavor.is_public is False: from_nova = get_nova('from') access = from_nova.flavor_access.list(flavor=flavor.id) for acc in access: to_tenant = keystone_common.find_opposite_project_id(acc.tenant_id) nova.flavor_access.add_tenant_access(flavor=new_flavor.id, tenant=to_tenant['to_id']) return new_flavor
def network_create_net(destination, network): neutron = get_neutron(destination) # need a "to" tenant id. tenant_info = keystone_common.find_opposite_project_id( network['tenant_id']) new_network = { 'network': { 'name': network['name'], 'tenant_id': tenant_info['to_id'], 'admin_state_up': network['admin_state_up'], 'provider:network_type': network['provider:network_type'], #'provider:segmentation_id': network['provider:segmentation_id'], #todo: check on this 'router:external': network['router:external'], 'shared': network['shared'] } } physical = network['provider:physical_network'] if physical is not None: new_network['network'].update({'provider:physical_network': physical}) new_net = neutron.create_network(body=new_network) return new_net
print "Exception occured while adding interface to router", str(e) # create ports for floating ips as well as any other ports that get individual ips on subnets that are then attached to # vm instances. Equivalent of 'neutron port-create egle-net --fixed-ip ip_address=11.11.11.3' def create_ip_ports(destination, port): neutron = get_neutron(destination) try: corspd_network = find_corresponding_network_name_by_id( port['network_id']) except Exception, e: print "Couldn't find a matching network, please check that source and destination networks match." return if port['device_owner'].startswith('network:floatingip'): fip = find_float_by_floatip('from', port['fixed_ips'][0]['ip_address']) corspd_tenant = keystone_common.find_opposite_project_id( fip['tenant_id']) else: corspd_tenant = keystone_common.find_opposite_project_id( port['tenant_id']) # print "old port tenant", port['tenant_id'] # print "corresponding tenant in port creation", corspd_tenant try: if port['device_owner'].startswith('network:floatingip'): body = { "floatingip": { "floating_network_id": corspd_network['id'], "floating_ip_address": port['fixed_ips'][0]['ip_address'], "tenant_id": corspd_tenant['to_id'] } }
else: print "Exception occured while adding interface to router", str(e) # create ports for floating ips as well as any other ports that get individual ips on subnets that are then attached to # vm instances. Equivalent of 'neutron port-create egle-net --fixed-ip ip_address=11.11.11.3' def create_ip_ports(destination, port): neutron = get_neutron(destination) try: corspd_network = find_corresponding_network_name_by_id(port['network_id']) except Exception, e: print "Couldn't find a matching network, please check that source and destination networks match." return if port['device_owner'].startswith('network:floatingip'): fip = find_float_by_floatip('from', port['fixed_ips'][0]['ip_address']) corspd_tenant = keystone_common.find_opposite_project_id(fip['tenant_id']) else: corspd_tenant = keystone_common.find_opposite_project_id(port['tenant_id']) # print "old port tenant", port['tenant_id'] # print "corresponding tenant in port creation", corspd_tenant print port try: if port['device_owner'].startswith('network:floatingip'): print "---------" body = { "floatingip": { "floating_network_id": corspd_network['id'], "floating_ip_address": port['fixed_ips'][0]['ip_address'], "tenant_id": corspd_tenant['to_id'], # "mac_address": port['mac_address']