mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-08 01:40:31 +00:00
Access fsm states directly
This commit is contained in:
parent
fb0fa1e94e
commit
1bf61770d9
7 changed files with 10 additions and 21 deletions
|
@ -19,7 +19,7 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
super(AbstractPartitionMap, self).__init__(cfg)
|
super(AbstractPartitionMap, self).__init__(cfg)
|
||||||
|
|
||||||
def is_blocking(self):
|
def is_blocking(self):
|
||||||
return self.is_state('mapped')
|
return self.fsm.current == 'mapped'
|
||||||
|
|
||||||
def get_total_size(self):
|
def get_total_size(self):
|
||||||
return sum(p.size for p in self.partitions) + 1
|
return sum(p.size for p in self.partitions) + 1
|
||||||
|
@ -54,12 +54,12 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
self.partitions[p_idx].map(partition_path)
|
self.partitions[p_idx].map(partition_path)
|
||||||
|
|
||||||
for idx, partition in enumerate(self.partitions):
|
for idx, partition in enumerate(self.partitions):
|
||||||
if not partition.is_state('mapped'):
|
if partition.fsm.current not in ['mapped', 'formatted']:
|
||||||
raise PartitionError('kpartx did not map partition #{idx}'.format(idx=idx+1))
|
raise PartitionError('kpartx did not map partition #{idx}'.format(idx=idx+1))
|
||||||
|
|
||||||
except PartitionError as e:
|
except PartitionError as e:
|
||||||
for partition in self.partitions:
|
for partition in self.partitions:
|
||||||
if not partition.is_state('mapped'):
|
if not partition.fsm.can('unmap'):
|
||||||
partition.unmap()
|
partition.unmap()
|
||||||
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
||||||
raise e
|
raise e
|
||||||
|
@ -70,7 +70,7 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
def _before_unmap(self, event):
|
def _before_unmap(self, event):
|
||||||
volume = event.volume
|
volume = event.volume
|
||||||
for partition in self.partitions:
|
for partition in self.partitions:
|
||||||
if partition.is_state('mounted'):
|
if partition.fsm.cannot('unmap'):
|
||||||
msg = 'The partition {partition} prevents the unmap procedure'.format(partition=partition)
|
msg = 'The partition {partition} prevents the unmap procedure'.format(partition=partition)
|
||||||
raise PartitionError(msg)
|
raise PartitionError(msg)
|
||||||
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
||||||
|
|
|
@ -9,7 +9,7 @@ class NoPartitions(object):
|
||||||
self.partitions = [self.root]
|
self.partitions = [self.root]
|
||||||
|
|
||||||
def is_blocking(self):
|
def is_blocking(self):
|
||||||
return self.root.is_state('mounted')
|
return self.root.fsm == 'mounted'
|
||||||
|
|
||||||
def get_total_size(self):
|
def get_total_size(self):
|
||||||
return self.root.size
|
return self.root.size
|
||||||
|
|
|
@ -3,7 +3,5 @@ from abstract import AbstractPartition
|
||||||
|
|
||||||
class SinglePartition(AbstractPartition):
|
class SinglePartition(AbstractPartition):
|
||||||
|
|
||||||
initial_state = 'created'
|
|
||||||
|
|
||||||
def _before_create(self, e):
|
def _before_create(self, e):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Volume(FSMProxy):
|
||||||
self.partition_map.root.create()
|
self.partition_map.root.create()
|
||||||
|
|
||||||
def can_mount_specials(self):
|
def can_mount_specials(self):
|
||||||
return self.is_state('attached')
|
return self.fsm.current == 'attached'
|
||||||
|
|
||||||
def mount_specials(self):
|
def mount_specials(self):
|
||||||
if self.specials_mounted:
|
if self.specials_mounted:
|
||||||
|
|
|
@ -20,7 +20,7 @@ class LoopbackVolume(Volume):
|
||||||
extension = 'raw'
|
extension = 'raw'
|
||||||
|
|
||||||
def can_mount_specials(self):
|
def can_mount_specials(self):
|
||||||
return self.is_state('attached') or self.is_state('linked')
|
return self.fsm.current in ['attached', 'linked']
|
||||||
|
|
||||||
def create(self, image_path):
|
def create(self, image_path):
|
||||||
self.fsm.create(image_path=image_path)
|
self.fsm.create(image_path=image_path)
|
||||||
|
|
|
@ -9,15 +9,6 @@ class FSMProxy(object):
|
||||||
self.fsm = Fysom(cfg)
|
self.fsm = Fysom(cfg)
|
||||||
self.attach_proxy_methods(self.fsm, events)
|
self.attach_proxy_methods(self.fsm, events)
|
||||||
|
|
||||||
def is_state(self, event):
|
|
||||||
return self.fsm.isstate(event)
|
|
||||||
|
|
||||||
def set_state(self, event):
|
|
||||||
self.fsm.current = event
|
|
||||||
|
|
||||||
def get_state(self):
|
|
||||||
return self.fsm.current
|
|
||||||
|
|
||||||
def collect_event_listeners(self, events, callbacks):
|
def collect_event_listeners(self, events, callbacks):
|
||||||
callbacks = callbacks.copy()
|
callbacks = callbacks.copy()
|
||||||
callback_names = []
|
callback_names = []
|
||||||
|
|
|
@ -67,7 +67,7 @@ class CreateFromImage(Task):
|
||||||
|
|
||||||
|
|
||||||
def set_fs_states(volume):
|
def set_fs_states(volume):
|
||||||
volume.set_state('detached')
|
volume.fsm.current = 'detached'
|
||||||
|
|
||||||
p_map = volume.partition_map
|
p_map = volume.partition_map
|
||||||
partitions_state = 'attached'
|
partitions_state = 'attached'
|
||||||
|
@ -75,7 +75,7 @@ def set_fs_states(volume):
|
||||||
if isinstance(p_map, NoPartitions):
|
if isinstance(p_map, NoPartitions):
|
||||||
partitions_state = 'formatted'
|
partitions_state = 'formatted'
|
||||||
else:
|
else:
|
||||||
p_map.set_state('unmapped')
|
p_map.fsm.current = 'unmapped'
|
||||||
partitions_state = 'unmapped_fmt'
|
partitions_state = 'unmapped_fmt'
|
||||||
for partition in p_map.partitions:
|
for partition in p_map.partitions:
|
||||||
partition.set_state(partitions_state)
|
partition.fsm.current = partitions_state
|
||||||
|
|
Loading…
Add table
Reference in a new issue