<commit_before>module MiqProvisionOpenstack::Cloning
  def do_clone_task_check(clone_task_ref)
    self.source.with_provider_connection do |openstack|
      instance = openstack.servers.detect { |s| s.id == clone_task_ref}
      status   = instance.state.downcase.to_sym

      return true if status == :active
      return false, status
    end
  end

  def prepare_for_clone_task
    clone_options = super

    clone_options[:name]              = dest_name
    clone_options[:image_ref]         = self.source.ems_ref
    clone_options[:flavor_ref]        = instance_type.ems_ref
    clone_options[:availability_zone] = nil if dest_availability_zone.kind_of?(AvailabilityZoneOpenstackNull)
    clone_options[:security_groups]   = security_groups.collect(&:name)
    clone_options[:nics]              = configure_network_adapters unless configure_network_adapters.blank?

    clone_options
  end

  def log_clone_options(clone_options)
    log_header = "MIQ(#{self.class.name}#log_clone_options)"

    $log.info("#{log_header} Provisioning [#{self.source.name}] to [#{clone_options[:name]}]")
    $log.info("#{log_header} Source Image:                    [#{clone_options[:image_ref]}]")
    $log.info("#{log_header} Destination Availability Zone:   [#{clone_options[:availability_zone]}]")
    $log.info("#{log_header} Flavor:                          [#{clone_options[:flavor_ref]}]")
    $log.info("#{log_header} Guest Access Key Pair:           [#{clone_options[:key_name]}]")
    $log.info("#{log_header} Security Group:                  [#{clone_options[:security_groups]}]")
    $log.info("#{log_header} Network:                         [#{clone_options[:nics]}]")

    self.dumpObj(clone_options, "#{log_header} Clone Options: ", $log, :info)
    self.dumpObj(self.options,  "#{log_header} Prov Options:  ", $log, :info)
  end

  def start_clone(clone_options)
    self.source.with_provider_connection do |openstack|
      instance = openstack.servers.create(clone_options)
      return instance.id
    end
  end
end
<commit_msg>Use tenant in openstack provisioning<commit_after>module MiqProvisionOpenstack::Cloning
  def do_clone_task_check(clone_task_ref)
    self.source.with_provider_connection do |openstack|
      instance = openstack.servers.detect { |s| s.id == clone_task_ref}
      status   = instance.state.downcase.to_sym

      return true if status == :active
      return false, status
    end
  end

  def prepare_for_clone_task
    clone_options = super

    clone_options[:name]              = dest_name
    clone_options[:image_ref]         = self.source.ems_ref
    clone_options[:flavor_ref]        = instance_type.ems_ref
    clone_options[:availability_zone] = nil if dest_availability_zone.kind_of?(AvailabilityZoneOpenstackNull)
    clone_options[:security_groups]   = security_groups.collect(&:name)
    clone_options[:nics]              = configure_network_adapters unless configure_network_adapters.blank?

    clone_options
  end

  def log_clone_options(clone_options)
    log_header = "MIQ(#{self.class.name}#log_clone_options)"

    $log.info("#{log_header} Provisioning [#{self.source.name}] to [#{clone_options[:name]}]")
    $log.info("#{log_header} Source Image:                    [#{clone_options[:image_ref]}]")
    $log.info("#{log_header} Destination Availability Zone:   [#{clone_options[:availability_zone]}]")
    $log.info("#{log_header} Flavor:                          [#{clone_options[:flavor_ref]}]")
    $log.info("#{log_header} Guest Access Key Pair:           [#{clone_options[:key_name]}]")
    $log.info("#{log_header} Security Group:                  [#{clone_options[:security_groups]}]")
    $log.info("#{log_header} Network:                         [#{clone_options[:nics]}]")

    self.dumpObj(clone_options, "#{log_header} Clone Options: ", $log, :info)
    self.dumpObj(self.options,  "#{log_header} Prov Options:  ", $log, :info)
  end

  def start_clone(clone_options)
    connection_options = {:tenant_name => options[:cloud_tenant][1]} if options[:cloud_tenant].is_a? Array
    self.source.with_provider_connection(connection_options) do |openstack|
      instance = openstack.servers.create(clone_options)
      return instance.id
    end
  end
end

{'fraction_non_alphanumeric': 0.12452651515151515, 'fraction_numerical': 0.00023674242424242425, 'mean_word_length': 3.642857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6074798', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1315, 'n_words': 220}