Module: Yast::PartitioningAutoPartCreateInclude

Defined in:
../../src/include/partitioning/auto_part_create.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) create_partitions(tgmap, disk, partitions)



45
46
47
48
49
50
51
52
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File '../../src/include/partitioning/auto_part_create.rb', line 45

def create_partitions(tgmap, disk, partitions)
  tgmap = deep_copy(tgmap)
  disk = deep_copy(disk)
  partitions = deep_copy(partitions)
  Builtins.y2milestone(
    "create_partitions disk:%1",
    Builtins.haskey(disk, "partitions") ?
      Builtins.remove(disk, "partitions") :
      disk
  )
  Builtins.y2milestone("create_partitions partitions %1", partitions)
  StorageProposal.flex_init_swapable(tgmap)
  ret = false
  has_flex = StorageProposal.has_flex_proposal
  vm = StorageProposal.GetProposalVM
  Builtins.y2milestone("create_partitions flex %1 vm %2", has_flex, vm)
  Ops.set(disk, "partitions", partitions)
  if StorageProposal.NeedNewDisklabel(disk)
    Ops.set(tgmap, [Ops.get_string(disk, "device", ""), "disklabel"], "gpt")
    Ops.set(tgmap, [Ops.get_string(disk, "device", ""), "del_ptable"], true)
  end
  keep = Builtins.find(partitions) do |p|
    !Ops.get_boolean(p, "delete", false) &&
      Ops.get_symbol(p, "type", :unknown) != :free
  end
  if Builtins.size(vm) == 0
    if has_flex
      flex = StorageProposal.do_flexible_disk(disk)
      if Ops.get_boolean(flex, "ok", false)
        partitions = Ops.get_list(flex, ["disk", "partitions"], [])
      end
    else
      num_del_exist = Builtins.size(Builtins.filter(partitions) do |p|
        Ops.get_symbol(p, "type", :unknown) != :free &&
          Ops.get_boolean(p, "delete", false)
      end)
      num_del_free = Builtins.size(Builtins.filter(partitions) do |p|
        Ops.get_symbol(p, "type", :unknown) == :free &&
          Ops.get_boolean(p, "delete", false)
      end)
      r = StorageProposal.can_swap_reuse(
        Ops.get_string(disk, "device", ""),
        partitions,
        tgmap
      )
      if Builtins.haskey(r, "partitions")
        partitions = Ops.get_list(r, "partitions", [])
      elsif Builtins.haskey(r, "targets")
        tgmap = Ops.get_map(r, "targets", {})
      end

      Builtins.y2milestone(
        "create_partitions num_del_exist %1 num_del_free %2 swap_reuse %3",
        num_del_exist,
        num_del_free,
        Ops.greater_than(Builtins.size(r), 0)
      )
      Builtins.y2milestone("create_partitions keep %1", keep)
      if keep != nil && Ops.greater_than(Builtins.size(r), 0) &&
          !StorageProposal.GetProposalHome &&
          !StorageProposal.GetProposalSnapshots &&
          num_del_exist == 1 &&
          num_del_free == 0
        Builtins.y2milestone("create_partitions single special")
        first = true
        partitions = Builtins.maplist(partitions) do |p|
          if Ops.get_boolean(p, "delete", false) && first
            p = Builtins.remove(p, "delete")
            first = false
            p = Storage.SetVolOptions(
              p,
              "/",
              Partitions.DefaultFs,
              "",
              "",
              ""
            )
            Builtins.y2milestone("create_partitions single p %1", p)
          end
          deep_copy(p)
        end
      else
        have_swap = Ops.greater_than(Builtins.size(r), 0) &&
          !StorageProposal.GetProposalSuspend
        partitions = StorageProposal.get_proposal(have_swap, disk)
      end
    end
    Builtins.y2milestone("create_partitions %1", partitions)
  else
    id_save = {}
    Ops.set(
      disk,
      "partitions",
      Builtins.maplist(Ops.get_list(disk, "partitions", [])) do |p|
        if !Ops.get_boolean(p, "delete", false) &&
            Ops.get_symbol(p, "type", :unknown) != :free &&
            Ops.get_symbol(p, "type", :unknown) != :extended
          Ops.set(
            id_save,
            Ops.get_string(p, "device", ""),
            Ops.get_integer(p, "fsid", 0)
          )
          Ops.set(p, "fsid", Partitions.fsid_hibernation)
        end
        deep_copy(p)
      end
    )
    Builtins.y2milestone("create_partitions id_save %1", id_save)
    Builtins.y2milestone(
      "create_partitions ps %1",
      Ops.get_list(disk, "partitions", [])
    )
    r = StorageProposal.get_proposal_vm(tgmap, vm, disk)
    ret = Ops.get_boolean(r, "ok", false)
    if ret
      ddev = Ops.get_string(disk, "device", "")
      tgmap = Ops.get_map(r, "target", {})
      Ops.set(
        tgmap,
        [ddev, "partitions"],
        Builtins.maplist(Ops.get_list(tgmap, [ddev, "partitions"], [])) do |p|
          if Builtins.haskey(id_save, Ops.get_string(p, "device", ""))
            Ops.set(
              p,
              "fsid",
              Ops.get_integer(id_save, Ops.get_string(p, "device", ""), 0)
            )
          end
          deep_copy(p)
        end
      )
      Builtins.y2milestone(
        "create_partitions ps %1",
        Ops.get_list(tgmap, [ddev, "partitions"], [])
      )
    end
  end
  keep = Builtins.find(partitions) do |p|
    !Ops.get_boolean(p, "delete", false) &&
      !Ops.get_boolean(p, "create", false)
  end
  partitions = Builtins.filter(partitions) do |p|
    Ops.get_symbol(p, "type", :unknown) != :free
  end
  Builtins.y2milestone("create_partitions keep %1", keep)
  if Builtins.size(vm) == 0
    ret = Ops.greater_than(Builtins.size(partitions), 0)
    if ret
      Ops.set(
        tgmap,
        [Ops.get_string(disk, "device", ""), "partitions"],
        partitions
      )
      tgmap = Storage.SpecialBootHandling(tgmap)
    end
  end
  if ret
    Storage.SetTargetMap(tgmap)
    Storage.AddMountPointsForWin(tgmap)
  end
  Builtins.y2milestone("create_partitions ret %1", ret)
  ret
end

- (Object) initialize_partitioning_auto_part_create(include_target)



37
38
39
40
41
42
43
# File '../../src/include/partitioning/auto_part_create.rb', line 37

def initialize_partitioning_auto_part_create(include_target)
  textdomain "storage"

  Yast.import "Storage"
  Yast.import "Partitions"
  Yast.import "StorageProposal"
end