当前位置: 首页>>代码示例>>Python>>正文


Python DeviceDictionary.hostname方法代码示例

本文整理汇总了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)
开发者ID:pevik,项目名称:lava-server,代码行数:50,代码来源:device-dictionary.py

示例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)
开发者ID:SivagnanamCiena,项目名称:lava-server,代码行数:49,代码来源:device-dictionary.py

示例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
开发者ID:pevik,项目名称:lava-server,代码行数:65,代码来源:api.py


注:本文中的lava_scheduler_app.models.DeviceDictionary.hostname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。