This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Help with YAQL query

I have hit a brick wall trying to publish a yaql expression from output data and documentation on yaql is somewhat sparse

From the below output, I am trying to publish virtualmachine.id where virtualmachine.nic.networkname = lan-net

Any pointers to what the expression should look like would be appreciated

virtualmachine:
- account: user
affinitygroup: []
cpunumber: 1
cpuspeed: 1000
cpuused: 0.41%
created: 2020-08-31T12:00:16+0800
details:
Message.ReservedCapacityFreed.Flag: ‘true’
SSH.PublicKey: ssh-rsa AAAB35555yc2E1234DAQABAAABAQCAc1xLjLaxrSIVVFF8ihBX0yZxYgtVT5zmn7XxghTZvB40yeeCqQRaxLT1I2cKSKijA+jkxudgRAJzdeqk6c3EoBk3e2/Q+1o9QO/8xaHIXPKu5JoTKyCi8jq5FkqUxSf3/KHrDMk24/kgj5CGG3S0WeFSp3MORoVBxVSW+BDE5XIDBycQjWxEDSQOgbrOt6Ywmbkf955jh77Kcf/v8IqhLg1a94txmbDI+oaKyrzbVOisErI4/k7GzbyxjiozbQZ6ISp+SlcFsms5ecUGpM04WmIt6r7Hwli40kzcj4NGAN1lm3pK9+0Hp7tab/IJsgTmp7T9N3ICc60nBmdtoc3l
diskioread: 92512
diskiowrite: 34501
diskkbsread: 3167073
diskkbswrite: 3920315
diskofferingid: c8e23623-3c9c-4cf0-877b-92491560629b
diskofferingname: Custom
displayname: localhost
displayvm: true
domain: ROOT
domainid: b6155e47-64e7-11e9-3333-f2f9c859b603
guestosid: ebf3934c-3333-11e9-81d3-964f98ffb0e4
haenable: false
hypervisor: KVM
id: 3bc967ba-3402-3333-8206-4d005e469978
instancename: i-2-3748-VM
isdynamicallyscalable: false
keypair: ssh-keypair
memory: 1024
memoryintfreekbs: 644136
memorykbs: 1048576
memorytargetkbs: 1048576
name: localhost
networkkbsread: 234858
networkkbswrite: 4791
nic:
- broadcasturi: vlan://10
extradhcpoption: []
gateway: 10.10.10.2
id: 15aa2e71-2c93-4d98-94ea-46635109eced
ipaddress: 10.10.10.153
isdefault: true
isolationuri: vlan://10
macaddress: 1e:00:41:00:01:d4
netmask: 255.255.255.0
networkid: 07521c6d-17b4-4236-8f1d-87a61d4e770d
networkname: lan-net
secondaryip: []
traffictype: Guest
type: Shared
ostypeid: ebf3934c-fc51-11e9-81d3-964f98ffb0e4
passwordenabled: false
rootdeviceid: 0
rootdevicetype: ROOT
securitygroup: []
serviceofferingid: 4dea8ee3-3ce7-4d8b-ad45-46e6a769c6b6
serviceofferingname: Medium Instance
state: Stopped
tags: []
templatedisplaytext: CentOS 8
templateid: df40c1ff-9cbc-4e35-93bb-02dd3f68ccae
templatename: centos-8.2.2004-server
userid: d8b93f19-64e7-11e9-b6e7-f2f9c859b603
username: user
zoneid: bd43ff6e-ecaf-45ad-955c-9b1e28b5aeef
zonename: zone1
- account: user
affinitygroup: []
cpunumber: 1
cpuspeed: 500
cpuused: 1.04%
created: 2020-08-11T08:04:00+0800
details:
Message.ReservedCapacityFreed.Flag: ‘false’
SSH.PublicKey: ssh-rsa 1234B3NzaC1yc2E1234DAQABAAABAQCAc1xLjLaxrSIVVFF8ihBX0yZxYgtVT5zmn7XxghTZvB40yeeCqQRaxLT1I2cKSKijA+jkxudgRAJzdeqk6c3EoBk3e2/Q+1o9QO/8xaHIXPKu5JoTKyCi8jq5FkqUxSf3/KHrDMk24/kgj5CGG3S0WeFSp3MORoVBxVSW+BDE5XIDBycQjWxEDSQOgbrOt6Ywmbkf955jh77Kcf/v8IqhLg1a94txmbDI+oaKyrzbVOisErI4/k7GzbyxjiozbQZ6ISp+SlcFsms5ecUGpM04WmIt6r7Hwli40kzcj4NGAN1lm3pK9+0Hp7tab/IJsgTmp7T9N3ICc60nBmdtoc3l
rootDiskController: virtio
diskioread: 26918540
diskiowrite: 10790879
diskkbsread: 344913468
diskkbswrite: 76971660
displayname: VM-7afaecba-1dab-46e0-8f63-dfdd57f2f289
displayvm: true
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
guestosid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
haenable: false
hostid: 03081bfd-b1ba-4c62-8771-bf4e01ce44c4
hostname: cloudstack2.mydomain.internal
hypervisor: KVM
id: 7afaecba-1dab-46e0-8f63-dfdd57f2f289
instancename: i-2-3446-VM
isdynamicallyscalable: false
keypair: ssh-keypair
memory: 512
memoryintfreekbs: 601684
memorykbs: 524288
memorytargetkbs: 524288
name: VM-7afaecba-1dab-46e0-8f63-dfdd57f2f289
networkkbsread: 1236463
networkkbswrite: 445667
nic:
- broadcasturi: vlan://567
extradhcpoption: []
gateway: 10.1.90.1
id: 862bbc94-fe3f-412d-bae1-d6a0808bd2c7
ipaddress: 10.1.90.251
isdefault: true
isolationuri: vlan://567
macaddress: 02:00:74:df:00:01
netmask: 255.255.255.0
networkid: 8e09d5d5-4fd1-4edb-8e4b-a4fc91ff1212
networkname: plexstats-net
secondaryip: []
traffictype: Guest
type: Isolated
ostypeid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
passwordenabled: false
rootdeviceid: 1
rootdevicetype: DATADISK
securitygroup: []
serviceofferingid: eaf6a3db-6725-4eba-9dc8-ed3313cd470b
serviceofferingname: Small Instance
state: Running
tags:
- account: user
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
key: application
resourceid: 7afaecba-1dab-46e0-8f63-dfdd57f2f289
resourcetype: UserVm
value: plexstats
templatedisplaytext: Debian plexstats Server
templateid: fb86cf28-e32c-4bec-b09d-18a130fb482b
templatename: debian-10.0-plexstats-latest
userid: d8b93f19-64e7-11e9-b6e7-f2f9c859b603
username: user
zoneid: bd43ff6e-ecaf-45ad-955c-9b1e28b5aeef
zonename: zone1
- account: user
affinitygroup: []
cpunumber: 1
cpuspeed: 1000
cpuused: 0.95%
created: 2020-09-30T02:45:25+0800
details:
Message.ReservedCapacityFreed.Flag: ‘false’
SSH.PublicKey: ssh-rsa 1234B3NzaC1yc2E1234DAQABAAABAQCAc1xLjLaxrSIVVFF8ihBX0yZxYgtVT5zmn7XxghTZvB40yeeCqQRaxLT1I2cKSKijA+jkxudgRAJzdeqk6c3EoBk3e2/Q+1o9QO/8xaHIXPKu5JoTKyCi8jq5FkqUxSf3/KHrDMk24/kgj5CGG3S0WeFSp3MORoVBxVSW+BDE5XIDBycQjWxEDSQOgbrOt6Ywmbkf955jh77Kcf/v8IqhLg1a94txmbDI+oaKyrzbVOisErI4/k7GzbyxjiozbQZ6ISp+SlcFsms5ecUGpM04WmIt6r7Hwli40kzcj4NGAN1lm3pK9+0Hp7tab/IJsgTmp7T9N3ICc60nBmdtoc3l
rootDiskController: virtio
diskioread: 4047
diskiowrite: 7797
diskkbsread: 158040
diskkbswrite: 71824
displayname: VM-be958ccd-74cf-4993-a314-a92337d027fe
displayvm: true
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
guestosid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
haenable: false
hostid: 03081bfd-b1ba-4c62-8771-bf4e01ce44c4
hostname: cloudstack2.mydomain.internal
hypervisor: KVM
id: be958ccd-74cf-4993-a314-a92337d027fe
instancename: i-2-4458-VM
isdynamicallyscalable: false
keypair: ssh-keypair
memory: 1024
memoryintfreekbs: 1129512
memorykbs: 1048576
memorytargetkbs: 1048576
name: VM-be958ccd-74cf-4993-a314-a92337d027fe
networkkbsread: 102652
networkkbswrite: 24906
nic:
- broadcasturi: vlan://10
extradhcpoption: []
gateway: 10.10.10.2
id: 4b44bbc6-ba31-4c0f-92ff-3628598cbb50
ipaddress: 10.10.10.174
isdefault: true
isolationuri: vlan://10
macaddress: 1e:00:f8:00:01:e9
netmask: 255.255.255.0
networkid: 07521c6d-17b4-4236-8f1d-87a61d4e770d
networkname: lan-net
secondaryip: []
traffictype: Guest
type: Shared
ostypeid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
passwordenabled: false
rootdeviceid: 1
rootdevicetype: DATADISK
securitygroup: []
serviceofferingid: 4dea8ee3-3ce7-4d8b-ad45-46e6a769c6b6
serviceofferingname: Medium Instance
state: Running
tags:
- account: user
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
key: application
resourceid: be958ccd-74cf-4993-a314-a92337d027fe
resourcetype: UserVm
value:
templatedisplaytext: Debian Server
templateid: e9468c29-38cd-499a-b959-502468400b93
templatename: debian-10.0–latest
userid: d8b93f19-64e7-11e9-b6e7-f2f9c859b603
username: user
zoneid: bd43ff6e-ecaf-45ad-955c-9b1e28b5aeef
zonename: zone1
- account: user
affinitygroup: []
cpunumber: 2
cpuspeed: 2000
cpuused: 1.06%
created: 2020-08-08T15:49:25+0800
details:
Message.ReservedCapacityFreed.Flag: ‘false’
SSH.PublicKey: ssh-rsa 1234B3NzaC1yc2E1234DAQABAAABAQCAc1xLjLaxrSIVVFF8ihBX0yZxYgtVT5zmn7XxghTZvB40yeeCqQRaxLT1I2cKSKijA+jkxudgRAJzdeqk6c3EoBk3e2/Q+1o9QO/8xaHIXPKu5JoTKyCi8jq5FkqUxSf3/KHrDMk24/kgj5CGG3S0WeFSp3MORoVBxVSW+BDE5XIDBycQjWxEDSQOgbrOt6Ywmbkf955jh77Kcf/v8IqhLg1a94txmbDI+oaKyrzbVOisErI4/k7GzbyxjiozbQZ6ISp+SlcFsms5ecUGpM04WmIt6r7Hwli40kzcj4NGAN1lm3pK9+0Hp7tab/IJsgTmp7T9N3ICc60nBmdtoc3l
rootDiskController: virtio
diskioread: 724131
diskiowrite: 2206871
diskkbsread: 35246384
diskkbswrite: 29790544
displayname: VM-af0a53f8-ec1d-4602-9fe2-8940cf05ba8e
displayvm: true
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
guestosid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
haenable: false
hostid: 03081bfd-b1ba-4c62-8771-bf4e01ce44c4
hostname: cloudstack2.mydomain.internal
hypervisor: KVM
id: af0a53f8-ec1d-4602-9fe2-8940cf05ba8e
instancename: i-2-3399-VM
isdynamicallyscalable: false
keypair: ssh-keypair
memory: 4000
memoryintfreekbs: 4178404
memorykbs: 4096000
memorytargetkbs: 4096000
name: VM-af0a53f8-ec1d-4602-9fe2-8940cf05ba8e
networkkbsread: 1890289
networkkbswrite: 2065908
nic:
- broadcasturi: vlan://533
extradhcpoption: []
gateway: 10.1.70.1
id: 83fabe61-aa7b-432f-9db6-9767e9c3a065
ipaddress: 10.1.70.56
isdefault: true
isolationuri: vlan://534
macaddress: 02:00:09:26:00:01
netmask: 255.255.255.0
networkid: 7117ff2f-3c24-4ea6-a8e4-f96404b7a9ce
networkname: elk-net
secondaryip: []
traffictype: Guest
type: Isolated
ostypeid: d2a6d04b-64e7-11e9-b6e7-f2f9c859b603
passwordenabled: false
rootdeviceid: 1
rootdevicetype: DATADISK
securitygroup: []
serviceofferingid: 703cf223-0410-4b5d-87b9-4bb2cfe8f131
serviceofferingname: XX-Large Instance
state: Running
tags:
- account: user
domain: ROOT
domainid: b3355e55-63e7-11e9-b6e7-f2f9c859b603
key: application
resourceid: af0a53f8-ec1d-4602-9fe2-8940cf05ba8e
resourcetype: UserVm
value: elk
templatedisplaytext: Debian Server
templateid: 924e7779-88b8-4bbd-8c9a-bfa36c32365f
templatename: debian-10.0-elk-latest
userid: d8b93f19-64e7-11e9-b6e7-f2f9c859b603
username: user
zoneid: bd43ff6e-ecaf-45ad-955c-9b1e28b5aeef
zonename: zone1
nename: zone1

