def determine_remotely
      # Remove password field from URI, as libvirt doesn't support it directly. We can use it for passphrase if needed.
      lv_uri = URI::Generic.build(:scheme => @connection_uri.scheme, :userinfo => @connection_uri.user,
                                  :host => @connection_uri.host, :path => @connection_uri.path,
                                  :query => @connection_uri.query)

      # The authentication only pertains to libvirtd itself and _not_ the transport (e.g. SSH).
      conn = Libvirt::open_auth(lv_uri.to_s, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) do |cred|
        case cred["type"]
          when Libvirt::CRED_AUTHNAME
            @connection_uri.user
          when Libvirt::CRED_PASSPHRASE
            @connection_uri.password
        end
      end

      if dom = get_existing_domain(conn, @appliance_name)
        unless @overwrite
          @log.fatal("A domain already exists with the name #{@appliance_name}. Set overwrite:true to automatically destroy and undefine it.")
          raise RuntimeError, "Domain '#{@appliance_name}' already exists"  #Make better specific exception
        end
        @log.info("Undefining existing domain #{@appliance_name}")
        undefine_domain(dom)
      end

      guest = @libvirt_capabilities.determine_capabilities(conn, @previous_plugin_info)

      raise "Remote libvirt machine offered no viable guests!" if guest.nil?

      xml = generate_xml(guest)
      @log.info("Defining domain #{@appliance_name}")
      conn.define_domain_xml(xml)
      xml
    ensure
      if conn
        conn.close unless conn.closed?
      end
    end
def determine_remotely
      # Remove password field from URI, as libvirt doesn't support it directly. We can use it for passphrase if needed.
      lv_uri = URI::Generic.build(:scheme => @connection_uri.scheme, :userinfo => @connection_uri.user,
                                  :host => @connection_uri.host, :path => @connection_uri.path,
                                  :query => @connection_uri.query)

      # The authentication only pertains to libvirtd itself and _not_ the transport (e.g. SSH).
      conn = Libvirt::open_auth(lv_uri.to_s, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) do |cred|
        case cred["type"]
          when Libvirt::CRED_AUTHNAME
            @connection_uri.user
          when Libvirt::CRED_PASSPHRASE
            @connection_uri.password
        end
      end

      if dom = get_existing_domain(conn, @appliance_name)
        unless @overwrite
          @log.fatal("A domain already exists with the name #{@appliance_name}. Set overwrite:true to automatically destroy and undefine it.")
          raise RuntimeError, "Domain '#{@appliance_name}' already exists"  #Make better specific exception
        end
        @log.info("Undefining existing domain #{@appliance_name}")
        undefine_domain(dom)
      end

      guest = @libvirt_capabilities.determine_capabilities(conn, @previous_plugin_info)

      raise "Remote libvirt machine offered no viable guests!" if guest.nil?

      xml = generate_xml(guest)
      @log.info("Defining domain #{@appliance_name}")
      conn.define_domain_xml(xml)
      xml
    ensure
      if conn
        conn.close unless conn.closed?
      end
    end
Interact with a libvirtd, attempt to determine optimal settings where possible.
 Register the appliance as a new domain.