You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: system_console.rb
    path of file: ./repos/manageiq/app/models
    
    the code of the file until where you have to start completion: class SystemConsole < ApplicationRecord
  belongs_to :vm
  belongs_to :user

  default_value_for :opened, false

  validates :url_secret, :uniqueness_when_changed => true

  def connection_params
    {
      :url    => "ws/console/#{url_secret}",
      :secret => secret,
      :proto  => protocol
    }
  end

  def destroy_or_mark
    if proxy_pid.nil?
      destroy
      return
    end
    update(:proxy_status => 'websocket_closed')
    SystemConsole.cleanup_proxy_processes
  end

  def self.allocate_port
    port_range_start = ::Settings.server.console_proxy_port.start
    port_range_end   = ::Settings.server.console_proxy_port.end

    used_ports = SystemConsole.where.not(:proxy_pid => nil).where(:host_name => local_address).order(:port).pluck(:port).uniq

  
    
  def self.launch_proxy_if_not_local(console_args, originating_server, host_address, host_port)
    _log.info("Originating server: #{originating_server}, local server: #{MiqServer.my_server.id}")

    if ::Settings.server.console_proxy_disabled || SystemConsole.is_local?(originating_server)
      console_args.update(
        :host_name  => host_address,
        :port       => host_port
      )
    else
      SystemConsole.cleanup_proxy_processes
      proxy_address, proxy_port, proxy_pid = SystemConsole.launch_proxy(host_address, host_port)
      return nil if proxy_address.nil?

      _log.info("Proxy server started: #{proxy_address}:#{proxy_port} <--> #{host_address}:#{host_port}")
      _log.info("Proxy process PID: #{proxy_pid}")

      console_args.update(
        :host_name    => proxy_address,
        :port         => proxy_port,
        :proxy_status => 'proxy_running',
        :proxy_pid    => proxy_pid
      )
    end