Last active
September 9, 2016 08:16
-
-
Save florianpaquet/1ef74056605f67b1a90c to your computer and use it in GitHub Desktop.
My custom lxc aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom visudo entries : | |
# ----------------------- | |
# Defaults:florian env_keep=HTTP_PROXY | |
# %florian ALL = NOPASSWD: /usr/bin/lxc-* | |
# Starts a container | |
function cstart() { | |
for container in "$@" | |
do | |
sudo lxc-start -n $container -d | |
done | |
} | |
# Stops a container | |
function cstop() { | |
for container in "$@" | |
do | |
sudo lxc-stop -n $container | |
done | |
} | |
# Creates a container | |
function ccreate() { | |
sudo HTTP_PROXY=apt lxc-create -t ubuntu -n $1 -- -r trusty -a amd64 --packages bash-completion --auth-key ~/.ssh/id_rsa.pub | |
} | |
# Lists containers | |
function cls() { | |
sudo lxc-ls -f | |
} | |
# Logs in a container | |
function clog() { | |
ssh ubuntu@$(cip $1) | |
} | |
# Returns a container IP | |
function cip() { | |
sudo lxc-ls -f | grep "^$1\>" | tr -s ' ' | cut -d ' ' -f5 | |
} | |
# Completion | |
_lxc-stopped() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(sudo lxc-ls --stopped)" -- $cur) ) | |
} | |
complete -F _lxc-stopped cstart | |
_lxc-active() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "$(sudo lxc-ls --active)" -- $cur) ) | |
} | |
complete -F _lxc-active cstop | |
complete -F _lxc-active clog | |
complete -F _lxc-active cip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment