本文整理汇总了Python中aquilon.aqdb.model.Personality类的典型用法代码示例。如果您正苦于以下问题:Python Personality类的具体用法?Python Personality怎么用?Python Personality使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Personality类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
def render(self, generate, session, logger, personality, archetype,
pre_feature, post_feature, param_tmpl, **kwargs):
dbpersonality = Personality.get_unique(session, archetype=archetype,
name=personality, compel=True)
if pre_feature:
plenary = PlenaryPersonalityPreFeature.get_plenary(dbpersonality,
logger=logger)
elif post_feature:
plenary = PlenaryPersonalityPostFeature.get_plenary(dbpersonality,
logger=logger)
elif param_tmpl:
param_templates = get_parameters_by_tmpl(dbpersonality)
if param_tmpl in param_templates.keys():
values = param_templates[param_tmpl]
else:
values = {}
ptmpl = ParameterTemplate(dbpersonality, param_tmpl, values)
plenary = PlenaryPersonalityParameter(ptmpl, logger=logger)
else:
plenary = PlenaryPersonalityBase.get_plenary(dbpersonality,
logger=logger)
if generate:
return plenary._generate_content()
else:
return plenary.read()
示例2: validate_personality_config
def validate_personality_config(session, archetype, personality):
"""
Validates all the parameters on personality to validate
if all required parameters have been set. All feature
parameters are also validated.
"""
dbpersonality = None
if isinstance(personality, Personality):
dbpersonality = personality
else:
dbpersonality = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
dbarchetype = dbpersonality.archetype
error = []
## validate parameters
param_definitions = []
parameters = get_parameters(session, personality=dbpersonality)
if dbarchetype.paramdef_holder:
param_definitions = dbarchetype.paramdef_holder.param_definitions
error += validate_required_parameter(param_definitions, parameters)
## features for personalities
for link in dbarchetype.features + dbpersonality.features:
param_definitions = []
if link.feature.paramdef_holder:
param_definitions = link.feature.paramdef_holder.param_definitions
tmp_error = validate_required_parameter(param_definitions, parameters, link)
if tmp_error:
error.append("Feature Binding : %s" % link.feature)
error += tmp_error
return error
示例3: render
def render(self, generate, session, logger, personality, archetype,
pre_feature, post_feature, param_tmpl, **kwargs):
dbpersonality = Personality.get_unique(session, archetype=archetype,
name=personality, compel=True)
plenary = PlenaryPersonalityBase(dbpersonality, logger=logger)
if pre_feature:
plenary = PlenaryPersonalityPreFeature(dbpersonality, logger=logger)
if post_feature:
plenary = PlenaryPersonalityPostFeature(dbpersonality, logger=logger)
if param_tmpl:
param_templates = get_parameters_by_tmpl(dbpersonality)
if param_tmpl in param_templates.keys():
plenary = PlenaryPersonalityParameter(dbpersonality, param_tmpl,
param_templates[param_tmpl],
logger=logger)
else:
raise NotFoundException("No parameter template %s%s found." %
(param_tmpl, TEMPLATE_EXTENSION))
lines = []
if generate:
lines.append(plenary._generate_content())
else:
lines.append(plenary.read())
return lines
示例4: render
def render(
self, session, gateway, ip, netmask, prefixlen, network_environment, archetype, personality, **arguments
):
dbnet_env = NetworkEnvironment.get_unique_or_default(session, network_environment)
dbnetwork = get_net_id_from_ip(session, gateway, dbnet_env)
if netmask:
dest = IPv4Network("%s/%s" % (ip, netmask))
else:
dest = IPv4Network("%s/%s" % (ip, prefixlen))
if personality:
dbpersonality = Personality.get_unique(session, name=personality, archetype=archetype, compel=True)
else:
dbpersonality = None
q = session.query(StaticRoute)
q = q.filter_by(network=dbnetwork)
q = q.filter_by(gateway_ip=gateway)
q = q.filter_by(dest_ip=dest.ip)
q = q.filter_by(dest_cidr=dest.prefixlen)
q = q.filter_by(personality=dbpersonality)
try:
dbroute = q.one()
except NoResultFound:
raise NotFoundException("Static Route to {0} using gateway {1} " "not found.".format(dest, gateway))
session.delete(dbroute)
session.flush()
# TODO: refresh affected host templates
return
示例5: render
def render(self, session, logger, personality, archetype, vmhost_capacity_function,
vmhost_overcommit_memory, cluster_required, config_override,
host_environment, grn, eon_id, leave_existing, **arguments):
dbpersona = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
if vmhost_capacity_function is not None or \
vmhost_overcommit_memory is not None:
if not "esx" in dbpersona.cluster_infos:
dbpersona.cluster_infos["esx"] = PersonalityESXClusterInfo()
if vmhost_capacity_function:
# Basic sanity tests to see if the function works
try:
global_vars = {'__builtins__': restricted_builtins}
local_vars = {'memory': 10}
capacity = eval(vmhost_capacity_function, global_vars,
local_vars)
except Exception, err:
raise ArgumentError("Failed to evaluate the function: %s" % err)
if not isinstance(capacity, dict):
raise ArgumentError("The function should return a dictonary.")
for name, value in capacity.items():
if not isinstance(name, str) or (not isinstance(value, int) and
not isinstance(value, float)):
raise ArgumentError("The function should return a dictionary "
"with all keys being strings, and all "
"values being numbers.")
# TODO: Should this be mandatory? It is for now.
if "memory" not in capacity:
raise ArgumentError("The memory constraint is missing from "
"the returned dictionary.")
dbpersona.cluster_infos["esx"].vmhost_capacity_function = vmhost_capacity_function
示例6: render
def render(self, session, archetype, personality, other,
other_archetype, **arguments):
dbpersona = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
if not other_archetype:
other_archetype = archetype
db_other_persona = Personality.get_unique(session, name=other,
archetype=other_archetype, compel=True)
ret = defaultdict(dict)
self.populate_data(session, dbpersona, "my", ret)
self.populate_data(session, db_other_persona, "other", ret)
return DiffData(dbpersona, db_other_persona, ret)
示例7: render
def render(self, session, service, archetype, personality, **arguments):
dbpersonality = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
dbservice = Service.get_unique(session, service, compel=True)
if dbpersonality in dbservice.personalities:
raise ArgumentError("Service %s is already required by personality "
"%s, archetype %s." % (service, personality,
archetype))
dbservice.personalities.append(dbpersonality)
return
示例8: render
def render(self, session, service, archetype, personality, **arguments):
dbpersonality = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
dbservice = Service.get_unique(session, service, compel=True)
try:
dbservice.personalities.remove(dbpersonality)
except ValueError:
raise NotFoundException("Service %s required for archetype "
"%s, personality %s not found." %
(service, archetype, personality))
session.flush()
return
示例9: render
def render(self, session, logger, hostname, cluster,
personality, **arguments):
dbcluster = Cluster.get_unique(session, cluster, compel=True)
dbhost = hostname_to_host(session, hostname)
if not dbhost.cluster:
raise ArgumentError("{0} is not bound to a cluster.".format(dbhost))
if dbhost.cluster != dbcluster:
raise ArgumentError("{0} is bound to {1:l}, not {2:l}.".format(
dbhost, dbhost.cluster, dbcluster))
if personality:
dbpersonality = Personality.get_unique(session, name=personality,
archetype=dbhost.archetype,
compel=True)
if dbpersonality.cluster_required:
raise ArgumentError("Cannot switch host to personality %s "
"because that personality requires a "
"cluster" % personality)
dbhost.personality = dbpersonality
elif dbhost.personality.cluster_required:
raise ArgumentError("Host personality %s requires a cluster, "
"use --personality to change personality "
"when leaving the cluster." %
dbhost.personality.name)
dbcluster.hosts.remove(dbhost)
remove_service_addresses(dbcluster, dbhost)
dbcluster.validate()
session.flush()
session.expire(dbhost, ['_cluster'])
# Will need to write a cluster plenary and either write or
# remove a host plenary. Grab the domain key since the two
# must be in the same domain.
host_plenary = Plenary.get_plenary(dbhost, logger=logger)
cluster_plenary = Plenary.get_plenary(dbcluster, logger=logger)
key = CompileKey(domain=dbcluster.branch.name, logger=logger)
try:
lock_queue.acquire(key)
cluster_plenary.write(locked=True)
try:
host_plenary.write(locked=True)
except IncompleteError:
host_plenary.cleanup(domain=dbhost.branch.name, locked=True)
except:
cluster_plenary.restore_stash()
host_plenary.restore_stash()
raise
finally:
lock_queue.release(key)
示例10: get_parameter_holder
def get_parameter_holder(session, archetype=None, personality=None,
auto_include=False):
db_param_holder = None
dbpersonality = None
if isinstance(personality, Personality):
dbpersonality = personality
else:
dbpersonality = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
db_param_holder = dbpersonality.paramholder
if db_param_holder is None and auto_include:
db_param_holder = PersonalityParameter(personality=dbpersonality)
session.add(db_param_holder)
return db_param_holder
示例11: render
def render(self, session, logger, personality, archetype, **arguments):
dbpersona = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
dbhost = session.query(Host).filter_by(personality=dbpersona).first()
dbcls = session.query(Cluster).filter_by(personality=dbpersona).first()
if dbhost or dbcls:
raise ArgumentError("{0} is still in use and cannot be deleted."
.format(dbpersona))
plenary = Plenary.get_plenary(dbpersona, logger=logger)
session.delete(dbpersona)
session.flush()
plenary.remove()
return
示例12: render
def render(self, session, logger, hostname, cluster,
personality, **arguments):
dbcluster = Cluster.get_unique(session, cluster, compel=True)
dbhost = hostname_to_host(session, hostname)
if not dbhost.cluster:
raise ArgumentError("{0} is not bound to a cluster.".format(dbhost))
if dbhost.cluster != dbcluster:
raise ArgumentError("{0} is bound to {1:l}, not {2:l}.".format(
dbhost, dbhost.cluster, dbcluster))
if personality:
dbpersonality = Personality.get_unique(session, name=personality,
archetype=dbhost.archetype,
compel=True)
if dbpersonality.cluster_required:
raise ArgumentError("Cannot switch host to personality %s "
"because that personality requires a "
"cluster" % personality)
dbhost.personality = dbpersonality
elif dbhost.personality.cluster_required:
raise ArgumentError("Host personality %s requires a cluster, "
"use --personality to change personality "
"when leaving the cluster." %
dbhost.personality.name)
dbcluster.hosts.remove(dbhost)
remove_service_addresses(dbcluster, dbhost)
dbcluster.validate()
session.flush()
session.expire(dbhost, ['_cluster'])
host_plenary = Plenary.get_plenary(dbhost, logger=logger)
cluster_plenary = Plenary.get_plenary(dbcluster, logger=logger)
with CompileKey.merge([host_plenary.get_key(),
cluster_plenary.get_key()]):
try:
cluster_plenary.write(locked=True)
try:
host_plenary.write(locked=True)
except IncompleteError:
host_plenary.remove(locked=True)
except:
cluster_plenary.restore_stash()
host_plenary.restore_stash()
raise
示例13: render
def render(self, session, service, instance, archetype, personality,
networkip, **kwargs):
dbservice = Service.get_unique(session, service, compel=True)
dblocation = get_location(session, **kwargs)
dbinstance = get_service_instance(session, dbservice, instance)
if networkip:
dbnet_env = NetworkEnvironment.get_unique_or_default(session)
dbnetwork = get_network_byip(session, networkip, dbnet_env)
else:
dbnetwork = None
if archetype is None and personality:
# Can't get here with the standard aq client.
raise ArgumentError("Specifying --personality requires you to "
"also specify --archetype.")
kwargs = {}
if archetype and personality:
dbpersona = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
map_class = PersonalityServiceMap
query = session.query(map_class).filter_by(personality=dbpersona)
kwargs["personality"] = dbpersona
else:
map_class = ServiceMap
query = session.query(map_class)
dbmap = query.filter_by(location=dblocation,
service_instance=dbinstance,
network=dbnetwork).first()
if not dbmap:
dbmap = map_class(service_instance=dbinstance,
location=dblocation,
network=dbnetwork, **kwargs)
session.add(dbmap)
session.flush()
return
示例14: render
def render(self, session, logger, target, grn, eon_id, hostname, list, personality,
archetype, **arguments):
dbgrn = lookup_grn(session, grn, eon_id, logger=logger,
config=self.config)
plenaries = PlenaryCollection(logger=logger)
if hostname:
objs = [hostname_to_host(session, hostname)]
config_key = "host_grn_targets"
elif list:
check_hostlist_size(self.command, self.config, list)
objs = hostlist_to_hosts(session, list)
config_key = "host_grn_targets"
elif personality:
objs = [Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)]
config_key = "personality_grn_targets"
for obj in objs:
section = "archetype_" + obj.archetype.name
if self.config.has_option(section, config_key):
valid_targets = [s.strip() for s in
self.config.get(section, config_key).split(",")]
else:
raise ArgumentError("{0} has no valid GRN targets configured."
.format(obj.archetype))
if target not in valid_targets:
raise ArgumentError("Invalid target %s for archetype %s, please "
"choose from: %s." %
(target, obj.archetype.name,
", ".join(valid_targets)))
plenaries.append(Plenary.get_plenary(obj))
self._update_dbobj(obj, target, dbgrn)
session.flush()
plenaries.write()
return
示例15: render
def render(self, session, logger, domain, sandbox, archetype, personality,
pancinclude, pancexclude, pancdebug, cleandeps,
**arguments):
dbdomain = None
dbauthor = None
if domain or sandbox:
(dbdomain, dbauthor) = get_branch_and_author(session, logger,
domain=domain,
sandbox=sandbox,
compel=True)
dbpersonality = Personality.get_unique(session, name=personality,
archetype=archetype, compel=True)
if pancdebug:
pancinclude = r'.*'
pancexclude = r'components/spma/functions'
q = session.query(Host)
q = q.filter_by(personality=dbpersonality)
if dbdomain:
q = q.filter_by(branch=dbdomain)
if dbauthor:
q = q.filter_by(sandbox_author=dbauthor)
host_list = q.all()
if not host_list:
return
# If the domain was not specified, set it to the domain of first host
dbdomain, dbauthor = validate_branch_author(host_list)
plenaries = PlenaryCollection(logger=logger)
for host in host_list:
plenaries.append(Plenary.get_plenary(host))
dom = TemplateDomain(dbdomain, dbauthor, logger=logger)
with plenaries.get_key():
dom.compile(session, only=plenaries.object_templates,
panc_debug_include=pancinclude,
panc_debug_exclude=pancexclude,
cleandeps=cleandeps, locked=True)
return