It will be hard to help since the YAML you’ve posted is not formatted. The structure of the dataset is important. Can you update your post so it’s formatted correctly?

In general when working with YAQL, the YAQL evaluator website http://yaqluator.com/ and YAQL documentation https://yaql.readthedocs.io/en/latest/ are very useful

1 Like

Have you tried using the where / select. Is nic just a dict or an array of dictionaries? As indention has gone funny I wasn’t sure. I’m assuming virtuamachine is an array, that includes properties id and nic.

Not sure if this is the simplest, but I think if nic is just a dictionary then you could use:

ctx().virtualmachine.where($.nic.networkname="lan.net").select($.id)

But if its an array of dictionaries then maybe something like:
ctx().virtualmachine.where($.nic.networkname.contains("lan.net")).select($.id)

But as Carlos mentioned the yaqluator is really useful, I generally type in the JSON into there, and then build up my YAQL querie s- and using the YAQL doc site he has pointed at.

1 Like

Apologies, the data was actually a copy paste from yaqulator, but it appears it didn’t format correctly. The solution to the problem based on amanda11 response was

.virtualmachine.where(.nic.networkname.contains(“lan-net”)).id

I can’t work out how to post the data and maintain the formatting, if someone can tell me how I’ll post it again for other to reference

Thanks for your help & support

