{"record":{"id":"fe0eff443edb41f2","repo":"theforeman/foreman","slug":"no-unused-port-found","errorCode":null,"errorMessage":"no unused port found","messagePattern":"no unused port found","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/models/compute_resources/foreman/model/vmware.rb","lineNumber":812,"sourceCode":"      case e.message\n      when /The remote system presented a public key with hash (\\w+) but we're expecting a hash of/\n        raise Foreman::FingerprintException.new(\n          N_(\"The remote system presented a public key with hash %s but we're expecting a different hash. If you are sure the remote system is authentic, go to the compute resource edit page, press the 'Test Connection' or 'Load Datacenters' button and submit\"), Regexp.last_match(1))\n      when /Cannot complete login due to an incorrect user name or password./\n        raise Foreman::UsernameOrPasswordException.new(\n          N_(\"Can not load datacenters due to an incorrect user name or password.\"))\n      else\n        raise e\n      end\n    end\n\n    def unused_vnc_port(ip)\n      10.times do\n        port   = rand(5901..5964)\n        unused = (TCPSocket.connect(ip, port).close rescue true)\n        return port if unused\n      end\n      raise \"no unused port found\"\n    end\n\n    def vm_instance_defaults\n      super.merge(\n        :memory_mb  => 2048,\n        :interfaces => [new_interface],\n        :volumes    => [new_volume],\n        :scsi_controllers => [{ :type => scsi_controller_default_type }],\n        :nvme_controllers => [],\n        :datacenter => datacenter,\n        :firmware => 'automatic',\n        :boot_order => ['network', 'disk']\n      )\n    end\n\n    def set_vm_volumes_attributes(vm, vm_attrs)\n      volumes = vm.volumes || []\n      vm_attrs[:volumes_attributes] = Hash[volumes.each_with_index.map { |volume, idx| [idx.to_s, volume.attributes.merge(:size_gb => volume.size_gb)] }]","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/theforeman/foreman/blob/6b05625475cfe6aac31a88f8c8ee6e62e4efe620/app/models/compute_resources/foreman/model/vmware.rb#L794-L830","documentation":"Error \"no unused port found\" thrown in theforeman/foreman.","triggerScenarios":"Thrown at app/models/compute_resources/foreman/model/vmware.rb:812 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6b05625475cfe6aac31a88f8c8ee6e62e4efe620","analyzedAt":"2026-08-23T17:46:34.094Z","schemaVersion":2},"datasetVersion":"2026-08-23T21:17:23.414Z"}