mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
* F #2283 Fix parsing MarketPlace proxy string * Fix linting market_mad monitor files
This commit is contained in:
parent
bfa859925e
commit
fbe81b1008
@ -183,8 +183,6 @@ AllCops:
|
|||||||
- src/market_mad/remotes/s3/monitor
|
- src/market_mad/remotes/s3/monitor
|
||||||
- src/market_mad/remotes/s3/delete
|
- src/market_mad/remotes/s3/delete
|
||||||
- src/market_mad/remotes/s3/import
|
- src/market_mad/remotes/s3/import
|
||||||
- src/market_mad/remotes/linuxcontainers/monitor
|
|
||||||
- src/market_mad/remotes/one/monitor
|
|
||||||
- src/tm_mad/vcenter/monitor
|
- src/tm_mad/vcenter/monitor
|
||||||
- src/tm_mad/vcenter/delete
|
- src/tm_mad/vcenter/delete
|
||||||
- src/tm_mad/vcenter/mvds
|
- src/tm_mad/vcenter/mvds
|
||||||
|
@ -67,7 +67,8 @@ CONTEXT = [
|
|||||||
@options.merge!(options)
|
@options.merge!(options)
|
||||||
|
|
||||||
version_path = File.dirname(__FILE__) + '/../../VERSION'
|
version_path = File.dirname(__FILE__) + '/../../VERSION'
|
||||||
@options[:agent] = "OpenNebula #{File.read(version_path)}" if File.exist? version_path
|
@options[:agent] = "OpenNebula #{File.read(version_path)}" \
|
||||||
|
if File.exist? version_path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get container information
|
# Get container information
|
||||||
@ -76,6 +77,9 @@ CONTEXT = [
|
|||||||
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
|
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
|
||||||
|
|
||||||
if http_proxy
|
if http_proxy
|
||||||
|
# prepend 'http' if missing to parse with URI()
|
||||||
|
http_proxy = 'http://' + http_proxy if http_proxy !~ /^http/
|
||||||
|
|
||||||
p_uri = URI(http_proxy)
|
p_uri = URI(http_proxy)
|
||||||
p_host = p_uri.host
|
p_host = p_uri.host
|
||||||
p_port = p_uri.port
|
p_port = p_uri.port
|
||||||
@ -107,7 +111,7 @@ CONTEXT = [
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Get the list of appliances
|
# Get the list of appliances
|
||||||
def get_appliances
|
def fetch_appliances
|
||||||
first_level = '/images/'
|
first_level = '/images/'
|
||||||
|
|
||||||
rc, body = get(first_level)
|
rc, body = get(first_level)
|
||||||
@ -122,11 +126,11 @@ CONTEXT = [
|
|||||||
|
|
||||||
next if rc != 0
|
next if rc != 0
|
||||||
|
|
||||||
version = body.scan(%r{a href="(.*/)">})
|
versions = body.scan(%r{a href="(.*/)">})
|
||||||
version.shift # Remove first entry ("Parent Directory")
|
versions.shift # Remove first entry ("Parent Directory")
|
||||||
|
|
||||||
version_path = {}
|
version_path = {}
|
||||||
version.each do |version|
|
versions.each do |version|
|
||||||
path = "#{first_level}#{distro[0]}#{version[0]}amd64/default/"
|
path = "#{first_level}#{distro[0]}#{version[0]}amd64/default/"
|
||||||
rc, body = get(path)
|
rc, body = get(path)
|
||||||
|
|
||||||
@ -163,12 +167,14 @@ CONTEXT = [
|
|||||||
|
|
||||||
tmpl = ''
|
tmpl = ''
|
||||||
|
|
||||||
data.each {|key, value| print_var(tmpl, key, value) }
|
data.each {|key, val| print_var(tmpl, key, val) }
|
||||||
|
|
||||||
tmpl64 = ''
|
tmpl64 = ''
|
||||||
print_var(tmpl64, 'DRIVER', 'raw')
|
print_var(tmpl64, 'DRIVER', 'raw')
|
||||||
print_var(tmpl, 'APPTEMPLATE64', Base64.strict_encode64(tmpl64))
|
print_var(tmpl, 'APPTEMPLATE64',
|
||||||
print_var(tmpl, 'VMTEMPLATE64', Base64.strict_encode64(TEMPLATE))
|
Base64.strict_encode64(tmpl64))
|
||||||
|
print_var(tmpl, 'VMTEMPLATE64',
|
||||||
|
Base64.strict_encode64(TEMPLATE))
|
||||||
|
|
||||||
appstr << "APP=\"#{Base64.strict_encode64(tmpl)}\"\n"
|
appstr << "APP=\"#{Base64.strict_encode64(tmpl)}\"\n"
|
||||||
end
|
end
|
||||||
@ -187,8 +193,8 @@ CONTEXT = [
|
|||||||
# ./20181214_07:42/rootfs.tar.xz?size=5120&filesystem=ext4&format=raw
|
# ./20181214_07:42/rootfs.tar.xz?size=5120&filesystem=ext4&format=raw
|
||||||
#
|
#
|
||||||
def app_url(path)
|
def app_url(path)
|
||||||
"\\\"lxd://#{@options[:url]}#{path}?size=#{@options[:sizemb]}&filesystem=" \
|
"\\\"lxd://#{@options[:url]}#{path}?size=#{@options[:sizemb]}" \
|
||||||
"#{@options[:fs]}&format=#{@options[:format]}\\\""
|
"&filesystem=#{@options[:fs]}&format=#{@options[:format]}\\\""
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns build date based on image path
|
# Returns build date based on image path
|
||||||
@ -214,8 +220,8 @@ end
|
|||||||
################################################################################
|
################################################################################
|
||||||
# Main Program. Outpust the list of marketplace appliances
|
# Main Program. Outpust the list of marketplace appliances
|
||||||
################################################################################
|
################################################################################
|
||||||
def set_option(o, d, name, path)
|
def set_option(option, doc, name, path)
|
||||||
o[name] = d.elements[path].text if d.elements[path]
|
option[name] = ddoc.elements[path].text if doc.elements[path]
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -230,6 +236,7 @@ begin
|
|||||||
|
|
||||||
data.each {|key, value| set_option(options, doc, key, value) }
|
data.each {|key, value| set_option(options, doc, key, value) }
|
||||||
|
|
||||||
puts LinuxContainersMarket.new(options).get_appliances
|
puts LinuxContainersMarket.new(options).fetch_appliances
|
||||||
rescue Exception
|
rescue StandardError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,9 @@ require 'json'
|
|||||||
require 'base64'
|
require 'base64'
|
||||||
require 'rexml/document'
|
require 'rexml/document'
|
||||||
|
|
||||||
|
# OpenNebula MarketPlace
|
||||||
class OneMarket
|
class OneMarket
|
||||||
|
|
||||||
ONE_MARKET_URL = 'https://marketplace.opennebula.systems/'
|
ONE_MARKET_URL = 'https://marketplace.opennebula.systems/'
|
||||||
AGENT = 'Market Driver'
|
AGENT = 'Market Driver'
|
||||||
VERSION = File.dirname(__FILE__) + '/../../VERSION'
|
VERSION = File.dirname(__FILE__) + '/../../VERSION'
|
||||||
@ -33,11 +35,13 @@ class OneMarket
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get(path)
|
def get(path)
|
||||||
|
|
||||||
# Get proxy params (needed for ruby 1.9.3)
|
# Get proxy params (needed for ruby 1.9.3)
|
||||||
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
|
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
|
||||||
|
|
||||||
if http_proxy
|
if http_proxy
|
||||||
|
# prepend 'http' if missing to parse with URI()
|
||||||
|
http_proxy = 'http://' + http_proxy if http_proxy !~ /^http/
|
||||||
|
|
||||||
p_uri = URI(http_proxy)
|
p_uri = URI(http_proxy)
|
||||||
p_host = p_uri.host
|
p_host = p_uri.host
|
||||||
p_port = p_uri.port
|
p_port = p_uri.port
|
||||||
@ -52,18 +56,16 @@ class OneMarket
|
|||||||
req['User-Agent'] = @agent
|
req['User-Agent'] = @agent
|
||||||
|
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port, p_host, p_port,
|
response = Net::HTTP.start(uri.hostname, uri.port, p_host, p_port,
|
||||||
:use_ssl => uri.scheme == 'https') { |http|
|
:use_ssl => uri.scheme == 'https') do |http|
|
||||||
http.request(req)
|
http.request(req)
|
||||||
}
|
|
||||||
|
|
||||||
if response.is_a? Net::HTTPSuccess
|
|
||||||
return 0, response.body
|
|
||||||
else
|
|
||||||
return response.code.to_i, response.msg
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return 0, response.body if response.is_a? Net::HTTPSuccess
|
||||||
|
|
||||||
|
[response.code.to_i, response.msg]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_appliances()
|
def fetch_appliances
|
||||||
rc, body = get('/appliance')
|
rc, body = get('/appliance')
|
||||||
|
|
||||||
if rc != 0
|
if rc != 0
|
||||||
@ -71,57 +73,64 @@ class OneMarket
|
|||||||
end
|
end
|
||||||
|
|
||||||
applist = JSON.parse(body)
|
applist = JSON.parse(body)
|
||||||
appstr = ""
|
appstr = ''
|
||||||
|
|
||||||
applist['appliances'].each { |app|
|
applist['appliances'].each do |app|
|
||||||
id = app["_id"]["$oid"]
|
id = app['_id']['$oid']
|
||||||
source = "#{@url}/appliance/#{id}/download/0"
|
source = "#{@url}/appliance/#{id}/download/0"
|
||||||
|
|
||||||
tmpl = ""
|
tmpl = ''
|
||||||
|
|
||||||
print_var(tmpl, "NAME", app["name"])
|
print_var(tmpl, 'NAME', app['name'])
|
||||||
print_var(tmpl, "SOURCE", source)
|
print_var(tmpl, 'SOURCE', source)
|
||||||
print_var(tmpl, "IMPORT_ID", id)
|
print_var(tmpl, 'IMPORT_ID', id)
|
||||||
print_var(tmpl, "ORIGIN_ID", "-1")
|
print_var(tmpl, 'ORIGIN_ID', '-1')
|
||||||
print_var(tmpl, "TYPE", "IMAGE")
|
print_var(tmpl, 'TYPE', 'IMAGE')
|
||||||
print_var(tmpl, "PUBLISHER", app["publisher"])
|
print_var(tmpl, 'PUBLISHER', app['publisher'])
|
||||||
print_var(tmpl, "FORMAT", app["format"])
|
print_var(tmpl, 'FORMAT', app['format'])
|
||||||
print_var(tmpl, "DESCRIPTION", app["short_description"])
|
print_var(tmpl, 'DESCRIPTION', app['short_description'])
|
||||||
print_var(tmpl, "VERSION", app["version"])
|
print_var(tmpl, 'VERSION', app['version'])
|
||||||
print_var(tmpl, "TAGS", app["tags"].join(', '))
|
print_var(tmpl, 'TAGS', app['tags'].join(', '))
|
||||||
print_var(tmpl, "REGTIME", app["creation_time"])
|
print_var(tmpl, 'REGTIME', app['creation_time'])
|
||||||
|
|
||||||
if !app["files"].nil? && !app["files"][0].nil?
|
if !app['files'].nil? && !app['files'][0].nil?
|
||||||
file = app["files"][0]
|
file = app['files'][0]
|
||||||
size = 0
|
size = 0
|
||||||
|
|
||||||
if (file["size"].to_i != 0)
|
if file['size'].to_i != 0
|
||||||
size = file["size"].to_i / (2**20)
|
size = file['size'].to_i / (2**20)
|
||||||
end
|
end
|
||||||
|
|
||||||
print_var(tmpl, "SIZE", size)
|
print_var(tmpl, 'SIZE', size)
|
||||||
print_var(tmpl, "MD5", file["md5"])
|
print_var(tmpl, 'MD5', file['md5'])
|
||||||
|
|
||||||
tmpl64 = ""
|
tmpl64 = ''
|
||||||
print_var(tmpl64, "DEV_PREFIX", file["dev_prefix"])
|
print_var(tmpl64, 'DEV_PREFIX', file['dev_prefix'])
|
||||||
print_var(tmpl64, "DRIVER", file["driver"])
|
print_var(tmpl64, 'DRIVER', file['driver'])
|
||||||
print_var(tmpl64, "TYPE", file["type"])
|
print_var(tmpl64, 'TYPE', file['type'])
|
||||||
|
|
||||||
if !tmpl64.empty?
|
if !tmpl64.empty?
|
||||||
print_var(tmpl, "APPTEMPLATE64", Base64::strict_encode64(tmpl64))
|
print_var(tmpl,
|
||||||
|
'APPTEMPLATE64',
|
||||||
|
Base64.strict_encode64(tmpl64))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if !app["opennebula_template"].nil?
|
if !app['opennebula_template'].nil?
|
||||||
vmtmpl64 = template_to_str(JSON.parse(app["opennebula_template"]))
|
vmtmpl64 = template_to_str(
|
||||||
print_var(tmpl, "VMTEMPLATE64", Base64::strict_encode64(vmtmpl64))
|
JSON.parse(app['opennebula_template'])
|
||||||
end
|
)
|
||||||
rescue
|
print_var(tmpl,
|
||||||
|
'VMTEMPLATE64',
|
||||||
|
Base64.strict_encode64(vmtmpl64))
|
||||||
|
end
|
||||||
|
rescue StandardError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
appstr << "APP=\"#{Base64::strict_encode64(tmpl)}\"\n"
|
appstr << "APP=\"#{Base64.strict_encode64(tmpl)}\"\n"
|
||||||
}
|
end
|
||||||
|
|
||||||
appstr
|
appstr
|
||||||
end
|
end
|
||||||
@ -132,7 +141,7 @@ class OneMarket
|
|||||||
return if val.nil?
|
return if val.nil?
|
||||||
return if val.class == String && val.empty?
|
return if val.class == String && val.empty?
|
||||||
|
|
||||||
val.gsub!('"','\"') if val.class == String
|
val.gsub!('"', '\"') if val.class == String
|
||||||
|
|
||||||
str << "#{name}=\"#{val}\"\n"
|
str << "#{name}=\"#{val}\"\n"
|
||||||
end
|
end
|
||||||
@ -141,21 +150,23 @@ class OneMarket
|
|||||||
thash.collect do |key, value|
|
thash.collect do |key, value|
|
||||||
next if value.nil? || value.empty?
|
next if value.nil? || value.empty?
|
||||||
|
|
||||||
str = case value.class.name
|
case value.class.name
|
||||||
when "Hash"
|
when 'Hash'
|
||||||
attr = "#{key.to_s.upcase} = [ "
|
attr = "#{key.to_s.upcase} = [ "
|
||||||
|
|
||||||
attr << value.collect do |k, v|
|
attr << value.collect do |k, v|
|
||||||
next if v.nil? || v.empty?
|
next if v.nil? || v.empty?
|
||||||
"#{k.to_s.upcase} =\"#{v.to_s}\""
|
|
||||||
end.compact.join(",")
|
"#{k.to_s.upcase} =\"#{v}\""
|
||||||
|
end.compact.join(',')
|
||||||
|
|
||||||
attr << "]\n"
|
attr << "]\n"
|
||||||
when "String"
|
when 'String'
|
||||||
"#{key.to_s.upcase} = \"#{value.to_s}\""
|
"#{key.to_s.upcase} = \"#{value}\""
|
||||||
end
|
end
|
||||||
end.compact.join("\n")
|
end.compact.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -163,12 +174,13 @@ end
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
begin
|
begin
|
||||||
drv_message = Base64::decode64(ARGV[0])
|
drv_message = Base64.decode64(ARGV[0])
|
||||||
doc = REXML::Document.new(drv_message).root
|
doc = REXML::Document.new(drv_message).root
|
||||||
url = doc.elements['MARKETPLACE/TEMPLATE/ENDPOINT'].text rescue nil
|
url = doc.elements['MARKETPLACE/TEMPLATE/ENDPOINT'].text rescue nil
|
||||||
rescue Exception
|
rescue StandardError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO get marketplace URL from MARKETPLACE Templace for other markets
|
# TODO: get marketplace URL from MARKETPLACE Templace for other markets
|
||||||
one_market = OneMarket.new(url)
|
one_market = OneMarket.new(url)
|
||||||
puts one_market.get_appliances
|
puts one_market.fetch_appliances
|
||||||
|
Loading…
Reference in New Issue
Block a user