Coder Social home page Coder Social logo

vagrant-tramp's Introduction

#Vagrant TRAMP

Synopsis

vagrant-tramp adds an Emacs TRAMP method for Vagrant boxes. As far as Vagrant is concerned, the TRAMP vagrant method behaves like the built-in vagrant ssh command does. The vagrant-tramp method simply provides auto-completion and a wrapper around vagrant ssh for connecting to boxes.

Installation

If you have a recent Emacs with package.el, you can install vagrant-tramp from MELPA.

Or via el-get

Otherwise add it to your emacs load-path.

Usage

The TRAMP method vagrant uses vagrant global-status to get a list of running Vagrant boxes for completion:

C-x C-f /vagrant:

Find file: /vagrant:
-> devbox:
   esxbox:
   kafka-broker1:
   kafka-broker2:
   kafka-zookeeper:

Boxes are named using the Vagrantfile directory basename and the VM name (excluding default) to support multi-VM environments. TRAMP opens a connection by cd-ing into the Vagrantfile directory and running vagrant ssh $box_id.

Opening a file as root

Use this trick from the Emacs Wiki, where we replaced "ssh" with "vagrant" and where "box" is a Vagrant box name:

C-x C-f /vagrant:box|sudo:box:/path/to/file RET

vagrant-tramp-term

The vagrant-tramp-term function provides a convenient way to vagrant ssh into a box using an ansi-term.

M-x vagrant-tramp-term

vagrant ssh to box:
-> devbox:
   kafka-broker1:
   kafka-broker2:

See also

vagrant-tramp's People

Contributors

acowley avatar bradthebuilder avatar dougm avatar eeshugerman avatar ibrahima avatar jiacai2050 avatar kotfic avatar ryanprior avatar sulami avatar syohex avatar truls avatar zakame avatar zonuexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vagrant-tramp's Issues

Vagrant-tramp lists boxes after their deletion

When creating and deleting vagrant boxes in different locations on the system, they are not always created and deleted from the list when you press c-x c-f vagrant: + tab

this can be due to the Tramp file in ~/.emacs.d/Tramp

May you please create a tag for release?

Good evening,

Tonight I am writing to humbly put in a request for you to tag this project.

The reason is that a lot of users want to rely on a "numbered" release, by
the most broad definition of the term. For me, it is really simple, I am setting
up a "kind of stable" Emacs configuration of my system here https://github.com/grettke/home/blob/master/.emacs.el
and I would like to rely 100% just one tag. Whenever a "kind of stable" version
is ready, another tag would be super, too.

You might already have the most stable version in the mainline; and tagging it
would make it crystal clear to new users. Perhaps you have already released such
a version elsewhere, and if so, my apologies, and where does it live?

Stable is not the best word here. It just means that the project lives on GitHub
and that it has a tag. It doesn't mean that the software is perfect, it just
means that it is tagged. That tag gives users a version to settle on and go on
with their life is all.

I've used your package for a long time, love it, and so do many, many others.
This is a way to get that project out to the other thousands and thousands of
users who also rely upon MELPA stable.

All it takes is for you to create a tag, and within hours, it will show up on
MELPA stable.

Can't wait to hear about what you think and whether or not a tag is in this
project's future!

Kind regards,

Grant Rettke

Support for VirtualBox?

The listing of running VMs doesn't work for me on OS X with VirtualBox as a host VM. It seems like VBoxManage list runningvms is a start towards this, but I've not chased this all the way down.

In emacs 28 "when" parameter are mandatory in function define-obsolete-function-alias

In emacs 28 (master branch), the "when" parameter are mandatory in functions make-obsolete, define-obsolete-function-alias, make-obsolete-variable and define-obsolete-variable-alias.
In vagrant-tramp.el there is a lie line (134) where the "when" parameter are not defined:
(define-obsolete-function-alias 'vagrant-tramp-enable 'vagrant-tramp-add-method)

this raise an error: (wrong-number-of-arguments (3 . 4) 2)

It's announced in NEWS file in emacs master branch:

** The 'when' argument of make-obsolete and related functions is mandatory.
The use of those functions without a 'when' argument was marked
obsolete back in Emacs-23.1. The affected functions are:
make-obsolete, define-obsolete-function-alias, make-obsolete-variable,
define-obsolete-variable-alias.

Thank you

Make it work under Windows

This mode works great, except it doesn't play nice under Microsoft Windows, even when a cygwin installation as been performed.

