本文整理汇总了Python中nova.db.floating_ip_bulk_create函数的典型用法代码示例。如果您正苦于以下问题:Python floating_ip_bulk_create函数的具体用法?Python floating_ip_bulk_create怎么用?Python floating_ip_bulk_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了floating_ip_bulk_create函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
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}}
示例2: create
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)
示例3: _create_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])
示例4: _create_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],
)
示例5: create
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)