Skip to content

Instantly share code, notes, and snippets.

@sseago
Created March 20, 2014 14:27
Show Gist options
  • Save sseago/9664899 to your computer and use it in GitHub Desktop.
Save sseago/9664899 to your computer and use it in GitHub Desktop.
User.current = User.find_by_login 'admin'
#----------------------------------------------------------
base_hostgroup = Hostgroup.where(:name => "base_hostgroup").first_or_create!
deployment = Staypuft::Deployment.new(:name => SecureRandom.hex)
deployment.description = "This is a deployment"
deployment.layout = Staypuft::Layout.where(:name => "Distributed",
:networking => "neutron").first
deployment_hostgroup = Hostgroup.new(:name => SecureRandom.hex)
deployment_hostgroup.parent_id = base_hostgroup.id
deployment_hostgroup.save!
deployment.hostgroup = deployment_hostgroup
deployment.save!
# ------------------------------------------------------------
deployment.layout.roles.each do |role|
role_hostgroup = Hostgroup.where(:name =>"#{deployment.name}: #{role.name}").first_or_initialize
role_hostgroup.parent_id = deployment_hostgroup.parent_id
unless role_hostgroup.puppetclasses.include?(role.puppetclasses.first)
role_hostgroup.puppetclasses << role.puppetclasses.first
end
role_hostgroup.save!
Staypuft::DeploymentRoleHostgroup.where(:deployment_id => deployment.id, :hostgroup_id => role_hostgroup.id).first_or_create!
Staypuft::HostgroupRole.where(:role_id => role.id, :hostgroup_id => role_hostgroup.id).first_or_create!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment