providers/hyperv: clean up provider since we moved out SMB
This commit is contained in:
parent
dd6f1083b0
commit
41bc86c490
|
@ -71,7 +71,6 @@ module VagrantPlugins
|
||||||
b.use WaitForCommunicator, [:running]
|
b.use WaitForCommunicator, [:running]
|
||||||
b.use SyncedFolders
|
b.use SyncedFolders
|
||||||
|
|
||||||
#b.use ShareFolders
|
|
||||||
#b.use SyncFolders
|
#b.use SyncFolders
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -138,7 +137,6 @@ module VagrantPlugins
|
||||||
autoload :MessageNotRunning, action_root.join('message_not_running')
|
autoload :MessageNotRunning, action_root.join('message_not_running')
|
||||||
autoload :SyncFolders, action_root.join('sync_folders')
|
autoload :SyncFolders, action_root.join('sync_folders')
|
||||||
autoload :ReadGuestIP, action_root.join('read_guest_ip')
|
autoload :ReadGuestIP, action_root.join('read_guest_ip')
|
||||||
autoload :ShareFolders, action_root.join('share_folders')
|
|
||||||
autoload :WaitForIPAddress, action_root.join("wait_for_ip_address")
|
autoload :WaitForIPAddress, action_root.join("wait_for_ip_address")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
# Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
# All Rights Reserved. Licensed under the MIT License.
|
|
||||||
#--------------------------------------------------------------------------
|
|
||||||
require "debugger"
|
|
||||||
require "vagrant/util/subprocess"
|
|
||||||
module VagrantPlugins
|
|
||||||
module HyperV
|
|
||||||
module Action
|
|
||||||
class ShareFolders
|
|
||||||
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
@env = env
|
|
||||||
smb_shared_folders
|
|
||||||
prepare_smb_share
|
|
||||||
# A BIG Clean UP
|
|
||||||
# There should be a communicator class which branches between windows
|
|
||||||
# and Linux
|
|
||||||
if @smb_shared_folders.length > 0
|
|
||||||
env[:ui].info('Mounting shared folders with VM, This process may take few minutes.')
|
|
||||||
end
|
|
||||||
if env[:machine].config.vm.guest == :windows
|
|
||||||
env[:ui].info "Mounting shared folders to windows is under development."
|
|
||||||
# mount_shared_folders_to_windows
|
|
||||||
elsif env[:machine].config.vm.guest == :linux
|
|
||||||
mount_shared_folders_to_linux
|
|
||||||
end
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
|
|
||||||
def smb_shared_folders
|
|
||||||
@smb_shared_folders = {}
|
|
||||||
@env[:machine].config.vm.synced_folders.each do |id, data|
|
|
||||||
# Ignore disabled shared folders
|
|
||||||
next if data[:disabled]
|
|
||||||
|
|
||||||
# Collect all SMB shares
|
|
||||||
next unless data[:smb]
|
|
||||||
# This to prevent overwriting the actual shared folders data
|
|
||||||
@smb_shared_folders[id] = data.dup
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def prepare_smb_share
|
|
||||||
@smb_shared_folders.each do |id, data|
|
|
||||||
begin
|
|
||||||
hostpath = File.expand_path(data[:hostpath], @env[:root_path])
|
|
||||||
host_share_username = @env[:machine].provider_config.host_share.username
|
|
||||||
options = {:path => hostpath,
|
|
||||||
:share_name => data[:share_name],
|
|
||||||
:host_share_username => host_share_username}
|
|
||||||
response = @env[:machine].provider.driver.execute('set_smb_share.ps1', options)
|
|
||||||
if response["message"] == "OK"
|
|
||||||
@env[:ui].info "Successfully created SMB share for #{hostpath} with name #{data[:share_name]}"
|
|
||||||
end
|
|
||||||
rescue Error::SubprocessError => e
|
|
||||||
@env[:ui].info e.message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def ssh_info
|
|
||||||
@ssh_info || @env[:machine].ssh_info
|
|
||||||
end
|
|
||||||
|
|
||||||
def mount_shared_folders_to_windows
|
|
||||||
result = @env[:machine].provider.driver.execute('host_info.ps1', {})
|
|
||||||
@smb_shared_folders.each do |id, data|
|
|
||||||
begin
|
|
||||||
options = { :share_name => data[:share_name],
|
|
||||||
:guest_path => data[:guestpath].gsub("/", "\\"),
|
|
||||||
:guest_ip => ssh_info[:host],
|
|
||||||
:username => ssh_info[:username],
|
|
||||||
:host_ip => result["host_ip"],
|
|
||||||
:password => @env[:machine].provider_config.guest.password,
|
|
||||||
:host_share_username => @env[:machine].provider_config.host_share.username,
|
|
||||||
:host_share_password => @env[:machine].provider_config.host_share.password}
|
|
||||||
@env[:ui].info("Linking #{data[:share_name]} to Guest at #{data[:guestpath]} ...")
|
|
||||||
@env[:machine].provider.driver.execute('mount_share.ps1', options)
|
|
||||||
rescue Error::SubprocessError => e
|
|
||||||
@env[:ui].info "Failed to link #{data[:share_name]} to Guest"
|
|
||||||
@env[:ui].info e.message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def mount_shared_folders_to_linux
|
|
||||||
# Find Host Machine's credentials
|
|
||||||
result = @env[:machine].provider.driver.execute('host_info.ps1', {})
|
|
||||||
host_share_username = @env[:machine].provider_config.host_share.username
|
|
||||||
host_share_password = @env[:machine].provider_config.host_share.password
|
|
||||||
@smb_shared_folders.each do |id, data|
|
|
||||||
begin
|
|
||||||
# Mount the Network drive to Guest VM
|
|
||||||
@env[:ui].info("Linking #{data[:share_name]} to Guest at #{data[:guestpath]} ...")
|
|
||||||
|
|
||||||
# Create a location in guest to guestpath
|
|
||||||
@env[:machine].communicate.sudo("mkdir -p #{data[:guestpath]}")
|
|
||||||
owner = data[:owner] || ssh_info[:username]
|
|
||||||
group = data[:group] || ssh_info[:username]
|
|
||||||
|
|
||||||
mount_options = "-o rw,username=#{host_share_username},pass=#{host_share_password},"
|
|
||||||
mount_options += "sec=ntlm,file_mode=0777,dir_mode=0777,"
|
|
||||||
mount_options += "uid=`id -u #{owner}`,gid=`id -g #{group}`,rw #{data[:guestpath]}"
|
|
||||||
|
|
||||||
command = "mount -t cifs //#{result["host_ip"]}/#{data[:share_name]} #{mount_options}"
|
|
||||||
|
|
||||||
@env[:machine].communicate.sudo(command)
|
|
||||||
|
|
||||||
rescue RuntimeError => e
|
|
||||||
@env[:ui].error(e.message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,25 +0,0 @@
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
# Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
# All Rights Reserved. Licensed under the MIT License.
|
|
||||||
#--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Include the following modules
|
|
||||||
$presentDir = Split-Path -parent $PSCommandPath
|
|
||||||
$modules = @()
|
|
||||||
$modules += $presentDir + "\utils\write_messages.ps1"
|
|
||||||
forEach ($module in $modules) { . $module }
|
|
||||||
|
|
||||||
try {
|
|
||||||
$hostname = $(whoami)
|
|
||||||
$ip = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
|
|
||||||
$resultHash = @{
|
|
||||||
host_name = "$username"
|
|
||||||
host_ip = "$ip"
|
|
||||||
}
|
|
||||||
$result = ConvertTo-Json $resultHash
|
|
||||||
Write-Output-Message $result
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-Error-Message $_
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
Param(
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$path,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$share_name,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$host_share_username
|
|
||||||
)
|
|
||||||
|
|
||||||
$ErrorAction = "Stop"
|
|
||||||
|
|
||||||
# See all available shares and check alert user for
|
|
||||||
# existing/conflicting share name
|
|
||||||
$shared_folders = net share
|
|
||||||
$reg = "$share_name(\s+)$path(\s)"
|
|
||||||
$existing_share = $shared_folders -Match $reg
|
|
||||||
if ($existing_share) {
|
|
||||||
# Always clear the existing share name and create a new one
|
|
||||||
net share $share_name /delete /y
|
|
||||||
}
|
|
||||||
|
|
||||||
$computer_name = $(Get-WmiObject Win32_Computersystem).name
|
|
||||||
$grant_permission = "$computer_name\$host_share_username,Full"
|
|
||||||
$result = net share $share_name=$path /unlimited /GRANT:$grant_permission
|
|
||||||
if ($result -Match "$share_name was shared successfully.") {
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
$host.ui.WriteErrorLine("Error: $result")
|
|
||||||
exit 1
|
|
|
@ -1,9 +1,3 @@
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
# Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
# All Rights Reserved. Licensed under the MIT License.
|
|
||||||
#--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
param (
|
param (
|
||||||
[string]$share_name = $(throw "-share_name is required."),
|
[string]$share_name = $(throw "-share_name is required."),
|
||||||
[string]$guest_path = $(throw "-guest_path is required."),
|
[string]$guest_path = $(throw "-guest_path is required."),
|
|
@ -138,6 +138,29 @@ module VagrantPlugins
|
||||||
|
|
||||||
JSON.parse(r.stdout)["ip_addresses"]
|
JSON.parse(r.stdout)["ip_addresses"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
def mount_shared_folders_to_windows
|
||||||
|
result = @env[:machine].provider.driver.execute('host_info.ps1', {})
|
||||||
|
@smb_shared_folders.each do |id, data|
|
||||||
|
begin
|
||||||
|
options = { :share_name => data[:share_name],
|
||||||
|
:guest_path => data[:guestpath].gsub("/", "\\"),
|
||||||
|
:guest_ip => ssh_info[:host],
|
||||||
|
:username => ssh_info[:username],
|
||||||
|
:host_ip => result["host_ip"],
|
||||||
|
:password => @env[:machine].provider_config.guest.password,
|
||||||
|
:host_share_username => @env[:machine].provider_config.host_share.username,
|
||||||
|
:host_share_password => @env[:machine].provider_config.host_share.password}
|
||||||
|
@env[:ui].info("Linking #{data[:share_name]} to Guest at #{data[:guestpath]} ...")
|
||||||
|
@env[:machine].provider.driver.execute('mount_share.ps1', options)
|
||||||
|
rescue Error::SubprocessError => e
|
||||||
|
@env[:ui].info "Failed to link #{data[:share_name]} to Guest"
|
||||||
|
@env[:ui].info e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
=end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue