def create(self, req, body): """Bulk create floating ips.""" context = req.environ['nova.context'] authorize(context) if not 'floating_ips_bulk_create' in body: raise webob.exc.HTTPUnprocessableEntity() params = body['floating_ips_bulk_create'] LOG.debug(params) if not 'ip_range' in params: raise webob.exc.HTTPUnprocessableEntity() ip_range = params['ip_range'] pool = params.get('pool', CONF.default_floating_pool) interface = params.get('interface', CONF.public_interface) try: ips = ({'address': str(address), 'pool': pool, 'interface': interface} for address in self._address_to_hosts(ip_range)) except exception.InvalidInput as exc: raise webob.exc.HTTPBadRequest(explanation=str(exc)) try: db.floating_ip_bulk_create(context, ips) except exception.FloatingIpExists as exc: raise webob.exc.HTTPBadRequest(explanation=str(exc)) return {"floating_ips_bulk_create": {"ip_range": ip_range, "pool": pool, "interface": interface}}
def create(self, ip_range, pool=None, interface=None): """Creates floating ips for zone by range.""" admin_context = context.get_admin_context() if not pool: pool = CONF.default_floating_pool if not interface: interface = CONF.public_interface ips = ({'address': str(address), 'pool': pool, 'interface': interface} for address in self.address_to_hosts(ip_range)) try: db.floating_ip_bulk_create(admin_context, ips) except exception.FloatingIpExists as exc: # NOTE(simplylizz): Maybe logging would be better here # instead of printing, but logging isn't used here and I # don't know why. print('error: %s' % exc) return(1)
def _create_floating_ips(self, floating_ips=None): """Create a floating ip object.""" if floating_ips is None: floating_ips = [self.floating_ip] elif not isinstance(floating_ips, (list, tuple)): floating_ips = [floating_ips] dict_ = {"pool": "nova", "host": "fake_host"} return db.floating_ip_bulk_create(self.context, [dict(address=ip, **dict_) for ip in floating_ips])
def _create_floating_ips(self, floating_ips=None): """Create a floating IP object.""" if floating_ips is None: floating_ips = [self.floating_ip] elif not isinstance(floating_ips, (list, tuple)): floating_ips = [floating_ips] dict_ = {'pool': 'nova', 'host': 'fake_host'} return db.floating_ip_bulk_create( self.context, [dict(address=ip, **dict_) for ip in floating_ips], )
def _create_floating_ips(self, floating_ips=None): """Create a floating ip object.""" if floating_ips is None: floating_ips = [self.floating_ip] elif not isinstance(floating_ips, (list, tuple)): floating_ips = [floating_ips] def make_ip_dict(ip): """Shortcut for creating floating ip dict.""" return dict_ = {'pool': 'nova', 'host': 'fake_host'} return db.floating_ip_bulk_create( self.context, [dict(address=ip, **dict_) for ip in floating_ips], )
def create(cls, context, ip_info, want_result=False): db_floatingips = db.floating_ip_bulk_create(context, ip_info) if want_result: return obj_base.obj_make_list(context, cls(), FloatingIP, db_floatingips)