Skip to content

Instantly share code, notes, and snippets.

@lutter
Created November 18, 2013 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lutter/7530139 to your computer and use it in GitHub Desktop.
Save lutter/7530139 to your computer and use it in GitHub Desktop.
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
action = "node unbound. policy was #{policy_name}"
elsif node.bound
# Node was bound, policy had been deleted some time before
node.bound = false
node.log_append(:event => :unbind)
else
action = "no changes; node #{data['name']} is not bound"
end
else
action = "no changes; node #{data['name']} does not exist"
end
{ :result => action }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment