Class: BBGAPI::Blocks_Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/bbgapi/blocks_templates.rb

Class Method Summary collapse

Class Method Details

.blocksmenuObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bbgapi/blocks_templates.rb', line 44

def self.blocksmenu
  choose do |menu|
    menu.prompt = "Are you templating a VPS or a Block?"

    menu.choices(:vps) {
      vpslist = BBGAPI::Servers.raw
      choose do |vpsmenu|
        vpsmenu.prompt = "Which VPS?"
        vpslist.each {|vps| 
          vpsmenu.choices(vps["hostname"]) {return vps["id"]}
        }
      end
    }
    menu.choices(:block) {
      vpslist = BBGAPI::Blocks.raw
      choose do |vpsmenu|
        vpsmenu.prompt = "Which Block?"
        vpslist.each {|vps| 
          vpsmenu.choices(vps["hostname"]) {return vps["id"]}
        } 
      end
    }
  end
end

.createObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bbgapi/blocks_templates.rb', line 69

def self.create
  blockid = self.blocksmenu

  options = { :body => {
    :id => blockid
    } }

  partial = '/api/block_templates'
  api_response = BBGAPI::Client.posturl(partial,options)
  puts "#{api_response["text"]}"
end

.listObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bbgapi/blocks_templates.rb', line 16

def self.list
  partial = '/api/block_templates'
  api_response = BBGAPI::Client.geturl(partial,"")

  srv = api_response.find_all{|item| !item["public"] }
  sorted = srv.sort_by {|a| a["created"]}.reverse

  puts "Last 10 Images:"

  sorted.each_with_index {|x,i|
    break if i == 10;
    puts "#{x["description"]} - #{x["id"]}"
  }
  puts "\n"

  pubsrv = api_response.find_all{|item| item["public"] }
  pubsorted = pubsrv.sort_by {|a| a["description"]}

  puts "Public Images (limit 10):"

  pubsorted.each_with_index {|x,i|
    break if i == 10;
    puts "#{x["description"]} - #{x["id"]}"
  }
  puts "\n"

end


3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bbgapi/blocks_templates.rb', line 3

def self.menulist
  choose do |menu|
    puts "Block Templates"
    puts "----------------------------------------"
    menu.prompt = "Which Action?"

    menu.choices(:list) {self.list}
    menu.choices(:create) {self.create}
    menu.choices(:update) {self.tbi}
    menu.choices(:delete) {self.tbi}
  end
end

.rawObject



81
82
83
84
85
86
# File 'lib/bbgapi/blocks_templates.rb', line 81

def self.raw
  partial = '/api/block_templates'
  api_response = BBGAPI::Client.geturl(partial,"")
  sorted = api_response.sort_by {|a| a["created"]}.reverse
  return sorted
end

.tbiObject



88
89
90
# File 'lib/bbgapi/blocks_templates.rb', line 88

def self.tbi
  puts "This is not yet implemented"
end