Statistics
| Branch: | Tag: | Revision:

one / src / onedb / vcenter_one54.rb @ 27e61bae

History | View | Annotate | Download (4.45 KB)

1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

    
17
if !ONE_LOCATION
18
    LOG_LOCATION = "/var/log/one"
19
else
20
    LOG_LOCATION = ONE_LOCATION + "/var"
21
end
22

    
23
LOG     = LOG_LOCATION + "/onedb-vcenter-one54.log"
24
TMP_DIR = "/var/tmp/vcenter_one54"
25

    
26
module One54Vcenter
27
    VERSION = "5.4.0"
28

    
29
    def check_db_version(ops)
30
        db_version = read_db_version()
31

    
32
        if ( db_version[:version] != VERSION )
33

    
34
            raise <<-EOT
35
Version mismatch: vcenter migration is for version #{VERSION}
36

37
Current database is version #{db_version[:version]}
38
EOT
39
        end
40
    end
41

    
42
    def migrate_templates(verbose)
43
        Dir["#{TMP_DIR}/one_migrate_template_*"].each do |template_filename|
44
            template_id = template_filename.split("_")[-1]
45
            template_xml = File.read(template_filename)
46
            @db.run("UPDATE template_pool SET body='#{template_xml}' WHERE oid='#{template_id}'")
47
            puts "    Template #{template_id} migrated!" if verbose
48
        end
49

    
50
        return true
51
    end
52

    
53
    def migrate_vms(verbose)
54
        Dir["#{TMP_DIR}/one_migrate_vm_*"].each do |vm_filename|
55
            vm_id = vm_filename.split("_")[-1]
56
            vm_xml = File.read(vm_filename)
57
            @db.run("UPDATE vm_pool SET body='#{vm_xml}' WHERE oid='#{vm_id}'")
58
            puts "    VM #{vm_id} migrated!" if verbose
59
        end
60

    
61
        return true
62
    end
63

    
64
    def migrate_hosts(verbose)
65
        Dir["#{TMP_DIR}/one_migrate_host_*"].each do |host_filename|
66
            host_id  = host_filename.split("_")[-1]
67
            host_xml = File.read(host_filename)
68
            @db.run("UPDATE host_pool SET body='#{host_xml}' WHERE oid='#{host_id}'")
69
            puts "    Host #{host_id} migrated!" if verbose
70
        end
71

    
72
        return true
73
    end
74

    
75
    def migrate_datastores(verbose)
76
        Dir["#{TMP_DIR}/one_migrate_ds_*"].each do |ds_filename|
77
            ds_id  = ds_filename.split("_")[-1]
78
            ds_xml =  File.read(ds_filename)
79
            @db.run("UPDATE datastore_pool SET body='#{ds_xml}' WHERE oid='#{ds_id}'")
80
            puts "    Datastore #{ds_id} migrated!" if verbose
81
        end
82

    
83
        return true
84
    end
85

    
86
    def migrate_vnets(verbose)
87
        Dir["#{TMP_DIR}/one_migrate_vnet_*"].each do |vnet_filename|
88
            vnet_id  = vnet_filename.split("_")[-1]
89
            vnet_xml = File.read(vnet_filename)
90
            @db.run("UPDATE network_pool SET body='#{vnet_xml}' WHERE oid='#{vnet_id}'")
91
            puts "    Network #{vnet_id} migrated!" if verbose
92
        end
93

    
94
        return true
95
    end
96

    
97
    def migrate_images(verbose)
98
        Dir["#{TMP_DIR}/one_migrate_image_*"].each do |image_filename|
99
            image_id  = image_filename.split("_")[-1]
100
            image_xml = File.read(image_filename)
101
            @db.run("UPDATE image_pool SET body='#{image_xml}' WHERE oid='#{image_id}'")
102
            puts "    Image #{image_id} migrated!" if verbose
103
        end
104

    
105
        return true
106
    end
107

    
108
    def migrate_history(verbose)
109
        Dir["#{TMP_DIR}/one_migrate_history_*"].each do |history_filename|
110
            vm_id  = history_filename.split("_")[-2]
111
            seq_id = history_filename.split("_")[-1]
112
            history_xml = File.read(history_filename)
113
            @db.run("UPDATE history SET body='#{history_xml}' WHERE vid='#{vm_id}' and seq='#{seq_id}'")
114
            puts "    History for VM #{vm_id} migrated!" if verbose
115
        end
116

    
117
        return true
118
    end
119
end