It would be great to make it work, as both Emacs and Vagrant are pretty much OS-agnostic solutions.

I'd be ready to give a hand, with my limited knowledge.

Vagrant-Tramp does not support underscores

Note: I have submitted a pull request for this issue.

If you make two folders:

machineOne
and
machine_two

Then, you place two identical vagrant files in each folder. Then you start both machines. You can ssh into machineOne and machine_two - BUT you cannot use vagrant-tramp with machine_two.

My guess is that there must be some parsing related to the usage of an underscore that is causing it to break. It looks for a machine with a title of machineOne_default: to connect to, and when it sees an underscore ahead of time, it breaks for example it probably tries to connect to machine_two: instead of machine_two_default:.

I have a strong feeling it is tied to the following lines (bin/vagrant-tramp-ssh):
read dir_name name <<<
$(echo $1
| awk -F_ '{ print $1; print $2 }')
if [[ ! $name ]]; then name="default"; fi

Connect failures

How can I debug connection failures, I installed vagrant-tramp from MELPA

I using counsel and the prompt shows /vagrant:ubuntu--xenial64-dev

vagrant global-status --machine-readable
1522952773,,ui,info,id       
1522952773,,ui,info,name         
1522952773,,ui,info,provider   
1522952773,,ui,info,state    
1522952773,,ui,info,directory                                                    
1522952773,,ui,info,
1522952773,,ui,info,---------------------------------------------------------------------------------
1522952773,,ui,info,2a77f42  
1522952773,,ui,info,sid64-dev    
1522952773,,ui,info,virtualbox 
1522952773,,ui,info,poweroff 
1522952773,,ui,info,/home/jose/Documents/ZeroC/3.7/dist-utils/vagrant/ice/debian 
1522952773,,ui,info,
1522952773,,ui,info,303f41f  
1522952773,,ui,info,xenial64-dev 
1522952773,,ui,info,virtualbox 
1522952773,,ui,info,running  
1522952773,,ui,info,/home/jose/Documents/ZeroC/3.7/dist-utils/vagrant/ice/ubuntu 
1522952773,,ui,info,
1522952773,,ui,info, \n

The connection always fails, is the autocompletion inserting the bogus name?

Ssh from the console works fine.

Vagrant-tramp not always able to ssh

Depending on the machine I ran vagrant-tramp it could vagrant-tramp into a machine. I would run (find-file "/vagrant:proj_vm1:") and I would receive the following error:

A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.

The vagrant machine was running. I checked it with vagrant global-status. After some troubleshooting I found that the vagrant-tramp-ssh script was not getting the right machine name. This was due to the first awk statement not rebuilding $0 after $NF--. This happens on certain versions of awk.

Your stuff is completely broken

Hi,

As you can see, your program is completely broken. Please fix it, or remove your entire project from the Internet as you are using a name 'vagrant-tramp' which would be useful for a working version of an extension for tramp providing vagrant support.

Just out of curiosity, why would you want to connect your name to such a broken piece of software?

Possible completions are:
vagrant:                            [--machinereadable]:    vagrant:(C) 2005-2014 Oracle Corporation:
vagrant:All rights reserved.:   vagrant:Oracle VM VirtualBox Command Line Management Interface Version 4.3.16:
vagrant:Syntax error: unknown option: -:    vagrant:Usage::
vagrant:VBoxManage showvminfo       <uuid|vmname> --log <idx>:  vagrant:VBoxManage showvminfo       <uuid|vmname> [--details]:
vagrant:VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2611 of file VBoxManageInfo.cpp:
vagrant:VBoxManage: error: Could not find a registered machine named 'a1':  vagrant:VBoxManage: error: Could not find a registered machine named 'a2':
vagrant:VBoxManage: error: Could not find a registered machine named 'vagrant':
vagrant:VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports:

vagrant-tramp really slow when working on codebases inside a VM

Description :octocat:

Running spacemacs on host connected to a VM containing code files via vagrant-trap is very slow and auto-complete doesn't work (like it does if the code is on the host instead of the VM -- using python)

Reproduction guide 🪲

  • Start Emacs
  • Add the following to dotspacemacs/user-config ()
  (defun connect-vagrant ()
    (interactive)
    (dired "/ssh:vagrant@localhost#2222:/"))
  • SPC f e R
  • M-x connect-vagrant
  • navigate to a file on the VM
  • starting coding

