Get synced folder from machine

This commit is contained in:
sophia 2021-11-22 16:56:32 -06:00 committed by Paul Hinze
parent b9a8ff1089
commit 847d87a017
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
4 changed files with 39 additions and 8 deletions

View File

@ -178,7 +178,21 @@ func (m *Machine) UID() (userId string, err error) {
// SyncedFolders implements core.Machine
func (m *Machine) SyncedFolders() (folders []core.SyncedFolder, err error) {
// TODO: need Vagrantfile
config := m.target.Configuration
machineConfig := config.ConfigVm
syncedFolders := machineConfig.SyncedFolders
folders = []core.SyncedFolder{}
for _, folder := range syncedFolders {
// TODO: get default synced folder type
folder.Type = "virtualbox"
plg, err := m.project.basis.component(m.ctx, component.SyncedFolderType, folder.Type)
// TODO: configure with folder info
if err != nil {
return nil, err
}
folders = append(folders, plg.Value.(core.SyncedFolder))
}
return
}

View File

@ -371,8 +371,16 @@ module Vagrant
end
def synced_folders
# self.class.synced_folders(self)
client.synced_folders
folders = Vagrant::Plugin::V2::SyncedFolder::Collection.new
synced_folder_clients = client.synced_folders
@logger.debug("synced folder clients: #{synced_folder_clients}")
synced_folder_clients.each do |f|
# TODO: get type of synced folder and wrap it up in this hash
impl = "virtualbox"
sf = Vagrant::Plugin::V2::SyncedFolder.new._initialize(self, impl, f)
folders[impl] = {"id": {plugin: sf}}
end
folders
end
def to_proto

View File

@ -13,8 +13,14 @@ module Vagrant
end
end
def _initialize(machine, synced_folder_type)
@client = nil#TODO!
def _initialize(machine, synced_folder_type, client=nil)
@machine = machine
@client = client
if @client.nil?
raise ArgumentError,
"Remote client is required for `#{self.class.name}'"
end
@logger = Log4r::Logger.new("vagrant::synced_folder")
self
end
@ -62,7 +68,7 @@ module Vagrant
#
# @param [Symbol] cap_name Name of the capability
def capability(cap_name, *args)
@logger.debug("running remote host capability #{cap_name} with args #{args}")
@logger.debug("running remote synced folder capability #{cap_name} with args #{args}")
client.capability(cap_name, *args)
end
@ -71,7 +77,7 @@ module Vagrant
# @param [Symbol] cap_name Capability name
# @return [Boolean]
def capability?(cap_name)
@logger.debug("checking for remote host capability #{cap_name}")
@logger.debug("checking for remote synced folder capability #{cap_name}")
client.has_capability?(cap_name)
end

View File

@ -87,8 +87,11 @@ module VagrantPlugins
client.set_state(req)
end
# TODO: this is setup to return plugins. verify
def synced_folders
folder_protos = client.synced_folders(Empty.new).synced_folders
folder_protos.map do |f|
SyncedFolder.load(f, broker: broker)
end
end
# @return [Integer] user ID that owns machine