Class: Megam::DeleteNode

Inherits:
ServerAPI show all
Defined in:
lib/megam/builder/delete_node.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ DeleteNode

Returns a new instance of DeleteNode.



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

def initialize(email=nil, api_key=nil)
  super(email, api_key)
end

Class Method Details

.create(data, group, action, tmp_email = nil, tmp_api_key = nil) ⇒ Object



22
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/delete_node.rb', line 22

def self.create(data, group, action, tmp_email=nil, tmp_api_key=nil)
  delete_command = self.new(tmp_email, tmp_api_key)
  begin
    node_collection = delete_command.megam_rest.get_node(data[:node_name])
    ct_collection = delete_command.megam_rest.get_cloudtools
    cts_collection = delete_command.megam_rest.get_cloudtoolsettings
  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    
  node = node_collection.data[:body].lookup(data[:node_name])     
  tool = ct_collection.data[:body].lookup(node.request[:command]['systemprovider']['provider']['prov'])
  template = tool.cloudtemplates.lookup(node.request[:command]['compute']['cctype'])
  cloud_instruction = template.lookup_by_instruction(group, action)
  cts = cts_collection.data[:body].lookup(data[:repo])     
  ci_command = "#{cloud_instruction.command}"
  if ci_command["<node_name>"].present?
    ci_command["<node_name>"] = "#{data[:node_name]}"
  end
  u = URI.parse(node.request[:command]['compute']['access']['vault_location'])
  u.path[0]=""
  if ci_command["-f"].present?
    ci_command["-f"] = "-f " + u.path + "/#{node.request[:command]['compute']['cctype']}.json"
  end

  if ci_command["-c"].present?
    ci_command["-c"] = "-c #{cts.conf_location}"
  end
  command_hash = {
    "systemprovider" => {
      "provider" => {
        "prov" => "#{node.request[:command]['systemprovider']['provider']['prov']}"
      }
    },
    "compute" => {
      "cctype" => "#{node.request[:command]['compute']['cctype']}",
      "cc" => {
        "groups" => "",
        "image" => "",
        "flavor" => "",
        "tenant_id" =>  "#{node.request[:command]['compute']['cc']['tenant_id']}"
      },
      "access" => {
        "ssh_key" => "",
        "identity_file" => "",
        "ssh_user" => "",
        "vault_location" => "#{node.request[:command]['compute']['access']['vault_location']}",
        "sshpub_location" => "#{node.request[:command]['compute']['access']['sshpub_location']}",
        "zone" => "#{node.request[:command]['compute']['access']['zone']}",
        "region" => "#{node.request[:command]['compute']['access']['region']}"
      }
    },
    "cloudtool" => {
      "chef" => {
        "command" => "#{node.request[:command]['cloudtool']['chef']['command']}",
        "plugin" => "#{node.request[:command]['compute']['cctype']} #{ci_command}", #ec2 server delete or create
        "run_list" => "",
        "name" => "-N #{data[:node_name]}"
      }
    }
  }
  node_hash = {
    "node_name" => "#{data[:node_name]}",
    "node_type" => "#{node.node_type}",
    "req_type" => "#{action}",
    "noofinstances" => "",
    "command" => command_hash,
    "predefs" => {},
    "appdefns" => {},
    "boltdefns" => {},
    "appreq" => {},
    "boltreq" => {}
  }
  node_hash
end