Package virtualization :: Module state
[hide private]
[frames] | no frames]

Source Code for Module virtualization.state

 1  # 
 2  # Copyright (c) 2008--2013 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  from virtualization.constants import StateType 
17   
18  ############################################################################### 
19  # Classes 
20  ############################################################################### 
21   
22 -class State:
23 """ 24 This class represents the state of a virtual instance. It provides 25 abstraction to categorize the state into running, stopped, paused, or 26 crashed. 27 """ 28
29 - def __init__(self, state_type):
30 """ 31 Create a new state. If state_type is None, this state is assumed to be 32 stopped. If state_type is not None, it must be a StateType type. 33 """ 34 self.__state_type = state_type
35
36 - def get_state_type(self):
37 """ 38 Returns the state type used to create this instance. 39 """ 40 return self.__state_type
41
42 - def is_running(self):
43 """ 44 Returns true if this object represents a running state. 45 """ 46 return self.__state_type == StateType.NOSTATE or \ 47 self.__state_type == StateType.RUNNING or \ 48 self.__state_type == StateType.BLOCKED or \ 49 self.__state_type == StateType.SHUTDOWN
50
51 - def is_paused(self):
52 """ 53 Returns true if this object represents a paused instance. 54 """ 55 return self.__state_type == StateType.PAUSED
56
57 - def is_stopped(self):
58 """ 59 Returns true if this object represents a stopped instance. 60 """ 61 return self.__state_type == None or \ 62 self.__state_type == StateType.SHUTOFF
63
64 - def is_crashed(self):
65 """ 66 Returns true if this object represents a crashed instance. 67 """ 68 return self.__state_type == StateType.CRASHED
69