Statistics
| Branch: | Tag: | Revision:

one / src / onedb / fsck / cluster_vnc_bitmap.rb @ c4662c0b

History | View | Annotate | Download (1.27 KB)

1

    
2
module OneDBFsck
3
    def check_cluster_vnc_bitmap
4
        fixes = @fixes_cluster_vnc_bitmap = {}
5
        cluster_vnc = @data_vm[:vnc]
6

    
7
        vnc_pool_size = 65536
8

    
9
        @db.fetch("SELECT * FROM cluster_pool") do |row|
10
            cluster_id = row[:oid]
11

    
12
            if cluster_vnc[cluster_id]
13
                map = ""
14
                vnc_pool_size.times.each do |i|
15
                    map << (cluster_vnc[cluster_id].include?(vnc_pool_size - 1 - i) ? "1" : "0")
16
                end
17

    
18
                map_encoded = Base64::strict_encode64(Zlib::Deflate.deflate(map))
19
            else
20
                map_encoded = "eJztwYEAAAAAgCCl/ekWqQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABqFo8C0Q=="
21
            end
22

    
23
            old_map_encoded = @db[:cluster_vnc_bitmap].first(:id => cluster_id)[:map] rescue nil
24

    
25
            if old_map_encoded != map_encoded
26
                log_error("Cluster #{cluster_id} has not the proper reserved VNC ports")
27
                fixes[cluster_id] = map_encoded
28
            end
29
        end
30
    end
31

    
32
    def fix_cluster_vnc_bitmap
33
        @db.transaction do
34
            @fixes_cluster_vnc_bitmap.each do |id, map|
35
                @db[:cluster_vnc_bitmap].where(id: id).update(map: map)
36
            end
37
        end
38
    end
39
end
40