<commit_before>require 'ostruct'
require 'cgi'
require 'uri'

class VmOrTemplate < ApplicationRecord
  include NewWithTypeStiMixin
  include RetirementMixin
  include ScanningMixin
  include SupportsFeatureMixin

  self.table_name = 'vms'

  include_concern 'Operations'
  include_concern 'RetirementManagement'
  include_concern 'RightSizing'
  include_concern 'Scanning'
  include_concern 'Snapshotting'

  attr_accessor :surrogate_host
  @surrogate_host = nil

  include ProviderObjectMixin
  include ComplianceMixin
  include OwnershipMixin
  include CustomAttributeMixin

  include EventMixin
  include ProcessTasksMixin
  include TenancyMixin

  include AvailabilityMixin
  include ManageIQ::Providers::Inflector::Methods

  VENDOR_TYPES = {
    # DB            Displayed
    "azure"       => "Azure",
    "azure_stack" => "AzureStack",
    "vmware"      => "VMware",
    "microsoft"   => "Microsoft",
    "xen"         => "XenSource",
    "parallels"   => "Parallels",
    "amazon"      => "Amazon",
    "redhat"      => "RedHat",
    "openstack"   => "OpenStack",
    "google"      => "Google",
    "kubevirt"    => "KubeVirt",
    "unknown"     => "Unknown"
  }

  POWER_OPS = %w(start stop suspend reset shutdown_guest standby_guest reboot_guest)
  REMOTE_REGION_TASKS = POWER_OPS + %w(retire_now)

  validates_presence_of     :name, :location
  validates                 :vendor, :inclusion => {:in => VENDOR_TYPES.keys}

  has_one                   :operating_system, :dependent => :destroy
  has_one                   :openscap_result, :as => :resource, :dependent => :destroy
  has_one                   :hardware, :dependent => :destroy
  has_one                   :miq_provision, :dependent => :nullify, :as => :destination
  has_one                   :miq_provision_template, :through => "miq_provision", :source => "source", :source_type => "VmOrTemplate"
  has_one                   :miq_server, :foreign_key => :vm_id, :inverse_of => :vm
  has_one                   :conversion_host, :as => :resource, :dependent => :destroy, :inverse_of => :resource

  belongs_to                :host
  belongs_to                :ems_cluster
  belongs_to                :flavor

  belongs_to                :storage
  belongs_to                :storage_profile
  belongs_to                :ext_management_system, :foreign_key => "ems_id"
  belongs_to                :resource_group
  belongs_to                :tenant

  # Accounts - Users and Groups
  has_many                  :accounts, :dependent => :destroy
  has_many                  :users, -> { where(:accttype => 'user') }, :class_name => "Account"
  has_many                  :groups, -> { where(:accttype => 'group') }, :class_name => "Account"
  has_many                  :disks, :through => :hardware
  has_many                  :networks, :through => :hardware
  has_many                  :nics, :through => :hardware
  has_many                  :miq_provisions_from_template, :class_name => "MiqProvision", :as => :source, :dependent => :nullify
  has_many                  :miq_provision_vms, :through => :miq_provisions_from_template, :source => :destination, :source_type => "VmOrTemplate"
  has_many                  :miq_provision_requests, :as => :source
  has_many                  :guest_applications, :dependent => :destroy
  has_many                  :patches, :dependent => :destroy<commit_msg>Add CloudTenant relationship in VM class<commit_after>require 'ostruct'
require 'cgi'
require 'uri'

class VmOrTemplate < ApplicationRecord
  include NewWithTypeStiMixin
  include RetirementMixin
  include ScanningMixin
  include SupportsFeatureMixin

  self.table_name = 'vms'

  include_concern 'Operations'
  include_concern 'RetirementManagement'
  include_concern 'RightSizing'
  include_concern 'Scanning'
  include_concern 'Snapshotting'

  attr_accessor :surrogate_host
  @surrogate_host = nil

  include ProviderObjectMixin
  include ComplianceMixin
  include OwnershipMixin
  include CustomAttributeMixin

  include EventMixin
  include ProcessTasksMixin
  include TenancyMixin

  include AvailabilityMixin
  include ManageIQ::Providers::Inflector::Methods

  VENDOR_TYPES = {
    # DB            Displayed
    "azure"       => "Azure",
    "azure_stack" => "AzureStack",
    "vmware"      => "VMware",
    "microsoft"   => "Microsoft",
    "xen"         => "XenSource",
    "parallels"   => "Parallels",
    "amazon"      => "Amazon",
    "redhat"      => "RedHat",
    "openstack"   => "OpenStack",
    "google"      => "Google",
    "kubevirt"    => "KubeVirt",
    "unknown"     => "Unknown"
  }

  POWER_OPS = %w(start stop suspend reset shutdown_guest standby_guest reboot_guest)
  REMOTE_REGION_TASKS = POWER_OPS + %w(retire_now)

  validates_presence_of     :name, :location
  validates                 :vendor, :inclusion => {:in => VENDOR_TYPES.keys}

  has_one                   :operating_system, :dependent => :destroy
  has_one                   :openscap_result, :as => :resource, :dependent => :destroy
  has_one                   :hardware, :dependent => :destroy
  has_one                   :miq_provision, :dependent => :nullify, :as => :destination
  has_one                   :miq_provision_template, :through => "miq_provision", :source => "source", :source_type => "VmOrTemplate"
  has_one                   :miq_server, :foreign_key => :vm_id, :inverse_of => :vm
  has_one                   :conversion_host, :as => :resource, :dependent => :destroy, :inverse_of => :resource

  belongs_to                :host
  belongs_to                :ems_cluster
  belongs_to                :cloud_tenant
  belongs_to                :flavor

  belongs_to                :storage
  belongs_to                :storage_profile
  belongs_to                :ext_management_system, :foreign_key => "ems_id"
  belongs_to                :resource_group
  belongs_to                :tenant

  # Accounts - Users and Groups
  has_many                  :accounts, :dependent => :destroy
  has_many                  :users, -> { where(:accttype => 'user') }, :class_name => "Account"
  has_many                  :groups, -> { where(:accttype => 'group') }, :class_name => "Account"
  has_many                  :disks, :through => :hardware
  has_many                  :networks, :through => :hardware
  has_many                  :nics, :through => :hardware
  has_many                  :miq_provisions_from_template, :class_name => "MiqProvision", :as => :source, :dependent => :nullify
  has_many                  :miq_provision_vms, :through => :miq_provisions_from_template, :source => :destination, :source_type => "VmOrTemplate"
  has_many                  :miq_provision_requests, :as => :source
  has_many                  :guest_applications, :dependent => :destroy
  has_many                  :patches, :dependent => :destroy
{'fraction_non_alphanumeric': 0.1036504911303328, 'fraction_numerical': 0.0, 'mean_word_length': 2.4717557251908397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '4249916', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2061, 'n_words': 440}