lib/cloudstack-cli/helper.rb in cloudstack-cli-0.0.5 vs lib/cloudstack-cli/helper.rb in cloudstack-cli-0.1.0
- old
+ new
@@ -1,9 +1,7 @@
module CloudstackCli
class Helper
- include CommandLineReporter
-
attr_reader :cs
def initialize(config_file)
@config_file = config_file
@cs = CloudstackClient::Connection.new(
@@ -11,33 +9,27 @@
options[:api_key],
options[:secret_key]
)
end
- def remove_publicip(id)
- @cs.disassociate_ip_address(id)
+ def options
+ @options ||= CloudstackClient::ConnectionHelper.load_configuration(@config_file)
end
+ def print_options(options, attr = 'name')
+ options.to_enum.with_index(1).each do |option, i|
+ puts "#{i}: #{option[attr]}"
+ end
+ end
+
def domains(name = nil)
@cs.list_domains(name)
end
def server_offerings(domain = nil)
@server_offerings ||= @cs.list_service_offerings(domain)
end
-
- def create_offering(params)
- @cs.create_offering(params)
- end
-
- def delete_offering(id)
- @cs.delete_offering(id)
- end
-
- def update_offering(args)
- @cs.update_offering(args)
- end
def templates(type = 'featured', project_id = -1)
@templates ||= @cs.list_templates(type, project_id)
end
@@ -51,46 +43,18 @@
def networks(project_id = nil)
@cs.list_networks(project_id)
end
- def physical_networks
- @cs.list_physical_networks
- end
def volumes(project_id = nil)
@cs.list_volumes(project_id)
end
def virtual_machines(options = {})
@cs.list_servers(options)
end
-
- def virtual_machines_table(vms)
- table(border: true) do
- row do
- column 'Name', width: 20
- column 'State'
- column 'Offering', align: 'right'
- column 'Template', align: 'right', width: 30
- column 'IP\'s', width: 14
- column 'Project'
- column 'Account'
- end
- vms.each do |vm|
- row do
- column vm['name']
- column vm['state']
- column vm['serviceofferingname']
- column vm['templatename']
- column vm['nic'].map { |nic| nic['ipaddress']}.join(" ")
- column vm['project']
- column vm['account']
- end
- end
- end
- end
def bootstrap_server(name, zone, template, offering, networks, pf_rules = [], project = nil)
puts "Create server #{name}...".color(:yellow)
server = @cs.create_server(
name,
@@ -126,22 +90,10 @@
puts
puts "Complete!".color(:green)
end
- def stop_server(name)
- @cs.stop_server(name)
- end
-
- def start_server(name)
- @cs.start_server(name)
- end
-
- def reboot_server(name)
- @cs.reboot_server(name)
- end
-
def list_accounts(name = nil)
@cs.list_accounts({ name: name })
end
def list_load_balancer_rules(project = nil)
@@ -160,39 +112,9 @@
if rule['success']
puts "OK!".color(:green)
else
puts "Failed!".color(:red)
end
- end
-
- def list_routers(args, redundant_state = nil)
- routers = @cs.list_routers(args)
- if redundant_state
- return routers.select {|r| r['redundantstate'].downcase == redundant_state.downcase }
- end
- routers
- end
-
- def destroy_router(id)
- @cs.destroy_router(id)
- end
-
- def start_router(id)
- @cs.start_router(id)
- end
-
- def stop_router(id)
- @cs.stop_router(id)
- end
-
- def options
- @options ||= CloudstackClient::ConnectionHelper.load_configuration(@config_file)
- end
-
- def print_options(options, attr = 'name')
- options.to_enum.with_index(1).each do |option, i|
- puts "#{i}: #{option[attr]}"
- end
end
def bootstrap_server_interactive
ARGV.clear
puts
\ No newline at end of file