本文整理汇总了Python中aquilon.worker.processes.DSDBRunner.commit_or_rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DSDBRunner.commit_or_rollback方法的具体用法?Python DSDBRunner.commit_or_rollback怎么用?Python DSDBRunner.commit_or_rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aquilon.worker.processes.DSDBRunner
的用法示例。
在下文中一共展示了DSDBRunner.commit_or_rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, city, country, fullname, comments,
timezone, campus,
**arguments):
if country:
dbparent = Country.get_unique(session, country, compel=True)
else:
dbparent = Campus.get_unique(session, campus, compel=True)
dbcity = add_location(session, City, city, dbparent, fullname=fullname,
comments=comments, timezone=timezone)
session.flush()
plenary = Plenary.get_plenary(dbcity, logger=logger)
with plenary.get_key():
try:
plenary.write(locked=True)
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.add_city(city, dbcity.country.name, fullname)
dsdb_runner.commit_or_rollback()
except:
plenary.restore_stash()
raise
return
示例2: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, interface, chassis, mac, comments,
rename_to, **arguments):
for arg in self.invalid_parameters:
if arguments.get(arg) is not None:
raise UnimplementedError("update_interface --chassis cannot use "
"the --%s option." % arg)
dbchassis = Chassis.get_unique(session, chassis, compel=True)
dbinterface = Interface.get_unique(session, hardware_entity=dbchassis,
name=interface, compel=True)
oldinfo = DSDBRunner.snapshot_hw(dbchassis)
if comments:
dbinterface.comments = comments
if mac:
dbinterface.mac = mac
if rename_to:
rename_interface(session, dbinterface, rename_to)
session.flush()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbchassis, oldinfo)
dsdb_runner.commit_or_rollback("Could not update chassis in DSDB")
return
示例3: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, chassis, model, rack, ip, vendor, serial,
comments, **arguments):
dbchassis = Chassis.get_unique(session, chassis, compel=True)
oldinfo = DSDBRunner.snapshot_hw(dbchassis)
if vendor and not model:
model = dbchassis.model.name
if model:
dbmodel = Model.get_unique(session, name=model, vendor=vendor,
model_type=ChassisType.Chassis,
compel=True)
dbchassis.model = dbmodel
dblocation = get_location(session, rack=rack)
if dblocation:
dbchassis.location = dblocation
if serial is not None:
dbchassis.serial_no = serial
if ip:
update_primary_ip(session, logger, dbchassis, ip)
if comments is not None:
dbchassis.comments = comments
session.flush()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbchassis, oldinfo)
dsdb_runner.commit_or_rollback("Could not update chassis in DSDB")
return
示例4: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, interface, chassis, mac, iftype, type,
comments, **arguments):
if type:
self.deprecated_option("type", "Please use --iftype "
"instead.", logger=logger, **arguments)
if not iftype:
iftype = type
if iftype and iftype != "oa":
raise ArgumentError("Only 'oa' is allowed as the interface type "
"for chassis.")
for arg in self.invalid_parameters:
if arguments.get(arg) is not None:
raise ArgumentError("Cannot use argument --%s when adding an "
"interface to a chassis." % arg)
dbchassis = Chassis.get_unique(session, chassis, compel=True)
oldinfo = DSDBRunner.snapshot_hw(dbchassis)
get_or_create_interface(session, dbchassis, name=interface, mac=mac,
interface_type='oa', comments=comments,
preclude=True)
session.flush()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbchassis, oldinfo)
dsdb_runner.commit_or_rollback("Could not update chassis in DSDB")
return
示例5: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, fqdn, dns_environment, target, comments,
**kwargs):
dbdns_env = DnsEnvironment.get_unique_or_default(session,
dns_environment)
dbalias = Alias.get_unique(session, fqdn=fqdn,
dns_environment=dbdns_env, compel=True)
old_target_fqdn = str(dbalias.target.fqdn)
old_comments = dbalias.comments
if target:
old_target = dbalias.target
dbalias.target = create_target_if_needed(session, logger,
target, dbdns_env)
if dbalias.target != old_target:
delete_target_if_needed(session, old_target)
if comments is not None:
dbalias.comments = comments
session.flush()
if dbdns_env.is_default and dbalias.fqdn.dns_domain.name == "ms.com":
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_alias(fqdn, dbalias.target.fqdn,
dbalias.comments, old_target_fqdn,
old_comments)
dsdb_runner.commit_or_rollback("Could not update alias in DSDB")
return
示例6: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, city, **arguments):
dbcity = get_location(session, city=city)
name = dbcity.name
country = dbcity.country.name
fullname = dbcity.fullname
plenary = PlenaryCity(dbcity, logger=logger)
CommandDelLocation.render(self, session=session, name=city,
type='city', **arguments)
session.flush()
key = plenary.get_remove_key()
try:
lock_queue.acquire(key)
plenary.remove(locked=True)
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.del_city(name, country, fullname)
dsdb_runner.commit_or_rollback()
except:
plenary.restore_stash()
raise
finally:
lock_queue.release(key)
return
示例7: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, interface, switch, mac, type, comments,
**arguments):
if type and type not in self.valid_interface_types:
raise ArgumentError("Interface type %s is not allowed for "
"switches." % type)
if not type:
if interface.lower().startswith("lo"):
type = "loopback"
else:
type = "oa"
for arg in self.invalid_parameters:
if arguments.get(arg) is not None:
raise ArgumentError("Cannot use argument --%s when adding an "
"interface to a switch." % arg)
dbswitch = Switch.get_unique(session, switch, compel=True)
oldinfo = DSDBRunner.snapshot_hw(dbswitch)
dbinterface = get_or_create_interface(session, dbswitch,
name=interface, mac=mac,
interface_type=type,
comments=comments, preclude=True)
session.flush()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbswitch, oldinfo)
dsdb_runner.commit_or_rollback("Could not update switch in DSDB")
return
示例8: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, fqdn, dns_environment,
network_environment, reverse_ptr, comments, **arguments):
dbnet_env, dbdns_env = get_net_dns_env(session, network_environment,
dns_environment)
audit_results = []
ip = generate_ip(session, logger, compel=True, dbinterface=None,
network_environment=dbnet_env,
audit_results=audit_results, **arguments)
# TODO: add allow_multi=True
dbdns_rec, newly_created = grab_address(session, fqdn, ip, dbnet_env,
dbdns_env, comments=comments,
preclude=True)
if reverse_ptr:
set_reverse_ptr(session, logger, dbdns_rec, reverse_ptr)
session.flush()
if dbdns_rec.fqdn.dns_environment.is_default:
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.add_host_details(dbdns_rec.fqdn, ip, comments=comments)
dsdb_runner.commit_or_rollback("Could not add address to DSDB")
for name, value in audit_results:
self.audit_result(session, name, value, **arguments)
return
示例9: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, city, timezone, campus,
default_dns_domain, comments, **arguments):
dbcity = get_location(session, city=city)
# Updating machine templates is expensive, so only do that if needed
update_machines = False
if timezone is not None:
dbcity.timezone = timezone
if comments is not None:
dbcity.comments = comments
if default_dns_domain is not None:
if default_dns_domain:
dbdns_domain = DnsDomain.get_unique(session, default_dns_domain,
compel=True)
dbcity.default_dns_domain = dbdns_domain
else:
dbcity.default_dns_domain = None
prev_campus = None
dsdb_runner = None
dsdb_runner = DSDBRunner(logger=logger)
if campus is not None:
dbcampus = get_location(session, campus=campus)
# This one would change the template's locations hence forbidden
if dbcampus.hub != dbcity.hub:
# Doing this both to reduce user error and to limit
# testing required.
raise ArgumentError("Cannot change campus. {0} is in {1:l}, "
"while {2:l} is in {3:l}.".format(
dbcampus, dbcampus.hub,
dbcity, dbcity.hub))
if dbcity.campus:
prev_campus = dbcity.campus
dbcity.update_parent(parent=dbcampus)
update_machines = True
session.flush()
if campus is not None:
if prev_campus:
prev_name = prev_campus.name
else:
prev_name = None
dsdb_runner.update_city(city, dbcampus.name, prev_name)
plenaries = PlenaryCollection(logger=logger)
plenaries.append(Plenary.get_plenary(dbcity))
if update_machines:
q = session.query(Machine)
q = q.filter(Machine.location_id.in_(dbcity.offspring_ids()))
logger.client_info("Updating %d machines..." % q.count())
for dbmachine in q:
plenaries.append(Plenary.get_plenary(dbmachine))
count = plenaries.write()
dsdb_runner.commit_or_rollback()
logger.client_info("Flushed %d templates." % count)
示例10: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, switch, **arguments):
dbswitch = Switch.get_unique(session, switch, compel=True)
# Check and complain if the switch has any other addresses than its
# primary address
addrs = []
for addr in dbswitch.all_addresses():
if addr.ip == dbswitch.primary_ip:
continue
addrs.append(str(addr.ip))
if addrs:
raise ArgumentError("{0} still provides the following addresses, "
"delete them first: {1}.".format
(dbswitch, ", ".join(addrs)))
dbdns_rec = dbswitch.primary_name
ip = dbswitch.primary_ip
old_fqdn = str(dbswitch.primary_name.fqdn)
old_comments = dbswitch.comments
session.delete(dbswitch)
if dbdns_rec:
delete_dns_record(dbdns_rec)
session.flush()
# Any switch ports hanging off this switch should be deleted with
# the cascade delete of the switch.
switch_plenary = Plenary.get_plenary(dbswitch, logger=logger)
# clusters connected to this switch
plenaries = PlenaryCollection(logger=logger)
for dbcluster in dbswitch.esx_clusters:
plenaries.append(Plenary.get_plenary(dbcluster))
key = CompileKey.merge([switch_plenary.get_remove_key(),
plenaries.get_write_key()])
try:
lock_queue.acquire(key)
switch_plenary.stash()
plenaries.write(locked=True)
switch_plenary.remove(locked=True)
if ip:
dsdb_runner = DSDBRunner(logger=logger)
# FIXME: restore interface name/MAC on rollback
dsdb_runner.delete_host_details(old_fqdn, ip, comments=old_comments)
dsdb_runner.commit_or_rollback("Could not remove switch from DSDB")
return
except:
plenaries.restore_stash()
switch_plenary.restore_stash()
raise
finally:
lock_queue.release(key)
示例11: del_dynamic_stubs
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def del_dynamic_stubs(self, session, logger, dbstubs):
dsdb_runner = DSDBRunner(logger=logger)
for stub in dbstubs:
dsdb_runner.delete_host_details(str(stub.fqdn), stub.ip)
delete_dns_record(stub)
session.flush()
# This may take some time if the range is big, so be verbose
dsdb_runner.commit_or_rollback(verbose=True)
示例12: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, network_device, label, model, type, ip,
interface, iftype, mac, vendor, serial, comments, **arguments):
dbmodel = Model.get_unique(session, name=model, vendor=vendor,
compel=True)
if not dbmodel.model_type.isNetworkDeviceType():
raise ArgumentError("This command can only be used to "
"add network devices.")
dblocation = get_location(session, compel=True, **arguments)
dbdns_rec, newly_created = grab_address(session, network_device, ip,
allow_restricted_domain=True,
allow_reserved=True,
preclude=True)
if not label:
label = dbdns_rec.fqdn.name
try:
NetworkDevice.check_label(label)
except ArgumentError:
raise ArgumentError("Could not deduce a valid hardware label "
"from the network device name. Please specify "
"--label.")
# FIXME: What do the error messages for an invalid enum (switch_type)
# look like?
dbnetdev = NetworkDevice(label=label, switch_type=type,
location=dblocation, model=dbmodel,
serial_no=serial, comments=comments)
session.add(dbnetdev)
dbnetdev.primary_name = dbdns_rec
check_netdev_iftype(iftype)
dbinterface = get_or_create_interface(session, dbnetdev,
name=interface, mac=mac,
interface_type=iftype)
dbnetwork = get_net_id_from_ip(session, ip)
# TODO: should we call check_ip_restrictions() here?
assign_address(dbinterface, ip, dbnetwork, logger=logger)
session.flush()
plenary = Plenary.get_plenary(dbnetdev, logger=logger)
with plenary.get_key():
plenary.stash()
try:
plenary.write(locked=True)
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbnetdev, None)
dsdb_runner.commit_or_rollback("Could not add network device to DSDB")
except:
plenary.restore_stash()
raise
return
示例13: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, network_device, **arguments):
dbnetdev = NetworkDevice.get_unique(session, network_device, compel=True)
# Check and complain if the network device has any other addresses than its
# primary address
addrs = []
for addr in dbnetdev.all_addresses():
if addr.ip == dbnetdev.primary_ip:
continue
addrs.append(str(addr.ip))
if addrs:
raise ArgumentError("{0} still provides the following addresses, "
"delete them first: {1}.".format
(dbnetdev, ", ".join(addrs)))
dbdns_rec = dbnetdev.primary_name
ip = dbnetdev.primary_ip
old_fqdn = str(dbnetdev.primary_name.fqdn)
old_comments = dbnetdev.comments
session.delete(dbnetdev)
if dbdns_rec:
delete_dns_record(dbdns_rec)
session.flush()
# Any network device ports hanging off this network device should be deleted with
# the cascade delete of the network device.
netdev_plenary = Plenary.get_plenary(dbnetdev, logger=logger)
# clusters connected to this network device
plenaries = PlenaryCollection(logger=logger)
for dbcluster in dbnetdev.esx_clusters:
plenaries.append(Plenary.get_plenary(dbcluster))
with CompileKey.merge([netdev_plenary.get_key(), plenaries.get_key()]):
netdev_plenary.stash()
try:
plenaries.write(locked=True)
netdev_plenary.remove(locked=True)
if ip:
dsdb_runner = DSDBRunner(logger=logger)
# FIXME: restore interface name/MAC on rollback
dsdb_runner.delete_host_details(old_fqdn, ip,
comments=old_comments)
dsdb_runner.commit_or_rollback("Could not remove network device "
"from DSDB")
except:
plenaries.restore_stash()
netdev_plenary.restore_stash()
raise
return
示例14: add_srv_dsdb_callback
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def add_srv_dsdb_callback(session, logger, dbsrv, real_holder=None, oldinfo=None, newly_created=None, comments=None):
dsdb_runner = DSDBRunner(logger=logger)
if not newly_created:
dsdb_runner.delete_host_details(dbsrv.dns_record.fqdn, dbsrv.dns_record.ip)
if isinstance(real_holder, Host):
dsdb_runner.update_host(real_holder.machine, oldinfo)
else:
dsdb_runner.add_host_details(dbsrv.dns_record.fqdn, dbsrv.dns_record.ip, comments=comments)
dsdb_runner.commit_or_rollback("Could not add host to DSDB")
示例15: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import commit_or_rollback [as 别名]
def render(self, session, logger, hostname, manager, interface, mac,
comments, **arguments):
dbhost = hostname_to_host(session, hostname)
dbmachine = dbhost.machine
oldinfo = DSDBRunner.snapshot_hw(dbmachine)
if not manager:
manager = "%sr.%s" % (dbmachine.primary_name.fqdn.name,
dbmachine.primary_name.fqdn.dns_domain.name)
dbinterface = get_or_create_interface(session, dbmachine,
name=interface, mac=mac,
interface_type='management')
addrs = ", ".join(["%s [%s]" % (addr.logical_name, addr.ip) for addr
in dbinterface.assignments])
if addrs:
raise ArgumentError("{0} already has the following addresses: "
"{1}.".format(dbinterface, addrs))
audit_results = []
ip = generate_ip(session, logger, dbinterface, compel=True,
audit_results=audit_results, **arguments)
dbdns_rec, newly_created = grab_address(session, manager, ip,
comments=comments,
preclude=True)
assign_address(dbinterface, ip, dbdns_rec.network)
session.flush()
plenary_info = PlenaryMachineInfo(dbmachine, logger=logger)
key = plenary_info.get_write_key()
try:
lock_queue.acquire(key)
plenary_info.write(locked=True)
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbmachine, oldinfo)
dsdb_runner.commit_or_rollback("Could not add host to DSDB")
except:
plenary_info.restore_stash()
raise
finally:
lock_queue.release(key)
if dbmachine.host:
# XXX: Host needs to be reconfigured.
pass
for name, value in audit_results:
self.audit_result(session, name, value, **arguments)
return