Class: Replicator

Inherits:
Object
  • Object
show all
Defined in:
lib/one_helper/onezone_helper.rb

Overview

Check differences between files and copy them

Constant Summary collapse

SSH_OPTIONS =
'-o stricthostkeychecking=no -o passwordauthentication=no'
ONE_AUTH =
'/var/lib/one/.one/one_auth'
FED_ATTRS =
['MODE', 'ZONE_ID', 'SERVER_ID', 'MASTER_ONED']
FILES =
[
    { :name    => 'monitord.conf',
      :service => 'opennebula' },
    { :name    => 'oneflow-server.conf',
      :service => 'opennebula-flow' },
    { :name    => 'onegate-server.conf',
      :service => 'opennebula-gate' }
]
FOLDERS =
[
    { :name => 'auth', :service => 'opennebula' },
    { :name => 'hm', :service => 'opennebula' },
    { :name => 'vmm_exec', :service => 'opennebula' },
    { :name => 'schedulers', :service => 'opennebula' }
]

Instance Method Summary collapse

Constructor Details

#initialize(ssh_key, server) ⇒ Replicator

Class constructor

Parameters:

  • ssh_key (String)

    SSH key file path

  • server (String)

    OpenNebula server IP address



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
# File 'lib/one_helper/onezone_helper.rb', line 53

def initialize(ssh_key, server)
    @oneadmin_identity_file = ssh_key
    @remote_server          = server

    # Get local configuration
    l_credentials = File.read(ONE_AUTH).gsub("\n", '')
    l_endpoint    = 'http://localhost:2633/RPC2'
    local_client  = Client.new(l_credentials, l_endpoint)

    @l_config = System.new(local_client).get_configuration
    @l_config_elements = { :raw => @l_config }
    @l_fed_elements    = { :raw => @l_config }

    if OpenNebula.is_error?(@l_config)
        STDERR.puts 'Unable to read local OpenNebula configuration. ' \
                    'Is OpenNebula running?'
        exit(-1)
    end

    fetch_db_config(@l_config_elements)
    fetch_fed_config(@l_fed_elements)

    # Get remote configuration
    r_credentials = ssh("cat #{ONE_AUTH}").stdout.gsub("\n", '')
    r_endpoint    = "http://#{server}:2633/RPC2"
    remote_client = Client.new(r_credentials, r_endpoint)

    @r_config = System.new(remote_client).get_configuration
    @r_config_elements = { :raw => @r_config }
    @r_fed_elements    = { :raw => @r_config }

    if OpenNebula.is_error?(@r_config)
        STDERR.puts 'Unable to read remote OpenNebula configuration. ' \
                    "Is OpenNebula running on #{@remote_server}?"
        exit(-1)
    end

    fetch_db_config(@r_config_elements)
    fetch_fed_config(@r_fed_elements)

    # Set OpenNebula services to not restart
    @opennebula_services = { 'opennebula'          => false,
                             'opennebula-gate'     => false,
                             'opennebula-flow'     => false }
end

Instance Method Details

#process_files(sync_database) ⇒ Object

Process files and folders

Parameters:

  • sync_database (Boolean)

    True to sync database



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/one_helper/onezone_helper.rb', line 102

def process_files(sync_database)
    # Files to be copied
    copy_onedconf

    FILES.each do |file|
        copy_and_check(file[:name], file[:service])
    end

    # Folders to be copied
    FOLDERS.each do |folder|
        copy_folder(folder[:name], folder[:service])
    end

    restart_services

    # Sync database
    sync_db if sync_database
end