本文整理汇总了Python中aquilon.worker.processes.DSDBRunner.add_host_details方法的典型用法代码示例。如果您正苦于以下问题:Python DSDBRunner.add_host_details方法的具体用法?Python DSDBRunner.add_host_details怎么用?Python DSDBRunner.add_host_details使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aquilon.worker.processes.DSDBRunner
的用法示例。
在下文中一共展示了DSDBRunner.add_host_details方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [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
示例2: add_srv_dsdb_callback
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [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")
示例3: del_srv_dsdb_callback
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [as 别名]
def del_srv_dsdb_callback(session, logger, holder, dbsrv_addr, oldinfo, keep_dns):
dsdb_runner = DSDBRunner(logger=logger)
toplevel_holder = holder.toplevel_holder_object
if isinstance(toplevel_holder, Host):
dsdb_runner.update_host(toplevel_holder.hardware_entity, oldinfo)
if keep_dns:
dsdb_runner.add_host_details(
dbsrv_addr.dns_record.fqdn, dbsrv_addr.dns_record.ip, comments=dbsrv_addr.dns_record.comments
)
elif not keep_dns:
dsdb_runner.delete_host_details(str(dbsrv_addr.dns_record.fqdn), dbsrv_addr.dns_record.ip)
dsdb_runner.commit_or_rollback("Could not delete host from DSDB")
示例4: del_srv_dsdb_callback
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [as 别名]
def del_srv_dsdb_callback(session, logger, holder, dbsrv_addr, oldinfo,
keep_dns):
real_holder = holder.holder_object
if isinstance(real_holder, ResourceGroup):
real_holder = real_holder.holder.holder_object
dsdb_runner = DSDBRunner(logger=logger)
if isinstance(real_holder, Host):
dsdb_runner.update_host(real_holder.machine, oldinfo)
if keep_dns:
dsdb_runner.add_host_details(dbsrv_addr.dns_record.fqdn,
dbsrv_addr.dns_record.ip,
comments=dbsrv_addr.dns_record.comments)
elif not keep_dns:
dsdb_runner.delete_host_details(str(dbsrv_addr.dns_record.fqdn),
dbsrv_addr.dns_record.ip)
dsdb_runner.commit_or_rollback("Could not delete host from DSDB")
示例5: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [as 别名]
#.........这里部分代码省略.........
hwname = machine
elif chassis:
hwtype = "chassis"
hwname = chassis
elif switch:
hwtype = "switch"
hwname = switch
dbhw_ent = HardwareEntity.get_unique(session, hwname, hardware_type=hwtype, compel=True)
dbinterface = Interface.get_unique(session, hardware_entity=dbhw_ent, name=interface, compel=True)
dbnet_env = NetworkEnvironment.get_unique_or_default(session, network_environment)
oldinfo = DSDBRunner.snapshot_hw(dbhw_ent)
if fqdn:
dbdns_rec = ARecord.get_unique(session, fqdn=fqdn, dns_environment=dbnet_env.dns_environment, compel=True)
ip = dbdns_rec.ip
addr = None
if ip:
addr = first_of(dbinterface.assignments, lambda x: x.ip == ip)
if not addr:
raise ArgumentError("{0} does not have IP address {1} assigned to " "it.".format(dbinterface, ip))
elif label is not None:
addr = first_of(dbinterface.assignments, lambda x: x.label == label)
if not addr:
raise ArgumentError("{0} does not have an address with label " "{1}.".format(dbinterface, label))
if not addr:
raise ArgumentError("Please specify the address to be removed " "using either --ip, --label, or --fqdn.")
dbnetwork = addr.network
ip = addr.ip
if dbnetwork.network_environment != dbnet_env:
raise ArgumentError(
"The specified address lives in {0:l}, not in "
"{1:l}. Use the --network_environment option "
"to select the correct environment.".format(dbnetwork.network_environment, dbnet_env)
)
# Forbid removing the primary name
if ip == dbhw_ent.primary_ip:
raise ArgumentError("The primary IP address of a hardware entity " "cannot be removed.")
dbinterface.assignments.remove(addr)
# Check if the address was assigned to multiple interfaces, and remove
# the DNS entries if this was the last use
q = session.query(AddressAssignment)
q = q.filter_by(network=dbnetwork)
q = q.filter_by(ip=ip)
other_uses = q.all()
if not other_uses and not keep_dns:
q = session.query(ARecord)
q = q.filter_by(network=dbnetwork)
q = q.filter_by(ip=ip)
q = q.join(ARecord.fqdn)
q = q.filter_by(dns_environment=dbnet_env.dns_environment)
map(delete_dns_record, q.all())
session.flush()
dbhost = getattr(dbhw_ent, "host", None)
if dbhost:
plenary_info = PlenaryHost(dbhost, logger=logger)
key = plenary_info.get_write_key()
try:
lock_queue.acquire(key)
try:
plenary_info.write(locked=True)
except IncompleteError:
# FIXME: if this command is used after "add host" but before
# "make", then writing out the template will fail due to
# required services not being assigned. Ignore this error
# for now.
plenary_info.restore_stash()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbhw_ent, oldinfo)
if not other_uses and keep_dns:
q = session.query(ARecord)
q = q.filter_by(network=dbnetwork)
q = q.filter_by(ip=ip)
dbdns_rec = q.first()
dsdb_runner.add_host_details(dbdns_rec.fqdn, ip)
dsdb_runner.commit_or_rollback("Could not add host to DSDB")
except:
plenary_info.restore_stash()
raise
finally:
lock_queue.release(key)
else:
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.update_host(dbhw_ent, oldinfo)
dsdb_runner.commit_or_rollback("Could not add host to DSDB")
return
示例6: render
# 需要导入模块: from aquilon.worker.processes import DSDBRunner [as 别名]
# 或者: from aquilon.worker.processes.DSDBRunner import add_host_details [as 别名]
def render(self, session, logger, startip, endip, dns_domain, prefix,
**arguments):
if not prefix:
prefix = 'dynamic'
dbnet_env = NetworkEnvironment.get_unique_or_default(session)
dbdns_env = DnsEnvironment.get_unique_or_default(session)
startnet = get_net_id_from_ip(session, startip, dbnet_env)
endnet = get_net_id_from_ip(session, endip, dbnet_env)
if startnet != endnet:
raise ArgumentError("IP addresses %s (%s) and %s (%s) must be on "
"the same subnet." %
(startip, startnet.ip, endip, endnet.ip))
dbdns_domain = DnsDomain.get_unique(session, dns_domain, compel=True)
dbdns_domain.lock_row()
startnet.lock_row()
q = session.query(AddressAssignment.ip)
q = q.filter_by(network=startnet)
q = q.filter(AddressAssignment.ip >= startip)
q = q.filter(AddressAssignment.ip <= endip)
q = q.order_by(AddressAssignment.ip)
conflicts = q.all()
if conflicts:
raise ArgumentError("Cannot allocate the address range because the "
"following IP addresses are already in use:\n" +
", ".join([str(c.ip) for c in conflicts]))
# No filtering on DNS environment. If an address is dynamic in one
# environment, it should not be considered static in a different
# environment.
q = session.query(ARecord)
q = q.filter_by(network=startnet)
q = q.filter(ARecord.ip >= startip)
q = q.filter(ARecord.ip <= endip)
q = q.order_by(ARecord.ip)
conflicts = q.all()
if conflicts:
raise ArgumentError("Cannot allocate the address range because the "
"following DNS records already exist:\n" +
"\n".join([format(c, "a") for c in conflicts]))
dsdb_runner = DSDBRunner(logger=logger)
with session.no_autoflush:
for ipint in range(int(startip), int(endip) + 1):
ip = IPv4Address(ipint)
check_ip_restrictions(startnet, ip)
name = "%s-%s" % (prefix, str(ip).replace('.', '-'))
dbfqdn = Fqdn.get_or_create(session, name=name,
dns_domain=dbdns_domain,
dns_environment=dbdns_env,
preclude=True)
dbdynamic_stub = DynamicStub(fqdn=dbfqdn, ip=ip, network=startnet)
session.add(dbdynamic_stub)
dsdb_runner.add_host_details(dbfqdn, ip)
session.flush()
# This may take some time if the range is big, so be verbose
dsdb_runner.commit_or_rollback("Could not add addresses to DSDB",
verbose=True)
return