lib/providers/lxd.rb in gogetit-0.12.4 vs lib/providers/lxd.rb in gogetit-0.13.1

- old
+ new

@@ -1,9 +1,10 @@ require 'hyperkit' require 'gogetit/util' require 'yaml' require 'hashie' +require 'table_print' module Gogetit class GogetLXD include Gogetit::Util @@ -12,15 +13,47 @@ def initialize(conf, maas, logger) @config = conf @conn = Hyperkit::Client.new( api_endpoint: config[:lxd][:nodes][0][:url], verify_ssl: false - ) + ) @maas = maas @logger = logger end + def list_all_containers + logger.debug("Calling <#{__method__.to_s}>") + + config[:lxd][:nodes].each do |node| + puts "Listing LXC containers on #{node[:url]}..." + conn = Hyperkit::Client.new( + api_endpoint: node[:url], + verify_ssl: false + ) + + nodes = [] + conn.containers.each do |con| + row = {} + row[:name] = conn.container(con).to_hash[:name] + row[:status] = conn.container_state(con).to_hash[:status].upcase + if conn.container_state(con).to_hash[:network] && \ + conn.container_state(con).to_hash[:network][:eth0] && \ + conn.container_state(con).to_hash[:network][:eth0][:addresses] && \ + conn.container_state(con).to_hash[:network][:eth0][:addresses][0] && \ + conn.container_state(con).to_hash[:network][:eth0][:addresses][0][:address] + row[:ipv4] = \ + conn.container_state(con).to_hash[:network][:eth0][:addresses][0][:address] + else + row[:ipv4] = "NA" + end + nodes << row + end + tp nodes, :name, :status, :ipv4 + puts + end + end + def list logger.info("Calling <#{__method__.to_s}>") conn.containers end @@ -47,9 +80,11 @@ # to generate 'user.user-data' def generate_user_data(args, options) logger.info("Calling <#{__method__.to_s}>") args[:config] = {} + + args[:config][:"user.user-data"]['maas'] = true if options['no-maas'] args[:config][:'user.user-data'] = \ YAML.load_file(options['file'])[:config]['user.user-data'] else