Remove seed functions from qemu_nbd

This commit is contained in:
Thomas S Hatch 2013-02-26 14:31:25 -07:00
parent 5e76213ba4
commit 2feeabf08a

View File

@ -118,77 +118,3 @@ def clear(mnt):
return ret
def seed(location, id_='', config=None):
'''
Make sure that the image at the given location is mounted, salt is
installed, keys are seeded, and execute a state run
CLI Example::
salt '*' qemu.seed /tmp/image.qcow2
'''
if config is None:
config = {}
mnt = init(location)
mpt = mnt.keys()[0]
mpt_tmp = os.path.join(mpt, 'tmp')
__salt__['mount.mount'](
os.path.join(mpt, 'dev'),
'udev',
fstype='devtmpfs')
# Verify that the boostrap script is downloaded
bs_ = gather_bootstrap_script()
# Apply the minion config
# Generate the minion's key
salt.crypt.gen_keys(mpt_tmp, 'minion', 2048)
# TODO Send the key to the master for approval
# Execute chroot routine
sh_ = '/bin/sh'
if os.path.isfile(os.path.join(mpt, 'bin/bash')):
sh_ = '/bin/bash'
# Copy script into tmp
shutil.copy(bs_, os.path.join(mpt, 'tmp'))
if not 'master' in config:
config['master'] = __opts__['master']
if id_:
config['id'] = id_
with open(os.path.join(mpt_tmp, 'minion'), 'w+') as fp_:
fp_.write(yaml.dump(config, default_flow_style=False))
# Generate the chroot command
c_cmd = 'sh /tmp/bootstrap.sh'
cmd = 'chroot {0} {1} -c \'{2}\''.format(
mpt,
sh_,
c_cmd)
__salt__['cmd.run'](cmd)
__salt__['mount.umount'](os.path.join(mpt, 'dev'))
clear(mnt)
def bootstrap(location, size, fmt):
'''
HIGHLY EXPERIMENTAL
Bootstrap a virtual machine image
location:
The location to create the image
size:
The size of the image to create in megabytes
fmt:
The image format, raw or qcow2
CLI Example::
salt '*' qemu_nbd.bootstrap /srv/salt-images/host.qcow 4096 qcow2
'''
location = __salt__['qemu_img.make_image'](location, size, fmt)
if not location:
return ''
nbd = connect(location)
__salt__['partition.mklabel'](nbd, 'msdos')
__salt__['partition.mkpart'](nbd, 'primary', 'ext4', 1, -1)
__salt__['partition.probe'](nbd)
__salt__['partition.mkfs']('{0}p1'.format(nbd), 'ext4')
mnt = mount(nbd)
#return __salt__['pkg.bootstrap'](nbd, mnt.keys()[0])