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