2013-09-18 00:46:58 +02:00
|
|
|
from abstract import AbstractPartition
|
2013-09-15 13:19:45 +02:00
|
|
|
|
|
|
|
|
2013-09-18 00:46:58 +02:00
|
|
|
class BasePartition(AbstractPartition):
|
2013-09-15 13:19:45 +02:00
|
|
|
|
|
|
|
events = [{'name': 'create', 'src': 'nonexistent', 'dst': 'unmapped'},
|
|
|
|
{'name': 'map', 'src': 'unmapped', 'dst': 'mapped'},
|
|
|
|
{'name': 'format', 'src': 'mapped', 'dst': 'formatted'},
|
|
|
|
{'name': 'mount', 'src': 'formatted', 'dst': 'mounted'},
|
|
|
|
{'name': 'unmount', 'src': 'mounted', 'dst': 'formatted'},
|
|
|
|
{'name': 'unmap', 'src': 'formatted', 'dst': 'unmapped_fmt'},
|
2013-09-22 21:20:09 +02:00
|
|
|
|
|
|
|
{'name': 'map', 'src': 'unmapped_fmt', 'dst': 'formatted'},
|
2013-09-15 13:19:45 +02:00
|
|
|
{'name': 'unmap', 'src': 'mapped', 'dst': 'unmapped'},
|
|
|
|
]
|
|
|
|
|
2013-09-22 21:20:09 +02:00
|
|
|
def __init__(self, size, filesystem, previous):
|
2013-09-15 13:19:45 +02:00
|
|
|
self.previous = previous
|
2013-09-22 21:20:09 +02:00
|
|
|
super(BasePartition, self).__init__(size, filesystem)
|
|
|
|
|
2013-10-09 00:09:34 +02:00
|
|
|
def create(self, volume):
|
|
|
|
self.fsm.create(volume=volume)
|
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
def get_index(self):
|
|
|
|
if self.previous is None:
|
|
|
|
return 1
|
|
|
|
else:
|
2013-12-14 19:37:23 +01:00
|
|
|
return self.previous.get_index() + 1
|
2013-09-15 13:19:45 +02:00
|
|
|
|
|
|
|
def get_start(self):
|
|
|
|
if self.previous is None:
|
2013-10-08 23:12:03 +02:00
|
|
|
return 0
|
2013-09-15 13:19:45 +02:00
|
|
|
else:
|
|
|
|
return self.previous.get_start() + self.previous.size
|
|
|
|
|
|
|
|
def map(self, device_path):
|
|
|
|
self.fsm.map(device_path=device_path)
|
|
|
|
|
2013-09-22 21:20:09 +02:00
|
|
|
def _before_map(self, e):
|
2013-09-15 13:19:45 +02:00
|
|
|
self.device_path = e.device_path
|
|
|
|
|
2013-09-22 21:20:09 +02:00
|
|
|
def _before_unmap(self, e):
|
2013-09-15 13:19:45 +02:00
|
|
|
self.device_path = None
|