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?, #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



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

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



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

def command_to_read_remote
  command_to_remote internal_host, fingerprint_command(remote_file)
end

#command_to_remote(host, command) ⇒ Object



55
56
57
# File 'lib/shards/base_yaml_object.rb', line 55

def command_to_remote host, command
  "ssh -q -o StrictHostKeychecking=no #{host} '#{command}'"
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(ENV['ENGINEERING_ROOT_PATH'],ENV['CONFIG_FILES_ROOT_PATH'], dir ,file_name)
end

#fingerprint_command(file_full_name) ⇒ Object



59
60
61
# File 'lib/shards/base_yaml_object.rb', line 59

def fingerprint_command file_full_name
  "md5sum #{file_full_name}"
end

#fingerprintsObject



75
76
77
78
79
80
81
# File 'lib/shards/base_yaml_object.rb', line 75

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

#local_fingerprintObject



63
64
65
# File 'lib/shards/base_yaml_object.rb', line 63

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

#proxy_read_remote_fileObject



37
38
39
# File 'lib/shards/base_yaml_object.rb', line 37

def proxy_read_remote_file
  ssh! command_to_read_remote
end

#remote_fileObject



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

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

#remote_fingerprintObject



67
68
69
# File 'lib/shards/base_yaml_object.rb', line 67

def remote_fingerprint
  proxy_read_remote_file.split.first
end

#same_fingerprint?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/shards/base_yaml_object.rb', line 71

def same_fingerprint?
  local_fingerprint == remote_fingerprint
end

#ssh!(command) ⇒ Object



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

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

#write_yamlObject



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

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