Class: Megam::DeleteNode

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(node_name, 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
# File 'lib/megam/builder/delete_node.rb', line 23

def self.create(node_name, group, action)

  delete_command = self.new()
  begin
    node_collection = delete_command.megam_rest.get_node(node_name)
    ct_collection = delete_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

  node = node_collection.data[:body].lookup(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)
  ci_command = "#{cloud_instruction.command}"
  ci_command["<node_name>"] = "#{node_name}"
     command_hash = {
    "systemprovider" => {
      "provider" => {
        "prov" => "#{node.request[:command]['systemprovider']['provider']['prov']}"
      }
    },
    "compute" => {
      "cctype" => "#{node.request[:command]['compute']['cctype']}",
      "cc" => {
        "groups" => "",
        "image" => "",
        "flavor" => ""
      },
      "access" => {
        "ssh_key" => "#{node.request[:command]['compute']['access']['ssh_key']}",
        "identity_file" => "#{node.request[:command]['compute']['access']['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']}"
      }
    },
    "cloudtool" => {
      "chef" => {
        "command" => "#{node.request[:command]['cloudtool']['chef']['prov']}",
        "plugin" => "#{node.request[:command]['compute']['cctype']} #{ci_command}", #ec2 server delete or create
        "run_list" => "",
        "name" => "-N #{node_name}"
      }
    }
  }

  node_hash = {
    "node_name" => "#{node_name}",
    "req_type" => "#{action}",
    "command" => command_hash
  }
  node_hash
end

Instance Method Details

#megam_restObject



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

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