本文整理汇总了Python中lava_scheduler_app.models.DeviceDictionary.hostname方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceDictionary.hostname方法的具体用法?Python DeviceDictionary.hostname怎么用?Python DeviceDictionary.hostname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lava_scheduler_app.models.DeviceDictionary
的用法示例。
在下文中一共展示了DeviceDictionary.hostname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import hostname [as 别名]
def handle(self, *args, **options):
"""
Accept options via lava-server manage which provides access
to the database.
"""
hostname = options['hostname']
if hostname is None:
self.stderr.write("Please specify a hostname")
sys.exit(2)
if options['import'] is not None:
data = parse_template(options['import'])
element = DeviceDictionary.get(hostname)
if element is None:
self.stdout.write("Adding new device dictionary for %s" %
hostname)
element = DeviceDictionary(hostname=hostname)
element.hostname = hostname
element.parameters = data
element.save()
self.stdout.write("Device dictionary updated for %s" % hostname)
elif options['export'] is not None or options['review'] is not None:
element = DeviceDictionary.get(hostname)
data = None
if element is None:
self.stderr.write("Unable to export - no dictionary found for '%s'" %
hostname)
sys.exit(2)
else:
data = devicedictionary_to_jinja2(
element.parameters,
element.parameters['extends']
)
if options['review'] is None:
self.stdout.write(data)
else:
template = prepare_jinja_template(hostname, data, system_path=False, path=options['path'])
device_configuration = template.render()
# validate against the device schema
try:
validate_device(yaml.load(device_configuration))
except (yaml.YAMLError, SubmissionException) as exc:
self.stderr.write("Invalid template: %s" % exc)
self.stdout.write(device_configuration)
else:
self.stderr.write("Please specify one of --import, --export or --review")
sys.exit(1)
示例2: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import hostname [as 别名]
def handle(self, *args, **options):
"""
Accept options via lava-server manage which provides access
to the database.
"""
hostname = options['hostname']
if hostname is None:
self.stderr.write("Please specify a hostname")
sys.exit(2)
if options['import'] is not None:
data = parse_template(options['import'])
element = DeviceDictionary.get(hostname)
if element is None:
self.stdout.write("Adding new device dictionary for %s" %
hostname)
element = DeviceDictionary(hostname=hostname)
element.hostname = hostname
element.parameters = data
element.save()
self.stdout.write("Device dictionary updated for %s" % hostname)
elif options['export'] is not None or options['review'] is not None:
element = DeviceDictionary.get(hostname)
data = None
if element is None:
self.stderr.write("Unable to export - no dictionary found for '%s'" %
hostname)
sys.exit(2)
else:
data = devicedictionary_to_jinja2(
element.parameters,
element.parameters['extends']
)
if options['review'] is None:
self.stdout.write(data)
else:
string_loader = jinja2.DictLoader({'%s.yaml' % hostname: data})
type_loader = jinja2.FileSystemLoader([
os.path.join(options['path'], 'device-types')])
env = jinja2.Environment(
loader=jinja2.ChoiceLoader([string_loader, type_loader]),
trim_blocks=True)
template = env.get_template("%s.yaml" % hostname)
device_configuration = template.render()
self.stdout.write(device_configuration)
else:
self.stderr.write("Please specify one of --import, --export or --review")
sys.exit(1)
示例3: import_device_dictionary
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import hostname [as 别名]
def import_device_dictionary(self, hostname, jinja_str):
"""
Name
----
`import_device_dictionary` (`device_hostname`, `jinja_string`)
Description
-----------
[superuser only]
Import or update the device dictionary key value store for a
pipeline device.
Arguments
---------
`device_hostname`: string
Device hostname to update.
`jinja_str`: string
Jinja2 settings to store in the DeviceDictionary
Return value
------------
This function returns an XML-RPC binary data of output file.
"""
self._authenticate()
if not self.user.is_superuser:
raise xmlrpclib.Fault(
403,
"User '%s' is not superuser." % self.user.username
)
try:
Device.objects.get(hostname=hostname)
except DeviceType.DoesNotExist:
raise xmlrpclib.Fault(
404, "Device '%s' was not found." % hostname
)
try:
device_data = jinja2_to_devicedictionary(jinja_str)
except (ValueError, KeyError, TypeError):
raise xmlrpclib.Fault(
400, "Unable to parse specified jinja string"
)
if not device_data or 'extends' not in device_data:
raise xmlrpclib.Fault(
400, "Invalid device dictionary content - %s - not updating." % jinja_str
)
try:
template = prepare_jinja_template(hostname, jinja_str, system_path=True)
except (jinja2.TemplateError, yaml.YAMLError, IOError) as exc:
raise xmlrpclib.Fault(
400, "Template error: %s" % exc
)
if not template:
raise xmlrpclib.Fault(400, "Empty template")
element = DeviceDictionary.get(hostname)
msg = ''
if element is None:
msg = "Adding new device dictionary for %s\n" % hostname
element = DeviceDictionary(hostname=hostname)
element.hostname = hostname
element.parameters = device_data
element.save()
msg += "Device dictionary updated for %s\n" % hostname
return msg