Class: Megam::MakeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/builder/make_node.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(data, group, action) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
# File 'lib/megam/builder/make_node.rb', line 23

def self.create(data, group, action)

   make_command = self.new()
 begin
  pc_collection = make_command.megam_rest.get_predefclouds
  ct_collection = make_command.megam_rest.get_cloudtools
  
rescue ArgumentError => ae
  hash = {"msg" => ae.message, "msg_type" => "error"}
  re = Megam::Error.from_hash(hash)
  return re
rescue Megam::API::Errors::ErrorWithResponse => ewr
  hash = {"msg" => ewr.message, "msg_type" => "error"}
  re = Megam::Error.from_hash(hash)
  return re
rescue StandardError => se
  hash = {"msg" => se.message, "msg_type" => "error"}
  re = Megam::Error.from_hash(hash)
  return re
end


predef_cloud = pc_collection.data[:body].lookup("#{data[:predef_cloud_name]}")
tool = ct_collection.data[:body].lookup(data[:provider])
template = tool.cloudtemplates.lookup(predef_cloud.spec[:type_name])
cloud_instruction = template.lookup_by_instruction(group, action)
ci_command = cloud_instruction.command
ci_name = cloud_instruction.name

command_hash = {
"systemprovider" => {
"provider" => {
"prov" => "#{data[:provider]}"
}
},
"compute" => {
"cctype" => "#{predef_cloud.spec[:type_name]}",
"cc"=> {
"groups" => "#{predef_cloud.spec[:groups]}",
"image" => "#{predef_cloud.spec[:image]}",
"flavor" => "#{predef_cloud.spec[:flavor]}"
},
"access" => {
"ssh_key" => "#{predef_cloud.access[:ssh_key]}",
"identity_file" => "#{predef_cloud.access[:identity_file]}",
"ssh_user" => "#{predef_cloud.access[:ssh_user]}",
"vault_location" => "#{predef_cloud.access[:vault_location]}",
"sshpub_location" => "#{predef_cloud.access[:sshpub_location]}"
}
},
"cloudtool" => {
"chef" => {
"command" => "#{tool.cli}",
"plugin" => "#{template.cctype} #{ci_command}",
"run_list" => "'role[#{data[:provider_role]}]'",
"name" => "#{ci_name} #{data[:book_name]}"
}
}
}

  node_hash = {
    "node_name" => "#{data[:book_name]}#{data[:domain_name]}",
    "node_type" => "#{data[:book_type]}",
    "req_type" => "#{action}",
    "noofinstances" => data[:no_of_instances],
    "command" => command_hash,
    "predefs" => {"name" => data[:predef_name], "scm" => "#{data[:deps_scm]}",
      "db" => "[email protected]/morning.megam.co", "war" => "#{data[:deps_war]}", "queue" => "queue@queue1", "runtime_exec" => data[:runtime_exec]},
    "appdefns" => {"timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
    "boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
    "appreq" => {},
    "boltreq" => {}
  }

  if data[:book_type] == "APP"
    node_hash["appdefns"] = {"timetokill" => "#{data[:timetokill]}", "metered" => "#{data[:metered]}", "logging" => "#{data[:logging]}", "runtime_exec" => "#{data[:runtime_exec]}"}
  end
  if data[:book_type] == "BOLT"
    node_hash["boltdefns"] = {"username" => "#{data['user_name']}", "apikey" => "#{data['password']}", "store_name" => "#{data['store_db_name']}", "url" => "#{data['url']}", "prime" => "#{data['prime']}", "timetokill" => "#{data['timetokill']}", "metered" => "#{data['monitoring']}", "logging" => "#{data['logging']}", "runtime_exec" => "#{data['runtime_exec']}" }
  end

node_hash
end

Instance Method Details

#megam_rest ⇒ Object



18
19
20
21
# File 'lib/megam/builder/make_node.rb', line 18

def megam_rest
  options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
  Megam::API.new(options)
end