How is $id and $ref values are used in device tree yaml binding file? and can I see it? - yaml

This has been a question I had for a long time.
I started to read https://docs.kernel.org/devicetree/bindings/writing-schema.html but it's hard to understand.
For example in linux-5.15.68, the file Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml starts like this.
# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/pci/snps,dw-pcie.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Synopsys DesignWare PCIe interface
maintainers:
- Jingoo Han <jingoohan1#gmail.com>
- Gustavo Pimentel <gustavo.pimentel#synopsys.com>
description: |
Synopsys DesignWare PCIe host controller
allOf:
- $ref: /schemas/pci/pci-bus.yaml#
properties:
compatible:
anyOf:
- {}
- const: snps,dw-pcie
How is the URI $id and $scmema used? and if I want to browse the file, how can I do it?
When I put http://devicetree.org/schemas/pci/snps,dw-pcie.yaml the browser says 'These are not the schemas you are looking for.'.

Related

Get all children key values in a YAML with PyYAML

Say I have a YAML like:
Resources:
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- !If
- ShouldAlarm
Protocol: email
How do I get each key and value of all the children if I'm walking over each resource and I want to know if one of the values may contain a certain string? I'm using PyYAML but I'm also open to using some other library.
You can use the low-level event API if you only want to inspect scalar values:
import yaml
import sys
input = """
Resources:
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- !If
- ShouldAlarm
- Protocol: email
"""
for e in yaml.parse(input):
if isinstance(e, yaml.ScalarEvent):
print(e.value)
(I fixed your YAML because it had a syntax error.) This yields:
Resources
AlarmTopic
Type
AWS::SNS::Topic
Properties
Subscription
ShouldAlarm
Protocol
email

How to use $ref for tags between files

I am using Open API 3.0, in A.yaml
# something above
tags:
- name: user
description: Operations about user
- name: user_stuff
description: API for user stuff
- name: another_user_stuff
description: API for another user stuff
# something below
Then, in B.yaml, I want to make reference to the tags in A.yaml, for example the tag of user. Suppose in B.yaml, we have
post:
tags:
$ref: <What are the things should be here?>
summary: do somthing
description: "do something"
requestBody:
# bla bla bla
required: true
responses:
"200":
description: uccessfully
x-swagger-router-controller: B
How can I make a reference from B.yaml to A.yaml?
The tags keyword does not support $ref. All tags must be defined inline.
# B.yaml
tags:
- name: foo
description: Operations to manage Foos.
paths:
/something:
post:
tags:
- foo
- bar
That said, you don't have to define tags in the global tags section in order to use them in operations. The global tags section is used only to define extra tag metadata, such as descriptions and externalDocs, or the tag order in documentation tools.

Puppet 6 and module puppetlabs/accounts does not create user account in Hiera YAML format

When I run puppet agent --test I have no errors output but the user did not create.
My puppet hira.yaml configuration is:
---
version: 5
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
users.yaml is:
accounts::user:
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
I use this module
Nothing in Hiera data itself causes anything to be applied to target nodes. Some kind of declaration is required in a manifest somewhere or in the output of an external node classifier script. Moreover, the puppetlabs/accounts module provides only defined types, not classes. You can store defined-type data in Hiera and read it back, but automated parameter binding via Hiera applies only to classes, not defined types.
In short, then, no user is created (and no error is reported) because no relevant resources are declared into the target node's catalog. You haven't given Puppet anything to do.
If you want to apply the stored user data presented to your nodes, you would want something along these lines:
$user_data = lookup('accounts::user', Hash[String,Hash], 'hash', {})
$user_data.each |$user,$props| {
accounts::user { $user: * => $props }
}
That would go into the node block matched to your target node, or, better, into a class that is declared by that node block or an equivalent. It's fairly complicated for so few lines, but in brief:
the lookup function looks up key 'accounts::user' in your Hiera data
performing a hash merge of results appearing at different levels of the hierarchy
expecting the result to be a hash with string keys and hash values
and defaulting to an empty hash if no results are found;
the mappings in the result hash are iterated, and for each one, an instance of the accounts::user defined type is declared
using the (outer) hash key as the user name,
and the value associated with that key as a mapping from parameter names to parameter values.
There are a few problems here.
You are missing a line in your hiera.yaml namely the defaults key. It should be:
---
version: 5
defaults: ## add this line
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
I detected that using the puppet-syntax gem (included if you use PDK, which is recommended):
▶ bundle exec rake validate
Syntax OK
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
ERROR: Failed to parse hiera.yaml: (hiera.yaml): mapping values are not allowed in this context at line 3 column 10
Also, in addition to what John mentioned, the simplest class to read in your data would be this:
class test (Hash[String,Hash] $users) {
create_resources(accounts::user, $users)
}
Or if you want to avoid using create_resources*:
class test (Hash[String,Hash] $users) {
$users.each |$user,$props| {
accounts::user { $user: * => $props }
}
}
Note that I have relied on the Automatic Parameter Lookup feature for that. See the link below.
Then, in your Hiera data, you would have a key named test::users to correspond (class name "test", key name "users"):
---
test::users: ## Note that this line changed.
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
Use of automatic parameter lookup is generally the more idiomatic way of writing Puppet code compared to calling the lookup function explicitly.
For more info:
PDK
Automatic Parameter Lookup
create_resources
(*Note that create_resources is "controversial". Many in the Puppet community prefer not to use it.)

Create complex types (definitions) in Swagger [duplicate]

This question already has answers here:
Swagger: How to have a property reference a model in OpenAPI 2.0 (i.e. nest the models)?
(2 answers)
Closed 2 years ago.
I created a definition called Product and another called Text (see code).
On parameters of paths I can not use the type Text created in definitions. On the definition Product I have a property called message and I want that property to be the type Text too.
(...)
paths:
/products:
get:
summary: Product Types
description: |
Description text
parameters:
- name: latitude
in: query
description: Latitude component of location.
required: true
### The type Text was not found here
type: Text ### The type Text was not found here
(...)
definitions:
Product:
properties:
message:
### The type Text was not found here
type: Text ### Compilation Error in this line ####
name:
type: string
description: Data description.
Text:
properties:
code:
type: string
But this error occurs:
Swagger Error:
Data does not match any schemas from 'anyOf'.
How can I reference the type Text on the type Product?
Please use $ref instead. Here is an example
type: object
required:
- name
properties:
name:
type: string
address:
$ref: '#/definitions/Address'
age:
type: integer
format: int32
minimum: 0
Ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#simple-model

What kind of data structure is this?

I am pulling recent commits from github and trying to parse it using ruby. I know that I can parse it manually but I wanted to see if there was some package that could turn this into a hash or another data structure.
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message
This is YAML http://ruby-doc.org/core/classes/YAML.html. You can do something like obj = YAML::load yaml_string (and a require 'yaml' at the top of your file, its in the standard libs), and then access it like a nested hash.
YAML is basically used in the ruby world the way people use XML in the java/c# worlds.
Looks like YAML to me. There are parsers for a lot of languages. For example, with the YAML library included with Ruby:
data = <<HERE
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message
HERE
pp YAML.load data
It prints:
{"commits"=>
[{"author"=>{"name"=>"This guy", "login"=>"tguy", "email"=>"tguy#tguy.com"},
"parents"=>[{"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5"}],
"url"=>"a url",
"id"=>"e466354edb31f243899051e2119f4ce72bafd5f3",
"committed_date"=>"2010-07-19T13:44:43-07:00",
"authored_date"=>"2010-07-19T13:33:26-07:00",
"message"=>"message"},
{"author"=>
{"name"=>"Other Guy", "login"=>"oguy", "email"=>"oguy#gmail.com"},
"parents"=>[{"id"=>"c3c349ec3e9a3990cac4d256c308b18fd35d9606"}],
"url"=>"another url",
"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5",
"committed_date"=>"2010-07-19T13:44:11-07:00",
"authored_date"=>"2010-07-19T13:44:11-07:00",
"message"=>"this is another message"}]}
This format is YAML, but you can get the same information in XML or JSON, see General API Information. I'm sure there are libraries to parse those formats in Ruby.
Although this isn't exactly what you're looking for, here's some more info on pulling commits. http://develop.github.com/p/commits.html. Otherwise, I think you may just need to manually parse it.

Resources