Revision cb30f922 src/onedb/3.8.1_to_3.9.80.rb

View differences:

src/onedb/3.8.1_to_3.9.80.rb
112 112
        @db.run("DROP TABLE image_pool")
113 113
        @db.run("ALTER TABLE image_pool_new RENAME TO image_pool")
114 114

  
115
        ########################################################################
116
        # Feature #1617
117
        # New datastore, 2 "files"
118
        # DATASTORE/SYSTEM is now DATASTORE/TYPE
119
        ########################################################################
120

  
121
        @db.run "ALTER TABLE datastore_pool RENAME TO old_datastore_pool;"
122
        @db.run "CREATE TABLE datastore_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
123

  
124
        @db.fetch("SELECT * FROM old_datastore_pool") do |row|
125
            doc = Document.new(row[:body])
126

  
127
            type = "0"  # IMAGE_DS
128

  
129
            system_elem = doc.root.delete_element("SYSTEM")
130

  
131
            if ( !system_elem.nil? && system_elem.text == "1" )
132
                type = "1"  # SYSTEM_DS
133
            end
134

  
135
            doc.root.add_element("TYPE").text = type
136

  
137
            doc.root.each_element("TEMPLATE") do |e|
138
                e.delete_element("SYSTEM")
139
                e.add_element("TYPE").text = type == "0" ? "IMAGE_DS" : "SYSTEM_DS"
140
            end
141

  
142
            @db[:datastore_pool].insert(
143
                :oid        => row[:oid],
144
                :name       => row[:name],
145
                :body       => doc.root.to_s,
146
                :uid        => row[:uid],
147
                :gid        => row[:gid],
148
                :owner_u    => row[:owner_u],
149
                :group_u    => row[:group_u],
150
                :other_u    => row[:other_u])
151
        end
152

  
153
        @db.run "DROP TABLE old_datastore_pool;"
154

  
155

  
156
        user_0_name = "oneadmin"
157

  
158
        @db.fetch("SELECT name FROM user_pool WHERE oid=0") do |row|
159
            user_0_name = row[:name]
160
        end
161

  
162
        group_0_name = "oneadmin"
163

  
164
        @db.fetch("SELECT name FROM group_pool WHERE oid=0") do |row|
165
            group_0_name = row[:name]
166
        end
167

  
168
        base_path = "/var/lib/one/datastores/2"
169

  
170
        @db.fetch("SELECT body FROM datastore_pool WHERE oid=0") do |row|
171
            doc = Document.new(row[:body])
172

  
173
            doc.root.each_element("BASE_PATH") do |e|
174
                base_path = e.text
175
                base_path[-1] = "2"
176
            end
177
        end
178

  
179
        @db.run "INSERT INTO datastore_pool VALUES(2,'files','<DATASTORE><ID>2</ID><UID>0</UID><GID>0</GID><UNAME>#{user_0_name}</UNAME><GNAME>#{group_0_name}</GNAME><NAME>files</NAME><PERMISSIONS><OWNER_U>1</OWNER_U><OWNER_M>1</OWNER_M><OWNER_A>0</OWNER_A><GROUP_U>1</GROUP_U><GROUP_M>0</GROUP_M><GROUP_A>0</GROUP_A><OTHER_U>1</OTHER_U><OTHER_M>0</OTHER_M><OTHER_A>0</OTHER_A></PERMISSIONS><DS_MAD>fs</DS_MAD><TM_MAD>ssh</TM_MAD><BASE_PATH>#{base_path}</BASE_PATH><TYPE>2</TYPE><DISK_TYPE>0</DISK_TYPE><CLUSTER_ID>-1</CLUSTER_ID><CLUSTER></CLUSTER><IMAGES></IMAGES><TEMPLATE><DS_MAD><![CDATA[fs]]></DS_MAD><TM_MAD><![CDATA[ssh]]></TM_MAD><TYPE><![CDATA[FILE_DS]]></TYPE></TEMPLATE></DATASTORE>',0,0,1,1,1);"
180

  
115 181

  
116 182
        ########################################################################
117 183
        # Feature #1611: Default quotas

Also available in: Unified diff