examples: Add more examples and clean up some
This commit is contained in:
22
examples/lang/class-include.mcl
Normal file
22
examples/lang/class-include.mcl
Normal file
@@ -0,0 +1,22 @@
|
||||
import "fmt"
|
||||
class foo {
|
||||
print "foo1" {
|
||||
msg => "inside foo",
|
||||
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
}
|
||||
|
||||
class bar($a, $b) { # a parameterized class
|
||||
print "bar-"+ $a {
|
||||
msg => fmt.printf("inside bar: %s", $b),
|
||||
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
}
|
||||
|
||||
include foo
|
||||
include foo # duplicate
|
||||
include bar("b1", "hello")
|
||||
include bar("b2", "world")
|
||||
include bar("b2", "world") # duplicate
|
||||
@@ -1,9 +1,9 @@
|
||||
cron "purpleidea-oneshot" {
|
||||
session => true,
|
||||
trigger => "OnBootSec",
|
||||
time => "60",
|
||||
session => true,
|
||||
trigger => "OnBootSec",
|
||||
time => "60",
|
||||
}
|
||||
|
||||
svc "purpleidea-oneshot" {
|
||||
session => true,
|
||||
session => true,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
cron "purpleidea-oneshot" {
|
||||
state => "absent",
|
||||
state => "absent",
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cron "purpleidea-oneshot" {
|
||||
trigger => "OnUnitActiveSec",
|
||||
time => "2minutes",
|
||||
trigger => "OnUnitActiveSec",
|
||||
time => "2minutes",
|
||||
}
|
||||
|
||||
svc "purpleidea-oneshot" {}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
$home = getenv("HOME")
|
||||
|
||||
cron "purpleidea-oneshot" {
|
||||
session => true,
|
||||
trigger => "OnCalendar",
|
||||
time => "*:*:0",
|
||||
session => true,
|
||||
trigger => "OnCalendar",
|
||||
time => "*:*:0",
|
||||
}
|
||||
|
||||
svc "purpleidea-oneshot" {
|
||||
session => true,
|
||||
session => true,
|
||||
}
|
||||
|
||||
file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) {}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
$home = getenv("HOME")
|
||||
|
||||
cron "purpleidea-oneshot" {
|
||||
state => "absent",
|
||||
session => true,
|
||||
trigger => "OnCalendar",
|
||||
time => "*:*:0",
|
||||
state => "absent",
|
||||
session => true,
|
||||
trigger => "OnCalendar",
|
||||
time => "*:*:0",
|
||||
}
|
||||
|
||||
svc "purpleidea-oneshot" {
|
||||
state => "stopped",
|
||||
session => true,
|
||||
state => "stopped",
|
||||
session => true,
|
||||
}
|
||||
|
||||
file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) {
|
||||
state => "absent",
|
||||
state => "absent",
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
docker:container "mgmt-nginx" {
|
||||
state => "running",
|
||||
image => "nginx",
|
||||
cmd => ["nginx", "-g", "daemon off;",],
|
||||
ports => {"tcp" => {80 => 8080,},},
|
||||
state => "running",
|
||||
image => "nginx",
|
||||
cmd => ["nginx", "-g", "daemon off;",],
|
||||
ports => {"tcp" => {80 => 8080,},},
|
||||
}
|
||||
|
||||
8
examples/lang/duplicate-error.mcl
Normal file
8
examples/lang/duplicate-error.mcl
Normal file
@@ -0,0 +1,8 @@
|
||||
# this combination should error
|
||||
pkg "cowsay" {
|
||||
state => "uninstalled",
|
||||
}
|
||||
|
||||
pkg "cowsay" {
|
||||
state => "installed",
|
||||
}
|
||||
7
examples/lang/duplicate.mcl
Normal file
7
examples/lang/duplicate.mcl
Normal file
@@ -0,0 +1,7 @@
|
||||
pkg "cowsay" {
|
||||
state => "newest",
|
||||
}
|
||||
|
||||
pkg "cowsay" {
|
||||
state => "installed",
|
||||
}
|
||||
8
examples/lang/env-bad.mcl
Normal file
8
examples/lang/env-bad.mcl
Normal file
@@ -0,0 +1,8 @@
|
||||
import "fmt"
|
||||
import "sys"
|
||||
|
||||
$x = sys.getenv("TEST", "321")
|
||||
|
||||
print "print1" {
|
||||
msg => fmt.printf("TEST is: %s", $x),
|
||||
}
|
||||
21
examples/lang/iteration1.mcl
Normal file
21
examples/lang/iteration1.mcl
Normal file
@@ -0,0 +1,21 @@
|
||||
# single resource
|
||||
print "name" {}
|
||||
|
||||
# single resource, defined by list variable
|
||||
$names = ["hey", "there",]
|
||||
print $names {
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
|
||||
# multiples resources, defined by list
|
||||
print ["hello", "world",] {
|
||||
Meta:autogroup => false,
|
||||
Depend => Print[$names],
|
||||
}
|
||||
|
||||
$morenames = ["wow", "cool", "amazing",]
|
||||
print $morenames {
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
|
||||
Print[$names] -> Print[$morenames]
|
||||
3
examples/lang/nspawn1.mcl
Normal file
3
examples/lang/nspawn1.mcl
Normal file
@@ -0,0 +1,3 @@
|
||||
nspawn "sid-chroot" {
|
||||
state => "running",
|
||||
}
|
||||
3
examples/lang/nspawn2.mcl
Normal file
3
examples/lang/nspawn2.mcl
Normal file
@@ -0,0 +1,3 @@
|
||||
nspawn "Fedora-Cloud-Base-27-1.6.x86_64" {
|
||||
state => "running",
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import "os"
|
||||
|
||||
# this copies the contents from /tmp/foo and puts them in /tmp/output
|
||||
# this copies the contents from /tmp/input and puts them in /tmp/output
|
||||
file "/tmp/output" {
|
||||
content => os.readfile("/tmp/foo"),
|
||||
content => os.readfile("/tmp/input"),
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ virt "mgmt4" {
|
||||
# can't add this part until we fix the unification bug
|
||||
#disk => [
|
||||
# struct{
|
||||
# source => "~/.local/share/libvirt/images/fedora-23-scratch.qcow2",
|
||||
# type => "qcow2",
|
||||
# source => "~/.local/share/libvirt/images/fedora-23-scratch.qcow2",
|
||||
# type => "qcow2",
|
||||
# },
|
||||
#],
|
||||
# add the rest for unification bug
|
||||
|
||||
Reference in New Issue
Block a user