Organizing clients and matching up with core interfaces

This commit is contained in:
Chris Roberts 2021-08-17 12:34:32 -07:00 committed by Paul Hinze
parent 74ed9b2f5b
commit 3583259fc9
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 94 additions and 86 deletions

View File

@ -25,11 +25,48 @@ module VagrantPlugins
SDK::Ref::Target::Machine.new(resource_id: resource_id)
end
# @return [Vagrant::Box] box backing machine
def box
resp = client.box(Empty.new)
Vagrant::Box.new(
resp.box.name,
resp.box.provider.to_sym,
resp.box.version,
Pathname.new(resp.box.directory),
)
end
# @return
# TODO: This needs some design adjustments
def connection_info
end
# @return [Guest] machine guest
# TODO: This needs to be loaded properly
def guest
client.guest(Empty.new)
end
# @return [String] machine identifier
def id
client.get_id(Empty.new).id
end
# @return [Vagrant::MachineState] current state of machine
def machine_state
resp = client.get_state(Empty.new)
Vagrant::MachineState.new(
resp.id.to_sym,
resp.short_description,
resp.long_description
)
end
# Force a reload of the machine state
def reload
client.reload(Empty.new)
end
# Set ID for machine
#
# @param [String] new_id New machine ID
@ -41,41 +78,10 @@ module VagrantPlugins
)
end
# @return [Vagrant::Box] box backing machine
def box
resp = client.box(Empty.new)
Vagrant::Box.new(
resp.box.name,
resp.box.provider.to_sym,
resp.box.version,
Pathname.new(resp.box.directory),
)
end
def get_dir
req = Google::Protobuf::Empty.new
@client.data_dir(req)
end
def get_data_dir
dir = get_dir
Pathname.new(dir.data_dir)
end
# @return [Vagrant::MachineState] current state of machine
def machine_state
resp = client.get_state(Empty.new)
Vagrant::MachineState.new(
resp.id.to_sym,
resp.short_description,
resp.long_description
)
end
# Set the current state of the machine
#
# @param [Vagrant::MachineState] state of the machine
def set_state(state)
def set_machine_state(state)
req = SDK::Target::Machine::SetStateRequest.new(
state: SDK::Args::Target::Machine::State.new(
id: state.id,
@ -86,30 +92,14 @@ module VagrantPlugins
client.set_state(req)
end
# @return [Guest] machine guest
# TODO: This needs to be loaded properly
def guest
client.guest(Empty.new)
end
# Force a reload of the machine state
def reload
client.reload(Empty.new)
end
# @return
# TODO: This needs some design adjustments
def connection_info
# TODO: this is setup to return plugins. verify
def synced_folders
end
# @return [Integer] user ID that owns machine
def uid
client.uid(Empty.new).uid
end
# TODO: this is setup to return plugins. verify
def synced_folders
end
end
end
end

View File

@ -29,19 +29,36 @@ module VagrantPlugins
self.new(connect(proto: t, broker: broker), broker)
end
# @return [String] resource identifier for this target
def resource_id
client.resource_id(Empty.new).resource_id
end
# @return [SDK::Ref::Target] proto reference for this target
def ref
SDK::Ref::Target.new(resource_id: resource_id)
end
# Save the state of the target
def save
client.save(Empty.new)
# @return [Communicator]
# TODO: Implement
def communicate
end
# @return [Pathname] target specific data directory
def data_dir
Pathname.new(client.data_dir(Empty.new).data_dir)
end
# @return [Boolean] destroy the traget
def destroy
client.destroy(Empty.new)
true
end
# @return [String] Unique identifier of machine
def get_uuid
client.get_uuid(Empty.new).uuid
end
# @return [Hash] freeform key/value data for target
def metadata
kv = client.metadata(Empty.new).metadata
Vagrant::Util::HashWithIndifferentAccess.new(kv.to_h)
end
# @return [String] name of target
@ -49,6 +66,32 @@ module VagrantPlugins
client.name(Empty.new).name
end
# @return [Project] project this target is within
def project
Project.load(client.project(Empty.new), broker: broker)
end
# @return [Provider] provider for target
# TODO: This needs to be loaded proeprly
def provider
client.provider(Empty.new)
end
# @return [String] name of provider for target
def provider_name
client.provider_name(Empty.new).name
end
# @return [String] resource identifier for this target
def resource_id
client.resource_id(Empty.new).resource_id
end
# Save the state of the target
def save
client.save(Empty.new)
end
# Set name of target
#
# @param [String] name Name of target
@ -60,11 +103,6 @@ module VagrantPlugins
)
end
# @return [String] Unique identifier of machine
def get_uuid
client.get_uuid(Empty.new).uuid
end
# Set the unique identifier fo the machine
#
# @param [String] uuid Uniqe identifier
@ -76,24 +114,9 @@ module VagrantPlugins
)
end
# @return [Pathname] target specific data directory
def data_dir
Pathname.new(client.data_dir(Empty.new).data_dir)
end
# @return [Provider] provider for target
# TODO: This needs to be loaded proeprly
def provider
client.provider(Empty.new)
end
def provider_name
client.provider_name(Empty.new).name
end
# @return [Project] project this target is within
def project
Project.load(client.project(Empty.new), broker: broker)
# @return [Symbol] state of the target
def state
client.state(Empty.new).state
end
# @return [Time] time target was last updated
@ -101,11 +124,6 @@ module VagrantPlugins
Time.parse(client.updated_at(Empty.new).updated_at)
end
# @return [Symbol] state of the target
def state
client.state(Empty.new).state
end
# @return [Machine] specialize target into a machine client
def to_machine
Machine.load(