Module: ResourceIn::MachineResourceImpl

Included in:
Machine
Defined in:
lib/resource_in/machine_impl.rb

Instance Method Summary collapse

Instance Method Details

#do_create(options) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/resource_in/machine_impl.rb', line 72

def do_create(options)
  @drivers.each do |klass|
    obj = klass.new

    obj.create(options)
  end
end

#filter(condition, data) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/resource_in/machine_impl.rb', line 30

def filter(condition, data)
  data.select do |d|
    cond = false
    cond |= d['name'] =~ /^#{condition}/
    cond |= d['address'].any? {|x| x =~ /^#{condition}/}
  end
end

#get(condition) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/resource_in/machine_impl.rb', line 23

def get(condition)
  @drivers.map do |klass|
    obj = klass.new

    obj.get(condition)
  end.flatten
end

#listObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/resource_in/machine_impl.rb', line 3

def list
  @drivers.map do |klass|
    driver_racktables = RacktablesDriver.new
    obj = klass.new

    case [klass]
    when [ResourceIn::VMwareDriver]
      obj.list.map do |each|
        last_update = driver_racktables.get_lastupdate(each['name'])
        if !!last_update and last_update['status'] != 'error'
          each['created_by'] = "#{last_update['person']}"
        end

        each
      end
    else
      obj.list
    end
  end.flatten
end

#output(data) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/resource_in/machine_impl.rb', line 37

def output(data)
  format = Driver::FORMAT

  table_output = table do |t|
    t.headings = format
    data.each do |each|
      line = []
      format.each_with_index do |k, i|
        case k
        when 'address'
          line[i] = each[k].join("\n")
        else
          line[i] = each[k]
        end
      end
      t << line
    end
  end

  puts table_output
end

#output_detail(data) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/resource_in/machine_impl.rb', line 58

def output_detail(data)
  table = Terminal::Table.new do |t|
    format = Driver::DETAIL_FORMAT

    t << [key = format.shift, data.first[key]]
    t << :separator

    format.each do |k|
      t << [k, data.first[k]]
    end
  end

  puts table
end