Observed behaviour: 👀 💔
As you type and short pause between words or symbols kicks off a bunch of vagrant-tramp opening connection and sending ssh operations (See messages below). This makes typing really slow as it interrupts and prevents you from doing anything in the meantime. Also auto complete does not work.

Expected behaviour: ❤️ 😄
Coding should not be interrupted and auto-complete should work.

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.1
  • Spacemacs: 0.200.13
  • Spacemacs branch: master (rev. c7a103a77)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(html javascript auto-completion c-c++ emacs-lisp git vagrant ruby themes-megapack
      (python :variables python-test-runner 'pytest)
      ess colors markdown org
      (shell :variables shell-default-height 30 shell-default-position 'bottom)
      spell-checking syntax-checking html yaml version-control)
  • System configuration features: XPM JPEG TIFF GIF PNG SOUND DBUS GSETTINGS NOTIFY GNUTLS FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 THREADS

Messages 🐾

Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...
Tramp: Sending password
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done
Directory has changed on disk; type g to update Dired [3 times]
Tramp: Inserting ‘/ssh:vagrant@localhost#2222:/sync/path/hidden/backend/manage.py’...
Tramp: Encoding remote file ‘/ssh:vagrant@localhost#2222:/sync/path/hidden/backend/manage.py’ with ‘base64 <%s’...done
Tramp: Decoding local file ‘/tmp/tramp.bC8AqM.py’ with ‘base64-decode-region’...done
Tramp: Inserting ‘/ssh:vagrant@localhost#2222:/sync/path/hidden/backend/manage.py’...done
git-gutter+-refresh: Wrong type argument: arrayp, (tramp-file-name "ssh" "vagrant" nil "localhost" "2222" "/sync/path/hidden/backend/manage.py" nil)
Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -q -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done
auto trimmed 0 chars
Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -q -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done
user-error: No further undo information [2 times]
auto trimmed 0 chars
Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -q -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done
Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -q -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done
Tramp: Opening connection for vagrant@localhost using ssh...
Tramp: Sending command ‘exec ssh -q -l vagrant -p 2222 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none localhost’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘localhost’
Tramp: Opening connection for vagrant@localhost using ssh...done

Help connecting with these steps

Here is a list of the commands I run

    > cd ~/vagrant-test
    > vagrant init hashicorp/precise32
    # This gets created.
    
    > vagrant global-status
    af19297  default virtualbox running ~/vagrant-test      

Then in emacs

    C-x C-f /vagrant:af19297
    File not found and directory write-protected

I also try

    C-x C-f /vagrant:af19297|sudo:af19297:/home/vagrant RET
    Tramp: Waiting for prompts from remote shell...failed
    Tramp: Opening connection for root@af19297 using sudo...failed
    tramp-signal-hook-function: Tramp failed to connect.  If this happens repeatedly, try
        ‘M-x tramp-cleanup-this-connection’
    Quit

What steps am I missing?

vagrant-tramp can't find second running VM

I'm having some trouble getting vagrant-tramp to find my second running VM. Tested with minimal Emacs:

emacs -Q
M-x load-library /path/to/vagrant-tramp.el
M-x ido-mode
M-: (vagrant-tramp-enable)

I have two Vagrant VMs running, called e.g. vm1 and vm2. I can vagrant ssh into either of them with no problems.

I try to find a file in the second VM with C-x C-f /vagrant:. At this point, it prompts me for both VMs, as it should. I start typing and select the second:

Find file: /vagrant:vm2: [Confirm]

When I type a / at that point, it begins a Tramp connection, as I would expect. However, after navigating around the filesystem, I find that it did not actually connect me to the second VM, as I requested, but to the first one.

I can workaround this by halting the first VM, but it would be nice if I didn't have to do that.

Any idea why this happens?

Vagrant global-status parsing broken

Here's an example of my vagrant global-status --machine-readable:

➜  vagrant global-status --machine-readable            
1467524288,,ui,info,id       
1467524288,,ui,info,name      
1467524288,,ui,info,provider   
1467524288,,ui,info,state   
1467524288,,ui,info,directory                           
1467524288,,ui,info,
1467524288,,ui,info,--------------------------------------------------------------------------
1467524288,,ui,info,4f4a0f6  
1467524288,,ui,info,someproject      
1467524288,,ui,info,virtualbox 
1467524288,,ui,info,running 
1467524288,,ui,info,/home/dan/projects/someproject
1467524288,,ui,info,

vagrant-tramp--all-boxes drops the first 8 lines chopping off the id in my output. Changing it to drop 7 causes everything to start working again.

Curious if this output format is different for other versions/systems, since I've had it work on systems in the past.

Vagrant 1.8.1
Linux system 4.5.7-200.fc23.x86_64
GNU Emacs 24.5.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.18.9)

vagrant-tramp-ssh gives me no output.

So I can't get vagrant-tramp working at all. I'm pretty sure it's because of the shell script not returning any output. Unfortunately, my bash isn't very strong.

See this output:

bash -x /Users/jonathan.hill/.emacs.d/elpa/vagrant-tramp-20140709.814/bin/vagrant-tramp-ssh
++ uname -s
+ '[' Darwin == Darwin ']'
+ '[' -d '/Applications/VMWare Fusion.app' ']'
+ type=fusion
+ PATH='/Applications/VMware Fusion.app/Contents/Library:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
+ '[' '' == '' ']'
+ vm_func=vm_list
+ '[' fusion == virtualbox ']'
++ vmrun -T fusion list
++ grep vmx
+ for vmx in '$(vmrun -T $type list | grep vmx)'
++ vm_dir /Users/jonathan.hill/DEVDBVM/DEVDBVM.vmx
++++ dirname /Users/jonathan.hill/DEVDBVM/DEVDBVM.vmx
+++ dirname /Users/jonathan.hill/DEVDBVM
++ dir=/Users/jonathan.hill
++ '[' /Users/jonathan.hill '!=' / ']'
++ '[' -e /Users/jonathan.hill/Vagrantfile ']'
+++ dirname /Users/jonathan.hill
++ dir=/Users
++ '[' /Users '!=' / ']'
++ '[' -e /Users/Vagrantfile ']'
+++ dirname /Users
++ dir=/
++ '[' / '!=' / ']'
+ dir=
+ '[' '' '!=' '' ']'
bash-3.2$ 

Any suggestions would be helpful.

--jonathan

Trash in completion if vboxdrv kernel module is not loaded

The output of VBoxManage is not parsed correctly when vboxdrv kernel
module is not loaded at:

  for vm_running in $(VBoxManage list runningvms [...]

Unfortunately VBoxManage is not script friendly.
Errors are printed on stdin and the exitcode does not reflect the error:

 annotate-output +'' VBoxManage list runningvms
 I: Started VBoxManage list runningvms
 O: WARNING: The vboxdrv kernel module is not loaded. Either there is no module
 O:          available for the current kernel (4.1.0ors+) or it failed to
 O:          load. Please recompile the kernel module and install it by
 O: 
 O:            sudo /etc/init.d/vboxdrv setup
 O: 
 O:          You will not be able to start VMs until this problem is fixed.
 I: Finished with exitcode 0
VBoxManage --version
10:33:28 O: 4.3.28r100309

Maybe is better to check if vboxdrv is loaded before?

Host name must not match method "vagrant" when trying to use tramp /vagrant:

This looks like a very interesting project and I'm excited to try it out! The vagrant ssh works great for me with my multi-VM vagrant environment, but using tramp to open files within the VM doesn't seem to work in my setup.

I'm trying this with VMware fusion 6.0.3 and emacs 24.3 on Mac OSX. I've started emacs with a minimal setup only to include vagrant-tramp's package.

Here's how I reproduced this:

I switch the current directory in emacs to my project directory, "~/vm/mongo2" which contains a Vagrantfile with a bunch of VM's in it. I have a VM running called "shard1" and vagrant-tramp-term connects to it fine, and works great!

I was trying to do a find-file via tramp on the VM instance using the tramp notation /vagrant: but as soon as I type that in, I see:

Host name must not match method "vagrant"

The output of the shell script "vagrant-tramp-ssh" shows me it detected the directory name and the running instance name; it shows "mongo2-shard1" as the return result.

Thanks again for contributing this! I'm really interested in getting this working for me as it will be a huge time-saver, how can I help?

Update: including my Vagrantfile: https://gist.github.com/11548231

Find Vagrantfile by NFS shared folders?

I have the default vagrant share disabled, and share the top-level directory via NFS. For example:

config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder '.', '/opt/source', type: :nfs

Therefore this virtual machine doesn't show up in the list of available virtual machines. Does Virtualbox provide another way to locate the directory that contains the Vagrantfile besides the list of built-in shared directories?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.