Class: Haas::Cluster

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/models/cluster.rb

Instance Method Summary collapse

Instance Method Details

#chef_client_pem_pathObject



20
21
22
# File 'lib/models/cluster.rb', line 20

def chef_client_pem_path
  File.join(self.working_dir_path,"haas-api.pem")
end

#chef_validator_pem_pathObject



24
25
26
# File 'lib/models/cluster.rb', line 24

def chef_validator_pem_path
  File.join(self.working_dir_path,"haas-validator.pem")
end

#generate_nameObject



32
33
34
35
# File 'lib/models/cluster.rb', line 32

def generate_name
  random_str = (0...8).map { (65 + rand(26)).chr }.join
  self.name = "HAAS-#{random_str}"
end

#get_ambari_serverObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/models/cluster.rb', line 49

def get_ambari_server
  ambari_server = self.nodes.where('nodes.ambari_server=?',true)
  if ambari_server.first
    return ambari_server.first
  else
    node = self.nodes.where('nodes.chef_server IS NULL').first
    node.ambari_server = true
    node.save
    return node
  end
end

#get_chef_serverObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/models/cluster.rb', line 37

def get_chef_server
  chef_server = self.nodes.where('nodes.chef_server=?',true)
  if chef_server.first
    return chef_server.first
  else
    node = self.nodes.first
    node.chef_server = true
    node.save
    return node
  end
end

#identity_file_pathObject



16
17
18
# File 'lib/models/cluster.rb', line 16

def identity_file_path
  File.join(self.working_dir_path,"ssh-#{self.name}.pem")
end

#knife_config_pathObject



28
29
30
# File 'lib/models/cluster.rb', line 28

def knife_config_path
  File.join(self.working_dir_path,"knife.rb")
end

#mkdir_cluster_homeObject



7
8
9
10
# File 'lib/models/cluster.rb', line 7

def mkdir_cluster_home
  require 'fileutils'
  FileUtils.mkdir_p self.working_dir_path
end

#working_dir_pathObject



12
13
14
# File 'lib/models/cluster.rb', line 12

def working_dir_path
  File.join(Haas::Config::WORKING_DIR, self.name)
end