| 1 | # | ||||||||||
| 2 | # (c) Oleg Hardt <litwol@litwol.com> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | package Rex::Virtualization::Lxc::attach; | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Rex::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Rex::Helper::Run; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 16 | 0 | my ( $class, $name, %opt ) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 0 | my $opts = \%opt; | |||||||||
| 19 | 0 | $opts->{name} = $name; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | unless ($opts) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | die("You have to define the attach options!"); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | my $options = _format_opts($opts); | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $attach_command = "lxc-attach $options"; | |||||||||
| 28 | |||||||||||
| 29 | 0 | i_run $attach_command, fail_ok => 1; | |||||||||
| 30 | 0 | ▶ | if ( $? != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | die("Error running \"$attach_command\""); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | return $opts->{newname}; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub _format_opts { | ||||||||
|
Subroutine
_format_opts: not called CC=3 SCAR=24.8
| |||||||||||
| 38 | 0 | my ($opts) = @_; | |||||||||
| 39 | |||||||||||
| 40 | # -n, --name="" | ||||||||||
| 41 | # Assign the specified name to the container to be attached to. | ||||||||||
| 42 | 0 | ▶ | if ( !exists $opts->{"name"} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | die("You have to give a name."); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | my $str = "-n $opts->{'name'}"; | |||||||||
| 47 | |||||||||||
| 48 | # -B, --backingstorage=backingstorage | ||||||||||
| 49 | # backingstorage type for the container | ||||||||||
| 50 | 0 | ▶ | if ( !exists $opts->{command} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | die("You have to specify a COMMAND"); | |||||||||
| 52 | } | ||||||||||
| 53 | 0 | $str .= " -- $opts->{command}"; | |||||||||
| 54 | |||||||||||
| 55 | 0 | return $str; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 1 | 1; | |||||||||