def _remove_autonetwork(self, server_networks, request): """ Removes the automatically created network that was used prior to v1.4. """ server_networks_keys = list(server_networks.keys()) neutron_enabled = is_enabled_by_config('network') # delete only if vm has one network if neutron_enabled and len(server_networks) == 1: networks = network_list_for_tenant(request, request.user.tenant_id) autonetwork = filter(lambda network: network.name in server_networks_keys, networks) auto_subnet_name = autonetwork_subnet_name(request) if len(autonetwork) != 1: return autonetwork_subnet = filter(lambda subnet: subnet.name == auto_subnet_name, autonetwork[0].subnets) if len(autonetwork_subnet) != 1: return router = router_list(request, network_id=autonetwork_subnet[0]) if len(router) != 1: return router_remove_interface(request, router[0].id, subnet_id=autonetwork_subnet[0].id) router_delete(request, router[0].id) subnet_delete(request, autonetwork_subnet[0].id) network_delete(request, autonetwork[0].id)
def get_limits(request): """return the user's limits/quota. This includes nova, cinder and if neutron is available the number of attached IP addresses :param request: The request :returns nova, cinder & neutron limits """ cinder_limits = None neutron_limits = {} # get nova & cinder limits reserved = request.GET.get('reserved') == 'true' nova_limits = nova_tenant_absolute_limits(request, reserved) try: cinder_limits = cinder_tenant_absolute_limits(request) except: pass # if neturon is enabled, get the number of floating and attached IP addresses if is_enabled_by_config("network"): neutron_max = tenant_quota_get(request, request.user.tenant_id) for limit in neutron_max: # check if the used ips are really attached to an instance used_ips = [] if limit.name == 'floatingip': neutron_limits['maxTotalFloatingIps'] = limit.limit floating_ip_manager = FloatingIpManager(request) floating_ips = floating_ip_manager.list() neutron_limits['totalFloatingIps'] = len(floating_ips) for ip in floating_ips: if ip.instance_id: used_ips.append(ip) neutron_limits['totalFloatingIpsUsed'] = len(used_ips) return clean_limts(nova_limits), clean_limts(cinder_limits), clean_limts( neutron_limits)
def post(self, request): """Create a server. Create a server using the parameters supplied in the POST application/json object. The required parameters as specified by the underlying novaclient are: :param name: The new server name. :param source_id: The ID of the image to use. :param flavor_id: The ID of the flavor to use. :param key_name: (optional extension) name of previously created keypair to inject into the instance. :param user_data: user data to pass to be exposed by the metadata server this can be a file type object as well or a string. :param security_groups: An array of one or more objects with a "name" attribute. Other parameters are accepted as per the underlying novaclient: "block_device_mapping", "block_device_mapping_v2", "nics", "meta", "availability_zone", "instance_count", "admin_pass", "disk_config", "config_drive" This returns the new server object on success. """ default_user = "" user_email = "" floating_ip_manager = FloatingIpManager(request) security_groups = request.DATA['security_groups'] neutron_enabled = is_enabled_by_config('neutron') # default user for instance if 'default_user' in request.DATA: default_user = request.DATA['default_user'] self._create_and_add_security_group(security_groups) nics, floating_ip = self._get_nics_and_floating_ip(floating_ip_manager, neutron_enabled) args = self._verify_arguments(security_groups) # set keyword arguments kw = { 'nics': nics, 'disk_config': "AUTO", 'availability_zone': "nova", 'meta': { SW_METADATA[0]: SW_METADATA[1] } } instance = server_create(*args, **kw) self._associate_floating_ip(neutron_enabled, floating_ip_manager, instance, floating_ip, request) if settings.HORIZON_CONFIG['SW_SEND_VM_CREATED_NOTIFICATION']: LOG.debug("Servers.create(): Send Email") user_email = send_create_email(request, floating_ip, default_user, request.DATA['name']) return rest_utils.CreatedResponse( '/api/nova/servers/%s' % utils_http.urlquote(instance.id), { "instance": instance.to_dict(), "email": user_email, "network": PRIVATE_NETWORK } )