Skip to content

Instantly share code, notes, and snippets.

(defn is-in-env?
"Return true if node N is in the desired environment according to the
subtree rooted at G. The following helpers are used:
(good? g) - true if g sets the environment to the desired one
(bad? g) - (not (good? g)) Note that this includes groups that do
not set the environment at all
(matches? n g) - true if the node N matches G's rule
(children g) - a list of G's child groups
Ignores environment trumps/override"
@lutter
lutter / deps.pp
Created September 17, 2014 22:18
Collection-based dependencies
define echo {
exec { "echo-$name":
command => "/usr/bin/echo $name"
}
}
Foo <| color == 'green' |> -> echo { "yo": } -> Foo <| color == 'red' |>
define foo($color) {
notice("foo[$name]: $color")
> gem install pe-razor-client
> export RAZOR_API=http://razor-server:8080/api
# Use any mirror listed here: http://isoredirect.centos.org/centos/6/isos/x86_64/
# This will take a while, since it will download the ISO and unpack it. The response
# will mention a command, which you can use to check the progress/errors of the
# download via 'razor commands NNN'
> razor create-repo --name centos-6.5 --task centos \
--iso-url http://mirror.anl.gov/pub/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso
# A tag that will match any machine
> razor create-tag --name any --rule '["=", 1, 1]'
@lutter
lutter / README.md
Created June 25, 2014 12:17
Hook design document

Hooks

Hooks provide a way to be notified of certain events during the operation of the Razor server; the behavior of a hook is defined by a hook type.

File layout for a hook type

Similar to brokers and tasks, hook types are defined through a .hook directory and files within that directory:

nodes:
short:
layout: table
columns:
name:
dhcp_mac:
format: mac
tags:
format: tag_names
policy:
diff --git a/app.rb b/app.rb
index ae74307..75f43f2 100644
--- a/app.rb
+++ b/app.rb
@@ -505,6 +505,21 @@ class Razor::App < Sinatra::Base
command :create_repo do |data|
check_permissions! "commands:create-repo:#{data['name']}"
+
+ unless data['name'].is_a? String
command :unbind_node do |data|
data['name'] or error 400,
:error => "Supply 'name' to indicate which node to unbind"
if node = Razor::Data::Node.find_by_name(data['name'])
if node.policy
policy_name = node.policy.name
node.log_append(:event => :unbind, :policy => policy_name)
node.policy = nil
node.bound = false
node.save
@lutter
lutter / server-microkernel.md
Last active December 25, 2015 22:19
Some thoughts on evolving the Server/Microkernel protocol

Today

The main point of interaction between server and microkernel is the /svc/checkin/:id endpoint. It currently expects that the Microkernel peridoically posts the following JSON to that URL:

{
  "facts": { ... facts hash ... }
}
@lutter
lutter / network.xml
Created September 25, 2013 23:02
libvirt network on my laptop
<network>
<name>local</name>
<uuid>d5e4d859-721b-caf1-4842-21704dea23dd</uuid>
<forward mode='nat'/>
<bridge name='virbr2' stp='on' delay='0' />
<mac address='52:54:00:ca:8d:34'/>
<domain name='example.org'/>
<ip address='192.168.100.1' netmask='255.255.255.0'>
<tftp root='/var/lib/tftpboot' />
<dhcp>
@lutter
lutter / unpack
Created September 24, 2013 23:13
Little test script to try out libarchive. Run as 'bundle exec ruby unpack spec/fixtures/iso/tiny.iso /tmp/isotest' from the razor-server checkout
#! /usr/bin/env jruby
require 'archive'
unless ARGV.size == 2
puts "Usage: unpack ISO DIRECTORY"
puts "Unbpack ISO into the DIRECTORY"
end
destination = Pathname.new(ARGV[1])