Module: DeltaCloud::Operation
- Defined in:
- lib/deltacloud-cli.rb
Defined Under Namespace
Class Method Summary collapse
- .client ⇒ Object
- .client=(client) ⇒ Object
- .current_config(key = nil, value = nil) ⇒ Object
- .execute(operation, resource, options = '') ⇒ Object
- .help ⇒ Object
- .init ⇒ Object
- .resources ⇒ Object
- .switch(resource, value) ⇒ Object
Class Method Details
.client ⇒ Object
36 |
# File 'lib/deltacloud-cli.rb', line 36 def self.client; @client ; end |
.client=(client) ⇒ Object
37 |
# File 'lib/deltacloud-cli.rb', line 37 def self.client=(client); @client=client; end |
.current_config(key = nil, value = nil) ⇒ Object
27 28 29 30 |
# File 'lib/deltacloud-cli.rb', line 27 def self.current_config(key=nil, value=nil) @current_config[:"#{key}"]=value unless key.nil? @current_config end |
.execute(operation, resource, options = '') ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deltacloud-cli.rb', line 39 def self.execute(operation, resource, ='') client = Operation::client operation = operation.to_sym resource.gsub!('-', '_') case operation when :get, :list then DeltaCloud::Operation::GET::new(operation, resource, ) when :create, :get, :start, :stop, :reboot then DeltaCloud::Operation::POST::new(operation, resource, ) when :destroy then DeltaCloud::Operation::DELETE::new(resource, ) when :switch then DeltaCloud::Operation::switch(resource.to_sym, ) end end |
.help ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/deltacloud-cli.rb', line 57 def self.help help = "\n* Basic commands:\n\n" help += " help\t\t- Print this help\n" help += " exit\t\t- Exit to shell\n" help += " config\t- Print current configuration\n" help += " resources\t- Print collections available for current configuration\n\n" help += "* Changing settings:\n" help += " Every change will take effect immediately.\n\n" help += " switch-driver DRIVER\t\t- Switch to other Deltacloud driver. (See also: list-drivers)\n" help += " switch-provider PROVIDER\t- Switch provider for current Deltacloud driver.\n" help += " switch-username USERNAME\t- Set Deltacloud username for current driver (Eg. API key).\n" help += " switch-password PASSWORD\t- Set Deltacloud user password for current driver (Eg. API Secret key).\n\n" help += "* Listing and getting resources:\n\n" help += " list-COLLECTION \t\t- Will list all resources for given collection (Eg. list-images, See: resources)\n" help += " get-RESOURCE ID \t\t- Get single resource identified by given ID (Eg. get-image img1)\n\n" help += "* Creating and destroying new resources:\n\n" help += " create-RESOURCE OPTIONS\t- Will create a new resource based on options (Eg. create-instance image_id:img1 hwp_id:m1-small)\n" help += " destroy-RESOURCE ID\t\t- Will execute start operation on given resource (Eg. start-instance inst1)\n\n" help += "* Managing resources:\n\n" help += " start-RESOURCE ID\t\t- Will execute start operation on given resource (Eg. start-instance inst1)\n" help += " stop-RESOURCE ID\t\t- Will execute stop operation on given resource (Eg. stop-instance inst1)\n" help += " reboot-RESOURCE ID\t\t- Will execute reboot operation on given resource (Eg. reboot-instance inst1)\n" help += "\n\n" end |
.init ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/deltacloud-cli.rb', line 11 def self.init @current_config = { :username => ENV['API_USER'], :password => ENV['API_PASSWORD'], :provider => ENV['API_PROVIDER'], :api => ENV['API_HOST'] } begin @client = DeltaCloud::new(@current_config[:username], @current_config[:password], @current_config[:api]) @current_config[:driver] = ENV['API_DRIVER'] || @client.driver_name rescue Errno::ECONNREFUSED puts "ERROR: Unable to connect: #{ENV['API_HOST']}" exit(1) end end |
.resources ⇒ Object
32 33 34 |
# File 'lib/deltacloud-cli.rb', line 32 def self.resources Operation::client.entry_points end |
.switch(resource, value) ⇒ Object
51 52 53 54 55 |
# File 'lib/deltacloud-cli.rb', line 51 def self.switch(resource, value) Operation::current_config(resource, value) client = Operation::client.with_config(Operation::current_config) Operation::current_config end |