<commit_before>require 'fog/openstack/compute'
require 'fog/openstack/models/compute/server'
require 'fog/aws/compute'
require 'fog/aws/models/compute/flavor'
require 'fog/openstack/models/compute/flavor'
require 'fog/aws/models/compute/image'
require 'fog/openstack/models/compute/image'
require 'fog/aws/models/compute/server'
require 'fog/azure/models/compute/images'
require 'fog/aws/models/compute/images'
require 'fog/openstack/models/compute/images'
require 'fog/azure/models/compute/server'
require 'fog/azure/models/compute/servers'

# open stack client does not provide import_key_pair method
# while aws does
# It is desired that both aws and openstack client provide identical api hence the magic :-)
class Fog::Compute::OpenStack::Real
  def import_key_pair(name, public_key)
    create_key_pair(name, public_key)
  end

  # alias does not work since create_key_pair method is also added using magic
  # alias :import_key_pair :create_key_pair

  # AWS and openstack create_image methods have different signatures...
  def save_template(instance_id, tmpl_name)
    resp = create_image(instance_id, tmpl_name)
    if resp.status == 200
      resp.body['image']['id']
    else
      # TODO raise specific exc
      raise "Failed to save vm #{instance_id} as template"
    end
  end

  def create_tags_for_vm(server_id, tags_map)
    set_metadata('servers', server_id, tags_map)
  end
end

class Fog::Compute::OpenStack::Flavor
  def supported_architectures
    'x86_64'
  end
end

class Fog::Compute::OpenStack::Server

  def image_id
    image['id']
  end

  def task_state
    os_ext_sts_task_state
  end
end

class Fog::Compute::AWS::Real
  def save_template(instance_id, tmpl_name)
    resp = create_image(instance_id, tmpl_name, nil)
    if resp.status == 200
      resp.body['imageId']
    else
      # TODO raise specific exc
      raise "Failed to save vm #{instance_id} as template"
    end
  end
  def reboot_server(server_id)
    reboot_instances([server_id])
  end
  def create_tags_for_vm(server_id, tags_map)
    create_tags(server_id, tags_map)
  end
end

class Fog::Compute::AWS::Server

  def flavor
    # Return a hash with only flavor ID defined (mimics OpenStack behavior)
    # Note: would normally return a Fog::Compute::AWS::Flavor object
    {'id' => flavor_id}
  end

  def name
    tags['Name']
  end

  def task_state
    nil #TODO
  end

  def created
    created_at
  end

  def pause
    raise Air::UnsuportedException, 'Amazon des not support pause action'
  end

  def suspend
    raise Air::UnsuportedException, 'Amazon des not support suspend action'
  end<commit_msg>Corrected class name of the exception<commit_after>require 'fog/openstack/compute'
require 'fog/openstack/models/compute/server'
require 'fog/aws/compute'
require 'fog/aws/models/compute/flavor'
require 'fog/openstack/models/compute/flavor'
require 'fog/aws/models/compute/image'
require 'fog/openstack/models/compute/image'
require 'fog/aws/models/compute/server'
require 'fog/azure/models/compute/images'
require 'fog/aws/models/compute/images'
require 'fog/openstack/models/compute/images'
require 'fog/azure/models/compute/server'
require 'fog/azure/models/compute/servers'

# open stack client does not provide import_key_pair method
# while aws does
# It is desired that both aws and openstack client provide identical api hence the magic :-)
class Fog::Compute::OpenStack::Real
  def import_key_pair(name, public_key)
    create_key_pair(name, public_key)
  end

  # alias does not work since create_key_pair method is also added using magic
  # alias :import_key_pair :create_key_pair

  # AWS and openstack create_image methods have different signatures...
  def save_template(instance_id, tmpl_name)
    resp = create_image(instance_id, tmpl_name)
    if resp.status == 200
      resp.body['image']['id']
    else
      # TODO raise specific exc
      raise "Failed to save vm #{instance_id} as template"
    end
  end

  def create_tags_for_vm(server_id, tags_map)
    set_metadata('servers', server_id, tags_map)
  end
end

class Fog::Compute::OpenStack::Flavor
  def supported_architectures
    'x86_64'
  end
end

class Fog::Compute::OpenStack::Server

  def image_id
    image['id']
  end

  def task_state
    os_ext_sts_task_state
  end
end

class Fog::Compute::AWS::Real
  def save_template(instance_id, tmpl_name)
    resp = create_image(instance_id, tmpl_name, nil)
    if resp.status == 200
      resp.body['imageId']
    else
      # TODO raise specific exc
      raise "Failed to save vm #{instance_id} as template"
    end
  end
  def reboot_server(server_id)
    reboot_instances([server_id])
  end
  def create_tags_for_vm(server_id, tags_map)
    create_tags(server_id, tags_map)
  end
end

class Fog::Compute::AWS::Server

  def flavor
    # Return a hash with only flavor ID defined (mimics OpenStack behavior)
    # Note: would normally return a Fog::Compute::AWS::Flavor object
    {'id' => flavor_id}
  end

  def name
    tags['Name']
  end

  def task_state
    nil #TODO
  end

  def created
    created_at
  end

  def pause
    raise Atmosphere::UnsupportedException, 'Amazon des not support pause action'
  end

  def suspend
    raise Atmosphere::UnsupportedException, 'Amazon des not support suspend action'
  end
{'fraction_non_alphanumeric': 0.08849221420432966, 'fraction_numerical': 0.0037979491074819596, 'mean_word_length': 4.093810444874275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3305194', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1718, 'n_words': 470}