Class: Shards::BaseYamlObject

Inherits:
Base
  • Object
show all
Defined in:
lib/shards/base_yaml_object.rb

Direct Known Subclasses

Shard, Site

Instance Attribute Summary collapse

Attributes inherited from Base

#subdomain_param

Attributes included from Meta

#config

Instance Method Summary collapse

Methods inherited from Base

#default_region, method_list, #set_config

Methods included from Meta

#add, #custom_yaml, #default_yaml, #get_config, #method_list, #output, #print_output, #proxy, #proxy_user, #reset_output, #run, #ssh_conn, #test_env?, #write_extra_config_dirs, #yaml_file

Constructor Details

#initialize(stage) ⇒ BaseYamlObject

Returns a new instance of BaseYamlObject.



10
11
12
13
14
15
# File 'lib/shards/base_yaml_object.rb', line 10

def initialize stage
  set_config
  @stage=stage
  @yaml= YAML.load_file file
  @output=[]
end

Instance Attribute Details

#internal_hostObject



57
58
59
# File 'lib/shards/base_yaml_object.rb', line 57

def internal_host
  @internal_host || stage.internal_host
end

#stageObject (readonly)

Returns the value of attribute stage.



7
8
9
# File 'lib/shards/base_yaml_object.rb', line 7

def stage
  @stage
end

#yamlObject (readonly)

Returns the value of attribute yaml.



7
8
9
# File 'lib/shards/base_yaml_object.rb', line 7

def yaml
  @yaml
end

Instance Method Details

#command_to_read_remoteObject



61
62
63
# File 'lib/shards/base_yaml_object.rb', line 61

def command_to_read_remote
  command_to_remote internal_host, fingerprint_command(remote_file)
end

#command_to_remote(host, command) ⇒ Object



65
66
67
# File 'lib/shards/base_yaml_object.rb', line 65

def command_to_remote host, command
  "ssh -q -o StrictHostKeychecking=no #{host} '#{command}'"
end

#copy_file_to_extra_dirs(directories) ⇒ Object



33
34
35
36
37
# File 'lib/shards/base_yaml_object.rb', line 33

def copy_file_to_extra_dirs directories
  directories.each do |target_dir|
    FileUtils.cp_r file, target_config_dir(target_dir), remove_destination: true
  end
end

#dirObject



17
18
19
# File 'lib/shards/base_yaml_object.rb', line 17

def dir
  stage.get 'config_dir'
end

#fileObject



21
22
23
# File 'lib/shards/base_yaml_object.rb', line 21

def file
  file_path ENV['SHARDS_FILE_NAME']
end

#file_path(file_name) ⇒ Object



25
26
27
# File 'lib/shards/base_yaml_object.rb', line 25

def file_path file_name
  File.join(target_config_dir(dir) ,file_name)
end

#fingerprint_command(file_full_name) ⇒ Object



69
70
71
# File 'lib/shards/base_yaml_object.rb', line 69

def fingerprint_command file_full_name
  "md5sum #{file_full_name}"
end

#fingerprintsObject



85
86
87
88
89
90
91
# File 'lib/shards/base_yaml_object.rb', line 85

def fingerprints
  x={}
  x[:local]= local_fingerprint
  x[:remote]= remote_fingerprint
  x[:equal]= x[:local]==x[:remote]
  x
end

#local_fingerprintObject



73
74
75
# File 'lib/shards/base_yaml_object.rb', line 73

def local_fingerprint
  `#{fingerprint_command(file)}`.split.first
end

#proxy_read_remote_fileObject



47
48
49
# File 'lib/shards/base_yaml_object.rb', line 47

def proxy_read_remote_file
  ssh! command_to_read_remote
end

#remote_fileObject



43
44
45
# File 'lib/shards/base_yaml_object.rb', line 43

def remote_file
  File.join ENV['REMOTE_SERVER_CURRENT_PATH'],'config', File.basename(file)
end

#remote_fingerprintObject



77
78
79
# File 'lib/shards/base_yaml_object.rb', line 77

def remote_fingerprint
  proxy_read_remote_file.split.first
end

#same_fingerprint?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/shards/base_yaml_object.rb', line 81

def same_fingerprint?
  local_fingerprint == remote_fingerprint
end

#ssh!(command) ⇒ Object



51
52
53
54
55
# File 'lib/shards/base_yaml_object.rb', line 51

def ssh! command
  ssh_conn do |ssh|
    ssh.exec! command
  end
end

#target_config_dir(target_dir) ⇒ Object



29
30
31
# File 'lib/shards/base_yaml_object.rb', line 29

def target_config_dir target_dir
  File.join(ENV['ENGINEERING_ROOT_PATH'],ENV['CONFIG_FILES_ROOT_PATH'], target_dir)
end

#write_yamlObject



39
40
41
# File 'lib/shards/base_yaml_object.rb', line 39

def write_yaml
  File.write file, YAML.dump(yaml)
end