本文整理汇总了Python中scalarizr.storage2.volume函数的典型用法代码示例。如果您正苦于以下问题:Python volume函数的具体用法?Python volume怎么用?Python volume使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了volume函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: on_host_init_response
def on_host_init_response(self, hir):
LOG.info('Configuring block device mountpoints')
with bus.initialization_op as op:
with op.phase(self._phase_plug_volume):
wait_until(self._plug_all_volumes, sleep=10, timeout=600,
error_text='Cannot attach and mount disks in a reasonable time')
volumes = hir.body.get('volumes') or []
if volumes:
LOG.debug('HIR volumes: %s', volumes)
for i in range(0, len(volumes)):
vol = volumes[i]
template = vol.pop('template', None)
from_template_if_missing = vol.pop('from_template_if_missing', None)
vol = storage2.volume(**vol)
LOG.info('Ensuring %s volume %s', vol.type, dict(vol))
try:
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
except storage2.VolumeNotExistsError, e:
if template and from_template_if_missing == '1':
vol = storage2.volume(**template)
LOG.warn('Volume %s not exists, re-creating %s volume from config: %s',
str(e), vol.type, dict(vol))
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
else:
raise
self._volumes.append(dict(vol))
开发者ID:notbrain,项目名称:scalarizr,代码行数:28,代码来源:block_device.py
示例2: _ensure
def _ensure(self):
# snap should be applied after layout: download and extract data.
# this could be done on already ensured volume.
# Example: resync slave data
if not self._lvm_volume:
if isinstance(self.disk, basestring) and \
self.disk.startswith('/dev/sd'):
self.disk = storage2.volume(
type='ec2_ephemeral',
name='ephemeral0')
self._lvm_volume = storage2.volume(
type='lvm',
pvs=[self.disk],
size=self.size + 'VG',
vg=self.vg,
name='data')
self._lvm_volume.ensure()
self.device = self._lvm_volume.device
if self.snap:
self.snap = storage2.snapshot(self.snap)
self.mkfs()
tmp_mpoint = not self.mpoint
if tmp_mpoint:
tmp_mpoint = tempfile.mkdtemp()
self.mpoint = tmp_mpoint
transfer = cloudfs.LargeTransfer(self.snap.path, self.mpoint + '/')
try:
self.mount()
if hasattr(self.snap, 'size'):
df_info = filetool.df()
df = filter(lambda x: x.mpoint == self.mpoint, df_info)[0]
if df.free < self.snap.size:
raise storage2.StorageError('Not enough free space'
' on device %s to restore snapshot.' %
self.device)
transfer.run()
except:
e = sys.exc_info()[1]
raise storage2.StorageError("Snapshot restore error: %s" % e)
finally:
try:
self.umount()
finally:
if tmp_mpoint:
self.mpoint = None
os.rmdir(tmp_mpoint)
self.snap = None
开发者ID:golovast,项目名称:scalarizr,代码行数:53,代码来源:eph.py
示例3: on_host_init_response
def on_host_init_response(self, message):
with bus.initialization_op as op:
with op.phase(self._phase_rabbitmq):
with op.step(self._step_accept_scalr_conf):
if not message.body.has_key("rabbitmq"):
raise HandlerError("HostInitResponse message for RabbitMQ behaviour must have 'rabbitmq' property")
rabbitmq_data = message.rabbitmq.copy()
if not rabbitmq_data['password']:
rabbitmq_data['password'] = cryptotool.pwgen(10)
hostname = RABBIT_HOSTNAME_TPL % int(message.server_index)
rabbitmq_data['server_index'] = message.server_index
rabbitmq_data['hostname'] = hostname
dns.ScalrHosts.set('127.0.0.1', hostname)
with open('/etc/hostname', 'w') as f:
f.write(hostname)
system2(('hostname', '-F', '/etc/hostname'))
volume_config = rabbitmq_data.pop('volume_config')
volume_config['mpoint'] = DEFAULT_STORAGE_PATH
rabbitmq_data['volume'] = storage2.volume(volume_config)
rabbitmq_data['volume'].tags = self.rabbitmq_tags
__rabbitmq__.update(rabbitmq_data)
开发者ID:yoyama,项目名称:scalarizr,代码行数:28,代码来源:rabbitmq.py
示例4: ensure
def ensure(self, mount=False, mkfs=False, fstab=True, **updates):
"""
Make sure that volume is attached and ready for use.
:param mount: if set, volume eventually will be mounted to it's mpoint
:param mkfs: if set, volume will have corresponding fs eventually
:return:
"""
if not self.features['restore']:
self._check_restore_unsupported()
if self.snap and isinstance(self.snap, Snapshot):
self.snap = self.snap.config()
try:
self._ensure()
except storage2.VolumeNotExistsError, e:
LOG.debug("recreate_if_missing: %s" % self.recreate_if_missing)
if self.recreate_if_missing:
LOG.warning(e)
LOG.info('Volume %s not exists, re-creating %s from template', self.id, self.type)
template = self.clone()
vol = storage2.volume(**dict(template))
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
self._config = vol.config()
else:
raise
开发者ID:chenleji,项目名称:scalarizr,代码行数:25,代码来源:base.py
示例5: _destroy
def _destroy(self, force, **kwds):
remove_disks = kwds.get('remove_disks')
if remove_disks:
for disk in self.disks:
disk = storage2.volume(disk)
disk.destroy(force=force)
self.disks = []
开发者ID:notbrain,项目名称:scalarizr,代码行数:7,代码来源:raid.py
示例6: _plug_new_style_volumes
def _plug_new_style_volumes(self, volumes):
for vol in volumes:
vol = storage2.volume(**vol)
vol.tags.update(build_tags())
self._log_ensure_volume(vol)
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
self._volumes.append(dict(vol))
开发者ID:chenleji,项目名称:scalarizr,代码行数:7,代码来源:block_device.py
示例7: replace_disk
def replace_disk(self, index, disk):
'''
:param: index RAID disk index. Starts from 0
:type index: int
:param: disk Replacement disk.
:type: disk dict/Volume
'''
disk_replace = storage2.volume(disk)
replace_is_new = not disk_replace.id
try:
disk_replace.ensure()
disk_find = self.disks[index]
mdadm.mdadm('manage', self.raid_pv, '--fail', disk_find.device)
mdadm.mdadm('manage', self.raid_pv, '--remove', disk_find.device)
mdadm.mdadm('manage', self.raid_pv, '--add', disk_replace.device)
self.disks[index] = disk_replace
except:
with util.capture_exception(logger=LOG):
if replace_is_new:
disk_replace.destroy(force=True)
else:
disk_find.destroy(force=True)
开发者ID:chenleji,项目名称:scalarizr,代码行数:26,代码来源:raid.py
示例8: _plug_volume
def _plug_volume(self, qe_mpoint):
try:
assert len(qe_mpoint.volumes), 'Invalid mpoint info %s. Volumes list is empty' % qe_mpoint
qe_volume = qe_mpoint.volumes[0]
mpoint = qe_mpoint.dir or None
assert qe_volume.volume_id, 'Invalid volume info %s. volume_id should be non-empty' % qe_volume
vol = storage2.volume(
type=self._vol_type,
id=qe_volume.volume_id,
name=qe_volume.device,
mpoint=mpoint
)
if mpoint:
def block():
vol.ensure(mount=True, mkfs=True, fstab=True)
bus.fire("block_device_mounted",
volume_id=vol.id, device=vol.device)
if bus.initialization_op:
msg = 'Mount device %s to %s' % (vol.device, vol.mpoint)
with bus.initialization_op.step(msg):
block()
else:
block()
except:
LOG.exception("Can't attach volume")
开发者ID:notbrain,项目名称:scalarizr,代码行数:29,代码来源:block_device.py
示例9: clone
def clone(self):
config = self._config.copy()
config.pop('id', None)
config.pop('fscreated', None)
config.pop('device', None)
self._clone(config)
return storage2.volume(config)
开发者ID:notbrain,项目名称:scalarizr,代码行数:7,代码来源:base.py
示例10: on_before_host_up
def on_before_host_up(self, message):
LOG.debug("on_before_host_up")
"""
Configure MySQL __mysql__['behavior']
@type message: scalarizr.messaging.Message
@param message: HostUp message
"""
self.generate_datadir()
self.mysql.service.stop('Configuring MySQL')
# On Debian/GCE we've got 'Another MySQL daemon already running with the same unix socket.'
socket_file = mysql2_svc.my_print_defaults('mysqld').get('socket')
if socket_file:
coreutils.remove(socket_file)
if 'Amazon' == linux.os['name']:
self.mysql.my_cnf.pid_file = os.path.join(__mysql__['data_dir'], 'mysqld.pid')
repl = 'master' if int(__mysql__['replication_master']) else 'slave'
bus.fire('before_mysql_configure', replication=repl)
if repl == 'master':
self._init_master(message)
else:
self._init_slave(message)
# Force to resave volume settings
__mysql__['volume'] = storage2.volume(__mysql__['volume'])
bus.fire('service_configured', service_name=__mysql__['behavior'],
replication=repl, preset=self.initial_preset)
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:29,代码来源:mysql2.py
示例11: _run
def _run(self):
self.volume = storage2.volume(self.volume)
LOG.debug("Volume obj: %s", self.volume)
LOG.debug("Volume config: %s", dict(self.volume))
state = {}
self.fire("freeze", self.volume, state)
try:
snap = self.volume.snapshot(self.description, tags=self.tags)
finally:
self.fire("unfreeze", self.volume, state)
try:
util.wait_until(
lambda: snap.status() in (snap.COMPLETED, snap.FAILED),
start_text="Polling snapshot status (%s)" % snap.id,
logger=LOG,
)
except:
if "Request limit exceeded" in str(sys.exc_info()[1]):
pass
else:
raise
if snap.status() == snap.FAILED:
msg = "Backup failed because snapshot %s failed" % snap.id
raise Error(msg)
return restore(type=self.type, snapshot=snap, **state)
开发者ID:chenleji,项目名称:scalarizr,代码行数:25,代码来源:backup.py
示例12: check_growth
def check_growth(self, **growth):
if int(self.level) in (0, 10):
raise storage2.StorageError("Raid%s doesn't support growth" % self.level)
disk_growth = growth.get('disks')
change_disks = False
if disk_growth:
for disk_cfg_or_obj in self.disks:
disk = storage2.volume(disk_cfg_or_obj)
try:
disk.check_growth(**disk_growth)
change_disks = True
except storage2.NoOpError:
pass
new_len = growth.get('disks_count')
current_len = len(self.disks)
change_size = new_len and int(new_len) != current_len
if not change_size and not change_disks:
raise storage2.NoOpError('Configurations are equal. Nothing to do')
if change_size and int(new_len) < current_len:
raise storage2.StorageError('Disk count can only be increased.')
if change_size and int(self.level) in (0, 10):
raise storage2.StorageError("Can't add disks to raid level %s"
% self.level)
开发者ID:notbrain,项目名称:scalarizr,代码行数:29,代码来源:raid.py
示例13: _snapshot
def _snapshot(self, description, tags, **kwds):
lvm_snap = self._lvm_volume.lvm_snapshot(size='100%FREE')
try:
snap = storage2.snapshot(type='eph')
snap.path = os.path.join(os.path.join(
self.cloudfs_dir, snap.id + '.manifest.ini'))
lvm_snap_vol = storage2.volume(
device=lvm_snap.device,
mpoint=tempfile.mkdtemp())
lvm_snap_vol.ensure(mount=True)
df_info = filetool.df()
df = filter(lambda x: x.mpoint == lvm_snap_vol.mpoint, df_info)
snap.size = df[0].used
try:
transfer = cloudfs.LargeTransfer(
src=lvm_snap_vol.mpoint + '/',
dst=snap.path,
tar_it=True,
gzip_it=True,
tags=tags)
transfer.run()
finally:
lvm_snap_vol.umount()
os.rmdir(lvm_snap_vol.mpoint)
finally:
lvm_snap.destroy()
return snap
开发者ID:golovast,项目名称:scalarizr,代码行数:32,代码来源:eph.py
示例14: _plug_volume
def _plug_volume(self, qe_mpoint):
try:
assert len(qe_mpoint.volumes), 'Invalid mpoint info %s. Volumes list is empty' % qe_mpoint
qe_volume = qe_mpoint.volumes[0]
mpoint = qe_mpoint.dir or None
assert qe_volume.volume_id, 'Invalid volume info %s. volume_id should be non-empty' % qe_volume
vol = storage2.volume(
type=self._vol_type,
id=qe_volume.volume_id,
name=qe_volume.device,
mpoint=mpoint
)
if mpoint:
logger = bus.init_op.logger if bus.init_op else LOG
logger.info('Ensure %s: take %s, mount to %s', self._vol_type, vol.id, vol.mpoint)
vol.ensure(mount=True, mkfs=True, fstab=True)
bus.fire("block_device_mounted",
volume_id=vol.id, device=vol.device)
self.send_message(Messages.BLOCK_DEVICE_MOUNTED,
{"device_name": vol.device,
"volume_id": vol.id,
"mountpoint": vol.mpoint}
)
except:
LOG.exception("Can't attach volume")
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:28,代码来源:block_device.py
示例15: _plug_new_style_volumes
def _plug_new_style_volumes(self, volumes):
for vol in volumes:
template = vol.pop('template', None)
from_template_if_missing = vol.pop('from_template_if_missing', False)
vol = storage2.volume(**vol)
self._log_ensure_volume(vol)
try:
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
except storage2.VolumeNotExistsError, e:
if template and bool(int(from_template_if_missing)):
LOG.warn('Volume %s not exists, re-creating %s from template',
str(e), vol.type)
vol = storage2.volume(**template)
self._log_ensure_volume(vol)
vol.ensure(mount=bool(vol.mpoint), mkfs=True)
else:
raise
self._volumes.append(dict(vol))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:18,代码来源:block_device.py
示例16: do_grow
def do_grow(op):
vol = storage2.volume(volume)
self._mysql_init.stop('Growing data volume')
try:
growed_vol = vol.grow(**growth)
__mysql__['volume'] = dict(growed_vol)
return dict(growed_vol)
finally:
self._mysql_init.start()
开发者ID:chenleji,项目名称:scalarizr,代码行数:9,代码来源:mysql.py
示例17: do_grow
def do_grow(op):
vol = storage2.volume(volume)
self.stop_service(reason='Growing data volume')
try:
grown_vol = vol.grow(**growth)
postgresql_svc.__postgresql__['volume'] = dict(grown_vol)
return dict(grown_vol)
finally:
self.start_service()
开发者ID:chenleji,项目名称:scalarizr,代码行数:9,代码来源:postgresql.py
示例18: _clone
def _clone(self, config):
disks = []
for disk_cfg_or_obj in self.disks:
disk = storage2.volume(disk_cfg_or_obj)
disk_clone = disk.clone()
disks.append(disk_clone)
config['disks'] = disks
for attr in ('pv_uuid', 'lvm_group_cfg', 'raid_pv', 'device'):
config.pop(attr, None)
开发者ID:notbrain,项目名称:scalarizr,代码行数:10,代码来源:raid.py
示例19: on_ConvertVolume
def on_ConvertVolume(self, message):
try:
if __node__['state'] != 'running':
raise HandlerError('scalarizr is not in "running" state')
old_volume = storage2.volume(__mysql__['volume'])
new_volume = storage2.volume(message.volume)
if old_volume.type != 'eph' or new_volume.type != 'lvm':
raise HandlerError('%s to %s convertation unsupported.' %
(old_volume.type, new_volume.type))
new_volume.ensure()
__mysql__.update({'volume': new_volume})
except:
e = sys.exc_info()[1]
LOG.error('Volume convertation failed: %s' % e)
self.send_message(MysqlMessages.CONVERT_VOLUME_RESULT,
dict(status='error', last_error=str(e)))
开发者ID:AnyBucket,项目名称:scalarizr,代码行数:19,代码来源:mysql2.py
示例20: on_BeforeHostTerminate
def on_BeforeHostTerminate(self, message):
LOG.debug('Handling BeforeHostTerminate message from %s' % message.local_ip)
#assert message.local_ip
if message.local_ip == __node__['private_ip']:
self.mysql.service.stop(reason='Server will be terminated')
LOG.info('Detaching MySQL storage')
vol = storage2.volume(__mysql__['volume'])
vol.detach()
if not int(__mysql__['replication_master']):
LOG.info('Destroying volume %s', vol.id)
vol.destroy(remove_disks=True)
LOG.info('Volume %s has been destroyed.' % vol.id)
开发者ID:golovast,项目名称:scalarizr,代码行数:13,代码来源:mysql2.py
注:本文中的scalarizr.storage2.volume函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论