
The upstream pip provider hard-codes pypi.python.org as the index to search when determining the latest available release of a package. This means puppet won't use our mirrors on the second run of a pip package resource using ensure => latest. This patch adds a new provider that inherits from the upstream one and overrides the latest() method to just use `pip list --outdated` to see what the latest version is. This could potentially be proposed upstream in the future depending on what versions of pip support 'list --outdated' and what systems require support. To use this, package resources currently using the 'pip' provider will have to switch to the 'openstack_pip' provider. Change-Id: I6c24c8f99fb3f879a30d21f38d1ad883f96f7937
30 lines
725 B
Ruby
30 lines
725 B
Ruby
require 'puppet/provider/package'
|
|
require 'net/http'
|
|
require 'xmlrpc/client'
|
|
require 'puppet/util/http_proxy'
|
|
|
|
Puppet::Type.type(:package).provide(:openstack_pip, :parent => :pip) do
|
|
|
|
desc "Python packages via `pip` with mirrors."
|
|
|
|
commands :pip => 'pip'
|
|
|
|
def self.outdated
|
|
@outdated ||= pip(['list', '--outdated'])
|
|
end
|
|
|
|
def latest
|
|
outdated = self.class.outdated
|
|
if outdated =~ /#{@resource[:name]}/
|
|
latest = outdated.split('-')[1].match('Latest: (.*) ')[1]
|
|
else
|
|
package_info = lazy_pip(['show', @resource[:name]])
|
|
current = package_info.split("\n").select { |line|
|
|
line =~ /^Version/
|
|
}.first.split(': ')[1]
|
|
latest = current
|
|
end
|
|
return latest
|
|
end
|
|
end
|