Skip to content

Instantly share code, notes, and snippets.

@lastcanal
Created January 27, 2012 05:49
Show Gist options
  • Save lastcanal/1687253 to your computer and use it in GitHub Desktop.
Save lastcanal/1687253 to your computer and use it in GitHub Desktop.
require 'fog/vcloud'
# connect to cloud
connection = Vcloud::Compute.new(
:vcloud_host => 'vcloud.moc',
:vcloud_username => 'username',
:vcloud_password => 'password'
)
# virtual image template
template = "https://vcloud.moc/api/v1.0/vApp/vapp-1"
# create server
server = Vcloud::Compute::Servers.new(
:connection => connection, :href => template
).first
# update server attributes
server.name = "testserver"
server.description = "Testing fog"
server.cpus = 4
server.memory = (8 * 1024 * 1024)
# add disks
3.times do
server.add_disk(8 * 1024 * 1024)
end
# push server
server.save
server.reload
# start server
server.power_on
server.wait_for do
ready?
end
# setup user
server.scp("root", "alpine").run("/etc/master.password", "npasswd")
server.ssh("root", "alpine").run("passwd -l root")
# setup rbac
server.scp("root", "npasswd").run("/staging/rscd", "/staging/rscd", :resursive => true)
server.ssh("root", "npasswd").run("/staging/rscd/bin/setup")
# execute batch jobs
ao = Atrium.new("ao", "aopass", "http://cdp")
ao.execute(":server:bootstrap", server.attributes.merge(
:hostname => server.computer_name,
:os_desc => server.os_desc,
:os_type => server.os_type,
:ip_address => server.ip_address,
:cpus => server.cpus,
:memory => server.memory,
:disks => server.disks
))
# stop and cleanup
server.destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment