Use remote box metadata implementation
This commit is contained in:
parent
84a6950c9e
commit
428c3b02fd
@ -5,6 +5,9 @@ module Vagrant
|
||||
# it should have, a description of it, the versions it has, and
|
||||
# more.
|
||||
class BoxMetadata
|
||||
|
||||
autoload :Remote, "vagrant/box_metadata/remote"
|
||||
|
||||
# The name that the box should be if it is added.
|
||||
#
|
||||
# @return [String]
|
||||
|
||||
83
lib/vagrant/box_metadata/remote.rb
Normal file
83
lib/vagrant/box_metadata/remote.rb
Normal file
@ -0,0 +1,83 @@
|
||||
module Vagrant
|
||||
class BoxMetadata
|
||||
# This module enables the BoxMetadata for server mode
|
||||
module Remote
|
||||
|
||||
# Add an attribute reader for the client
|
||||
# when applied to the BoxMetadata class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_reader :client
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :name
|
||||
attr_accessor :description
|
||||
|
||||
# @param [IO] io An IO object to read the metadata from.
|
||||
def initialize(io, client: nil)
|
||||
@logger = Log4r::Logger.new("vagrant::box")
|
||||
|
||||
if client.nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}'"
|
||||
end
|
||||
@client = client
|
||||
end
|
||||
|
||||
def version(version, **opts)
|
||||
v = client.version(version, opts[:provider])
|
||||
Version.new(v, ver: v["version"], client: @client)
|
||||
end
|
||||
|
||||
def versions(**opts)
|
||||
provider = nil
|
||||
provider = opts[:provider].to_sym if opts[:provider]
|
||||
client.versions(provider)
|
||||
end
|
||||
|
||||
class Version
|
||||
attr_accessor :version
|
||||
|
||||
def initialize(raw=nil, ver: nil, client: nil)
|
||||
return if raw.nil?
|
||||
|
||||
@version = ver
|
||||
if client.nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}'"
|
||||
end
|
||||
@client = client
|
||||
end
|
||||
|
||||
def provider(name)
|
||||
p = client.provider(@version, name)
|
||||
Provider.new(p, @client)
|
||||
end
|
||||
|
||||
def providers
|
||||
client.providers(@version)
|
||||
end
|
||||
|
||||
class Provider
|
||||
attr_accessor :name
|
||||
attr_accessor :url
|
||||
attr_accessor :checksum
|
||||
attr_accessor :checksum_type
|
||||
|
||||
def initialize(raw, client: nil)
|
||||
@name = raw["name"]
|
||||
@url = raw["url"]
|
||||
@checksum = raw["checksum"]
|
||||
@checksum_type = raw["checksum_type"]
|
||||
if client.nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}'"
|
||||
end
|
||||
@client = client
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -260,6 +260,7 @@ module Vagrant
|
||||
SERVER_MODE_CALLBACKS = [
|
||||
->{ Vagrant::Box.prepend(Vagrant::Box::Remote) },
|
||||
->{ Vagrant::BoxCollection.prepend(Vagrant::BoxCollection::Remote) },
|
||||
->{ Vagrant::BoxMetadata.prepend(Vagrant::BoxMetadata::Remote) },
|
||||
->{ Vagrant::Guest.prepend(Vagrant::Guest::Remote) },
|
||||
->{ Vagrant::Host.prepend(Vagrant::Host::Remote) },
|
||||
->{ Vagrant::Machine.prepend(Vagrant::Machine::Remote) },
|
||||
|
||||
@ -4,6 +4,7 @@ module VagrantPlugins
|
||||
autoload :Basis, Vagrant.source_root.join("plugins/commands/serve/client/basis").to_s
|
||||
autoload :Box, Vagrant.source_root.join("plugins/commands/serve/client/box").to_s
|
||||
autoload :BoxCollection, Vagrant.source_root.join("plugins/commands/serve/client/box_collection").to_s
|
||||
autoload :BoxMetadata, Vagrant.source_root.join("plugins/commands/serve/client/box_metadata").to_s
|
||||
autoload :CapabilityPlatform, Vagrant.source_root.join("plugins/commands/serve/client/capability_platform").to_s
|
||||
autoload :Communicator, Vagrant.source_root.join("plugins/commands/serve/client/communicator").to_s
|
||||
autoload :Command, Vagrant.source_root.join("plugins/commands/serve/client/command").to_s
|
||||
|
||||
44
plugins/commands/serve/client/box_metadata.rb
Normal file
44
plugins/commands/serve/client/box_metadata.rb
Normal file
@ -0,0 +1,44 @@
|
||||
module VagrantPlugins
|
||||
module CommandServe
|
||||
class Client
|
||||
class BoxMetadata < Client
|
||||
def name
|
||||
client.name(Empty.new)
|
||||
end
|
||||
|
||||
# @param [String] version The version to return, this can also
|
||||
# be a constraint.
|
||||
# @param [String] (optional) adds a provider constraint to the version
|
||||
def version(version, provider)
|
||||
v = client.version(SDK::BoxMetadata::VersionRequest.new(
|
||||
version: version,
|
||||
opts: SDK::BoxMetadata::BoxMetadataOpts.new(name: provider)
|
||||
))
|
||||
v.to_h
|
||||
end
|
||||
|
||||
# @param [String] (optional) adds a provider constraint to the version list
|
||||
def list_versions(provider)
|
||||
v = client.list_version(SDK::BoxMetadata::BoxMetadataOpts.new(
|
||||
name: provider
|
||||
))
|
||||
v.versions
|
||||
end
|
||||
|
||||
def provider(version, name)
|
||||
p = client.provider(SDK::BoxMetadata::ProviderRequest.new(
|
||||
version: version, name: name
|
||||
))
|
||||
p.to_h
|
||||
end
|
||||
|
||||
def list_providers(version)
|
||||
p = client.list_providers(SDK::BoxMetadata::ListProvidersRequest.new(
|
||||
version: version
|
||||
))
|
||||
p.providers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user