Class: BBGAPI::Blocks
- Inherits:
-
Object
- Object
- BBGAPI::Blocks
- Defined in:
- lib/bbgapi/blocks.rb
Class Method Summary collapse
- .create ⇒ Object
- .find_id_from_name ⇒ Object
- .list ⇒ Object
- .menulist ⇒ Object
- .productmenu ⇒ Object
- .raw ⇒ Object
- .tbi ⇒ Object
- .templatemenu ⇒ Object
Class Method Details
.create ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/bbgapi/blocks.rb', line 69 def self.create productid = self. templateid = self. ssh_key_file = File.new("#{ENV['HOME']}/.ssh/id_rsa.pub", "r") keyfile = ssh_key_file.gets hostname = ask("Hostname: ") = { :body => { :product => productid, :template => templateid, :ssh_public_key => keyfile, :hostname => hostname } } partial = '/api/blocks' api_response = BBGAPI::Client.posturl(partial,) if api_response.code == 200 puts "Name: #{api_response["hostname"]}" puts "IP: #{api_response["ips"].first["address"]}" puts "Status: #{api_response["status"]}" puts "\n" puts "Sleeping 5 minutes while server boots up" sleep 300 choose do || .prompt = "Do you want to ssh to this new server?" .choices(:yes) { system("open", "ssh://deploy@#{api_response["ips"].first["address"]}") } .choices(:no) end choose do || .prompt = "Do you want to bootstrap this new server?" .choices(:yes) { ssh_host = api_response["ips"].first["address"] ssh_user = 'deploy' begin Net::SSH.start( ssh_host, ssh_user ) do|ssh| output = ssh.exec('sudo chmod +x /root/bootstrap.sh && sudo /root/bootstrap.sh') puts output end rescue Net::SSH::HostKeyMismatch => e puts "remembering new key: #{e.fingerprint}" e.remember_host! retry end } .choices(:no) end choose do || .prompt = "Do you want to add this machine to a load balanced pool?" .choices(:yes) { ssh_host = api_response["ips"].first["address"] ssh_user = 'deploy' begin Net::SSH.start( ssh_host, ssh_user ) do|ssh| output = ssh.exec('sudo chmod +x /root/tools/lb_add.sh && sudo /root/tools/lb_add.sh autoadd') puts output end rescue Net::SSH::HostKeyMismatch => e puts "remembering new key: #{e.fingerprint}" e.remember_host! retry end } .choices(:no) end else #puts "Recieved a #{api_response.code} to the request" end end |
.find_id_from_name ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bbgapi/blocks.rb', line 32 def self.find_id_from_name partial = '/api/blocks' api_response = BBGAPI::Client.geturl(partial,"") machines=api_response.first["lb_machines"] hostname = "#{id}.c45451" srv = machines.find_all{|item| item["hostname"] == hostname } srv_id = srv.first["id"] end |
.list ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bbgapi/blocks.rb', line 15 def self.list partial = '/api/blocks' api_response = BBGAPI::Client.geturl(partial,"") api_response.each {|x| puts "\n" puts "Name: #{x["hostname"]}" puts "ID: #{x["id"]}" puts "External IP: #{x["ips"].first["address"]}" if !x["lb_applications"].empty? puts "LB App: #{x["lb_applications"].first["lb_application_name"]}" end } puts "\n" end |
.menulist ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/bbgapi/blocks.rb', line 3 def self. choose do || puts "Blocks" puts "----------------------------------------" .prompt = "Which Action?" .choices(:list) {self.list} .choices(:create) {self.create} .choices(:delete) {self.tbi} end end |
.productmenu ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bbgapi/blocks.rb', line 49 def self. products = BBGAPI::Blocks_Products.raw choose do || .prompt = "Which Product Would You Like?" products.each {|product| .choices(product["description"]) {return product["id"]} } end end |
.raw ⇒ Object
43 44 45 46 47 |
# File 'lib/bbgapi/blocks.rb', line 43 def self.raw partial = '/api/blocks' api_response = BBGAPI::Client.geturl(partial,"") return api_response end |
.tbi ⇒ Object
145 146 147 |
# File 'lib/bbgapi/blocks.rb', line 145 def self.tbi puts "This is not yet implemented\n" end |
.templatemenu ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/bbgapi/blocks.rb', line 59 def self. templates = BBGAPI::Blocks_Templates.raw choose do || .prompt = "Which Template Would You Like?" templates.each {|template| .choices(template["description"]) {return template["id"]} } end end |