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 =
%w[MODE ZONE_ID SERVER_ID MASTER_ONED]
FILES =
[
    { :name    => 'az_driver.conf',
      :service => 'opennebula' },
    { :name    => 'az_driver.default',
      :service => 'opennebula' },
    { :name    => 'ec2_driver.conf',
      :service => 'opennebula' },
    { :name    => 'ec2_driver.default',
      :service => 'opennebula' },
    { :name    => 'monitord.conf',
      :service => 'opennebula' },
    { :name    => 'oneflow-server.conf',
      :service => 'opennebula-flow' },
    { :name    => 'onegate-server.conf',
      :service => 'opennebula-gate' },
    { :name    => 'sched.conf',
      :service => 'opennebula' },
    { :name    => 'sunstone-logos.yaml',
      :service => 'opennebula-sunstone' },
    { :name    => 'sunstone-server.conf',
      :service => 'opennebula-sunstone' },
    { :name    => 'vcenter_driver.default',
      :service => 'opennebula' }
]
FOLDERS =
[
    { :name => 'sunstone-views', :service => 'opennebula-sunstone' },
    { :name => 'auth', :service => 'opennebula' },
    { :name => 'hm', :service => 'opennebula' },
    { :name => 'sunstone-views', :service => 'opennebula' },
    { :name => 'vmm_exec', :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



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
98
99
100
101
102
103
104
105
106
# File 'lib/one_helper/onezone_helper.rb', line 67

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 = OpenNebula::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 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 = OpenNebula::System.new(remote_client).get_configuration
    @r_config_elements = { :raw => @r_config }
    @r_fed_elements    = { :raw => @r_config }

    fetch_db_config(@r_config_elements)
    fetch_fed_config(@r_fed_elements)

    # Set OpenNebula services to not restart
    @opennebula_services = { 'opennebula'          => false,
                             'opennebula-sunstone' => 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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/one_helper/onezone_helper.rb', line 111

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