Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New subcommands to show/update a server settings #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/chef/knife/softlayer_server_show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'chef/knife/softlayer_base'

class Chef
class Knife
class SoftlayerServerShow < Knife

include Knife::SoftlayerBase

banner 'knife softlayer server show ID (options)'

##
# Run the procedure to list all of the Softlayer VM's
# @return [nil]
def run
unless name_args.size == 1
puts ui.color("Specify a node ID to show.", :red)
show_usage
exit 1
end
$stdout.sync = false
server = connection.servers.get(name_args[0])

puts "#{ui.color("ID:", :green)} #{server.id}"
puts "#{ui.color("Name:", :green)} #{server.fqdn}"
puts "#{ui.color("CPU:", :green)} #{server.cpu}"
puts "#{ui.color("RAM:", :green)} #{server.ram}"
puts "#{ui.color("Datacenter:", :green)} #{server.datacenter}"
puts "#{ui.color("Public IP:", :green)} #{server.public_ip_address}"
puts "#{ui.color("Public Speed:", :green)} #{server.network_components[0].speed}"
puts "#{ui.color("Private IP:", :green)} #{server.private_ip_address}"
puts "#{ui.color("Private Speed:", :green)} #{server.network_components[1].speed}"
puts "#{ui.color("Status:", :green)} #{server.state}"
end
end
end
end
85 changes: 85 additions & 0 deletions lib/chef/knife/softlayer_server_update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require 'chef/knife/softlayer_base'

class Chef
class Knife
class SoftlayerServerUpdate < Knife

include Knife::SoftlayerBase

banner 'knife softlayer server update ID (options)'

option :ram,
:long => "--ram SIZE",
:description => "update ram size. In GBs"

option :cpu,
:long => "--cpu COUNT",
:description => "update cpu count"

option :nic,
:long => '--network-interface-speed VALUE',
:short => '-n VALUE',
:description => 'The maximum speed of the public NIC available to the instance.',
:default => nil

option :time,
:long => "--time Time",
:description => "set time when to make a change",
:default => Time.now

##
# Run the procedure to list all of the Softlayer VM's
# @return [nil]
def run
unless name_args.size == 1
puts ui.color("Specify a node ID to update.", :red)
show_usage
exit 1
end

new_attributes = Mash.new

new_attributes[:guest_core] = config[:cpu] if !!config[:cpu]
new_attributes[:network_components] = [ {"speed" => config[:nic]} ] if !!config[:nic]
new_attributes[:ram] = config[:ram] if !!config[:ram]
new_attributes[:time] = config[:time]

$stdout.sync = true
server = connection.servers.get(name_args[0])
if config[:guest_core] || config[:ram] || config[:nic]
server.update(new_attributes)
end
sleep 9

progress Proc.new { server.wait_for { ready? } }

server = connection.servers.get(name_args[0])
puts "#{ui.color("ID:", :green)} #{server.id}"
puts "#{ui.color("Name:", :green)} #{server.fqdn}"
puts "#{ui.color("CPU:", :green)} #{server.cpu}"
puts "#{ui.color("RAM:", :green)} #{server.ram}"
puts "#{ui.color("Datacenter:", :green)} #{server.datacenter}"
puts "#{ui.color("Public IP:", :green)} #{server.public_ip_address}"
puts "#{ui.color("Public Speed:", :green)} #{server.network_components[0].speed}"
puts "#{ui.color("Private IP:", :green)} #{server.private_ip_address}"
puts "#{ui.color("Private Speed:", :green)} #{server.network_components[1].speed}"
puts "#{ui.color("Status:", :green)} #{server.state}"
end

def progress(proc)
t = Thread.new { Thread.current[:output] = proc.call }
i = 0
while t.alive?
sleep 0.5
putc('.')
i += 1
putc("\n") if i == 76
i = 0 if i == 76
end
putc("\n")
t.join
t[:output]
end
end
end
end