Use the button for preformatted text inside the editor.

indent preformatted text by 4 spaces

So you just paste in the text you want preformatted. Select the pasted text in the editor and click the prefomatted text button. Here’s an example using some of your inital text.

virtualmachine:
	- account: user
		affinitygroup: []
		cpunumber: 1
		cpuspeed: 1000
		cpuused: 0.41%
		created: 2020-08-31T12:00:16+0800
		details:
		Message.ReservedCapacityFreed.Flag: ‘true’
		SSH.PublicKey: ssh-rsa AAAB35555yc2E1234DAQABAAABAQCAc1xLjLaxrSIVVFF8ihBX0yZxYgtVT5zmn7XxghTZvB40yeeCqQRaxLT1I2cKSKijA+jkxudgRAJzdeqk6c3EoBk3e2/Q+1o9QO/8xaHIXPKu5JoTKyCi8jq5FkqUxSf3/KHrDMk24/kgj5CGG3S0WeFSp3MORoVBxVSW+BDE5XIDBycQjWxEDSQOgbrOt6Ywmbkf955jh77Kcf/v8IqhLg1a94txmbDI+oaKyrzbVOisErI4/k7GzbyxjiozbQZ6ISp+SlcFsms5ecUGpM04WmIt6r7Hwli40kzcj4NGAN1lm3pK9+0Hp7tab/IJsgTmp7T9N3ICc60nBmdtoc3l
		diskioread: 92512
		diskiowrite: 34501
		diskkbsread: 3167073
		diskkbswrite: 3920315
		diskofferingid: c8e23623-3c9c-4cf0-877b-92491560629b
		diskofferingname: Custom
		displayname: localhost
		displayvm: true