first version of __dog_vdi
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								ff8f7ac287
							
						
					
				
			
			
				commit
				
					
						b22b581b67
					
				
			
		
					 6 changed files with 81 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -1,19 +1,42 @@
 | 
			
		|||
################################################################################
 | 
			
		||||
# State: absent is handled by manifest - we need only to do stuff if image is
 | 
			
		||||
# not existing and state != absent
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
#
 | 
			
		||||
state="$(cat "$__object/parameter/state")"
 | 
			
		||||
[ "$state" = "absent" ] && exit 0
 | 
			
		||||
 | 
			
		||||
exists="$(cat "$__object/explorer/exists")"
 | 
			
		||||
[ "$exists" ] && exit 0
 | 
			
		||||
 | 
			
		||||
################################################################################
 | 
			
		||||
# Still there? Create image
 | 
			
		||||
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
 | 
			
		||||
#
 | 
			
		||||
# This file is part of cdist.
 | 
			
		||||
#
 | 
			
		||||
# cdist is free software: you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of the GNU General Public License as published by
 | 
			
		||||
# the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
# (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# cdist is distributed in the hope that it will be useful,
 | 
			
		||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
# GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
format="$(cat "$__object/parameter/format")"
 | 
			
		||||
size="$(cat "$__object/parameter/size")"
 | 
			
		||||
diskimage="/$__object_id"
 | 
			
		||||
state_should="$(cat "$__object/parameter/state")"
 | 
			
		||||
num_vdi_lines=$(wc -l < "$__object/explorer/list")
 | 
			
		||||
name="$__object_id"
 | 
			
		||||
 | 
			
		||||
echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\"
 | 
			
		||||
 | 
			
		||||
if [ "$num_vdi_lines" = 1 ]; then
 | 
			
		||||
    state_is=present
 | 
			
		||||
else
 | 
			
		||||
    state_is=absent
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
[ "$state_is" = "$state_should" ] && exit 0
 | 
			
		||||
 | 
			
		||||
case "$state_should" in
 | 
			
		||||
    present)
 | 
			
		||||
        size="$(cat "$__object/parameter/size")"
 | 
			
		||||
        echo "dog vdi create '$name' '$size'"
 | 
			
		||||
    ;;
 | 
			
		||||
    absent)
 | 
			
		||||
        echo "dog vdi delete '$name'"
 | 
			
		||||
    ;;
 | 
			
		||||
esac
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,20 +10,19 @@ cdist-type__dog_vdi - Manage Sheepdog VM images
 | 
			
		|||
 | 
			
		||||
DESCRIPTION
 | 
			
		||||
-----------
 | 
			
		||||
The dog program is used to create qemu images for
 | 
			
		||||
qemu and (qemu-)kvm.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
REQUIRED PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
size::
 | 
			
		||||
    Size of the image in dog vdi compatible units.
 | 
			
		||||
The dog program is used to create images for sheepdog
 | 
			
		||||
to be used in qemu.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
OPTIONAL PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
state::
 | 
			
		||||
    Either "present" or "absent", defaults to "present"
 | 
			
		||||
size::
 | 
			
		||||
    Size of the image in dog vdi compatible units.
 | 
			
		||||
 | 
			
		||||
    Required if state == present.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
EXAMPLES
 | 
			
		||||
| 
						 | 
				
			
			@ -33,8 +32,14 @@ EXAMPLES
 | 
			
		|||
# Create a 50G size image
 | 
			
		||||
__dog_vdi nico-privat.sky.ungleich.ch --size 50G
 | 
			
		||||
 | 
			
		||||
# Create a 50G size image (more explicit)
 | 
			
		||||
__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state present
 | 
			
		||||
 | 
			
		||||
# Remove image
 | 
			
		||||
__dog_vdi nico-privat.sky.ungleich.ch --state absent
 | 
			
		||||
 | 
			
		||||
# Remove image - keeping --size is ok
 | 
			
		||||
__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state absent
 | 
			
		||||
--------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +47,7 @@ SEE ALSO
 | 
			
		|||
--------
 | 
			
		||||
- cdist-type(7)
 | 
			
		||||
- dog(8)
 | 
			
		||||
- qemu(1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
COPYING
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										28
									
								
								cdist/conf/type/__dog_vdi/manifest
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								cdist/conf/type/__dog_vdi/manifest
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
#!/bin/sh
 | 
			
		||||
#
 | 
			
		||||
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
 | 
			
		||||
#
 | 
			
		||||
# This file is part of cdist.
 | 
			
		||||
#
 | 
			
		||||
# cdist is free software: you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of the GNU General Public License as published by
 | 
			
		||||
# the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
# (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# cdist is distributed in the hope that it will be useful,
 | 
			
		||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
# GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
state_should="$(cat "$__object/parameter/state")"
 | 
			
		||||
 | 
			
		||||
if [ "$state_should" = "present" ]; then
 | 
			
		||||
    if [ ! -f "$__object/parameter/size" ]; then
 | 
			
		||||
        echo "Size is required when state is present" >&2
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
qcow2
 | 
			
		||||
| 
						 | 
				
			
			@ -1,2 +1,2 @@
 | 
			
		|||
format
 | 
			
		||||
state
 | 
			
		||||
size
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
size
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue