本文整理汇总了Python中nova.db.fixed_ip_update函数的典型用法代码示例。如果您正苦于以下问题:Python fixed_ip_update函数的具体用法?Python fixed_ip_update怎么用?Python fixed_ip_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fixed_ip_update函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self, context):
updates = self.obj_get_changes()
if 'address' in updates:
raise exception.ObjectActionError(action='save',
reason='address is not mutable')
db.fixed_ip_update(context, str(self.address), updates)
self.obj_reset_changes()
示例2: deallocate_ips_by_vif
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref):
"""Deallocate all fixed IPs associated with the specified
virtual interface.
"""
admin_context = context.elevated()
fixed_ips = db.fixed_ips_by_virtual_interface(admin_context,
vif_ref['id'])
# NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry
# associated with the instance-id. This prevents us from handing it
# out again immediately, as allocating it to a new instance before
# a DHCP lease has timed-out is bad. Instead, the fixed-ip will
# be disassociated with the instance-id by a call to one of two
# methods inherited from FlatManager:
# - if DHCP is in use, a lease expiring in dnsmasq triggers
# a call to release_fixed_ip in the network manager.
# - otherwise, _disassociate_stale_fixed_ips is called periodically
# to disassociate all fixed ips that are unallocated
# but still associated with an instance-id.
for fixed_ip in fixed_ips:
db.fixed_ip_update(admin_context, fixed_ip['address'],
{'allocated': False,
'virtual_interface_id': None})
if len(fixed_ips) == 0:
LOG.error(_('No fixed IPs to deallocate for vif %s') %
vif_ref['id'])
示例3: test_instance_dns
def test_instance_dns(self):
fixedip = '192.168.0.101'
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_update')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get(self.context,
1).AndReturn({'display_name': HOST})
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(fixedip)
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks[0])
db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
networks[0]['id'])
addresses = self.network.instance_dns_manager.get_entries_by_name(HOST)
self.assertEqual(len(addresses), 1)
self.assertEqual(addresses[0], fixedip)
示例4: test_add_fixed_ip_instance_without_vpn_requested_networks
def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.101')
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks[0])
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
networks[0]['id'])
示例5: test_unreserve
def test_unreserve(self):
db.fixed_ip_update(context.get_admin_context(), '10.0.0.100',
{'reserved': True})
self.commands.unreserve('10.0.0.100')
address = db.fixed_ip_get_by_address(context.get_admin_context(),
'10.0.0.100')
self.assertEqual(address['reserved'], False)
示例6: _set_reserved
def _set_reserved(self, context, address, reserved):
try:
fixed_ip = db.fixed_ip_get_by_address(context, address)
db.fixed_ip_update(context, fixed_ip["address"], {"reserved": reserved})
except exception.FixedIpNotFoundForAddress:
msg = _("Fixed IP %s not found") % address
raise webob.exc.HTTPNotFound(explanation=msg)
return webob.exc.HTTPAccepted()
示例7: allocate_fixed_ips
def allocate_fixed_ips(self, context, tenant_id, quantum_net_id, network_tenant_id, vif_rec):
"""Allocates a single fixed IPv4 address for a virtual interface."""
admin_context = context.elevated()
network = db.network_get_by_uuid(admin_context, quantum_net_id)
address = None
if network["cidr"]:
address = db.fixed_ip_associate_pool(admin_context, network["id"], vif_rec["instance_id"])
values = {"allocated": True, "virtual_interface_id": vif_rec["id"]}
db.fixed_ip_update(admin_context, address, values)
return [address]
示例8: deallocate_ips_by_vif
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref):
"""Deallocate all fixed IPs associated with the specified
virtual interface.
"""
admin_context = context.elevated()
fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref["id"])
for fixed_ip in fixed_ips:
db.fixed_ip_update(admin_context, fixed_ip["address"], {"allocated": False, "virtual_interface_id": None})
if len(fixed_ips) == 0:
LOG.error(_("No fixed IPs to deallocate for vif %s" % vif_ref["id"]))
示例9: _set_reserved
def _set_reserved(self, address, reserved):
ctxt = context.get_admin_context()
try:
fixed_ip = db.fixed_ip_get_by_address(ctxt, address)
if fixed_ip is None:
raise exception.NotFound("Could not find address")
db.fixed_ip_update(ctxt, fixed_ip["address"], {"reserved": reserved})
except exception.NotFound as ex:
print _("error: %s") % ex
return 2
示例10: allocate_fixed_ip
def allocate_fixed_ip(self, context, tenant_id, quantum_net_id, vif_rec):
"""Allocates a single fixed IPv4 address for a virtual interface."""
admin_context = context.elevated()
network = db.network_get_by_uuid(admin_context, quantum_net_id)
if network['cidr']:
address = db.fixed_ip_associate_pool(admin_context,
network['id'],
vif_rec['instance_id'])
values = {'allocated': True,
'virtual_interface_id': vif_rec['id']}
db.fixed_ip_update(admin_context, address, values)
示例11: _set_reserved
def _set_reserved(self, address, reserved):
ctxt = context.get_admin_context()
try:
fixed_ip = db.fixed_ip_get_by_address(ctxt, address)
if fixed_ip is None:
raise exception.NotFound('Could not find address')
db.fixed_ip_update(ctxt, fixed_ip['address'],
{'reserved': reserved})
except exception.NotFound as ex:
print(_("error: %s") % ex)
return(2)
示例12: deallocate_ips_by_vif
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref):
"""Deallocate all fixed IPs associated with the specified
virtual interface.
"""
admin_context = context.elevated()
fixed_ips = db.fixed_ips_by_virtual_interface(admin_context,
vif_ref['id'])
for fixed_ip in fixed_ips:
db.fixed_ip_update(admin_context, fixed_ip['address'],
{'allocated': False,
'virtual_interface_id': None})
if len(fixed_ips) == 0:
LOG.error(_('No fixed IPs to deallocate for vif %s'),
vif_ref['id'])
示例13: deallocate_ips_by_vif
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref):
"""Deallocate all fixed IPs associated with the specified
virtual interface.
"""
try:
admin_context = context.elevated()
fixed_ips = db.fixed_ip_get_by_virtual_interface(admin_context,
vif_ref['id'])
for fixed_ip in fixed_ips:
db.fixed_ip_update(admin_context, fixed_ip['address'],
{'allocated': False,
'virtual_interface_id': None})
except exception.FixedIpNotFoundForInstance:
LOG.error(_('No fixed IPs to deallocate for vif %s' %
vif_ref['id']))
示例14: test_network_delete_safe
def test_network_delete_safe(self):
ctxt = context.get_admin_context()
values = {"host": "localhost", "project_id": "project1"}
network = db.network_create_safe(ctxt, values)
db_network = db.network_get(ctxt, network.id)
values = {"network_id": network["id"], "address": "fake1"}
address1 = db.fixed_ip_create(ctxt, values)
values = {"network_id": network["id"], "address": "fake2", "allocated": True}
address2 = db.fixed_ip_create(ctxt, values)
self.assertRaises(exception.NetworkInUse, db.network_delete_safe, ctxt, network["id"])
db.fixed_ip_update(ctxt, address2, {"allocated": False})
network = db.network_delete_safe(ctxt, network["id"])
ctxt = ctxt.elevated(read_deleted="yes")
fixed_ip = db.fixed_ip_get_by_address(ctxt, address1)
self.assertTrue(fixed_ip["deleted"])
示例15: test_vpn_allocate_fixed_ip
def test_vpn_allocate_fixed_ip(self):
self.mox.StubOutWithMock(db, "fixed_ip_associate")
self.mox.StubOutWithMock(db, "fixed_ip_update")
self.mox.StubOutWithMock(db, "virtual_interface_get_by_instance_and_network")
db.fixed_ip_associate(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), reserved=True).AndReturn("192.168.0.1")
db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
{"id": 0}
)
self.mox.ReplayAll()
network = dict(networks[0])
network["vpn_private_address"] = "192.168.0.2"
self.network.allocate_fixed_ip(None, 0, network, vpn=True)