partition_device

in cookbooks/fb_storage/libraries/storage_handlers.rb [107:166]


      def partition_device(device_config)
        Chef::Log.info(
          "fb_storage: Writing gpt table to #{@device}",
        )
        Mixlib::ShellOut.new("/sbin/parted -s '#{@device}' mklabel gpt").
          run_command.error!
        return if device_config['whole_device']

        parted_commands = []
        sfdisk_commands = []
        device_config['partitions'].each_with_index do |partinfo, partindex|
          partnum = partindex + 1

          if partinfo['partition_start']
            parted_commands <<
              "mkpart primary #{partinfo['partition_start']} " +
                "#{partinfo['partition_end']} -a optimal " +
                "set #{partnum} boot off"
          else
            parted_commands << 'mkpart primary 0% 100% set 1 boot off'
          end
          if partinfo['_swraid_array'] || partinfo['_swraid_array_journal']
            parted_commands << "set #{partnum} raid on"
          end
          if partinfo['part_name']
            parted_commands << "name #{partnum} '\"#{partinfo['part_name']}\"'"
          end
          if partinfo['part_type']
            sfdisk_commands <<
              "sfdisk #{@device} #{partnum} " +
                "--part-type #{partinfo['part_type']}"
          end
        end

        Chef::Log.info("fb_storage: Partitioning #{@device}")
        cmd = "/sbin/parted -s '#{@device}' #{parted_commands.join(' ')}"
        Chef::Log.debug("fb_storage: Running #{cmd}")
        Mixlib::ShellOut.new(cmd).run_command.error!
        
        pname = partition_device_name(1)
        Chef::Log.debug("fb_storage: Polling for #{pname} to exist")
        max_seconds_to_wait = 5
        until File.exist?(pname)
          if max_seconds_to_wait.zero?
            fail 'fb_storage: Made partitions, but partition' +
              " #{pname} never showed up. :("
          end
          Chef::Log.info(
            "fb_storage: Waiting for #{pname} to show up...",
          )
          sleep(1)
          max_seconds_to_wait -= 1
        end

        sfdisk_commands.each do |sfdisk_cmd|
          Chef::Log.debug("fb_storage: Running #{sfdisk_cmd}")
          Mixlib::ShellOut.new(sfdisk_cmd).run_command.error!
        end
      end