Sean Dague | 7011236 | 2012-04-03 13:48:49 -0400 | [diff] [blame] | 1 | # Copyright 2011 Quanta Research Cambridge, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | """A class to store the state of various persistent objects in the Nova |
| 15 | cluster, e.g. instances, volumes. Use methods to query to state which than |
| 16 | can be compared to the current state of the objects in Nova""" |
| 17 | |
| 18 | |
| 19 | class State(object): |
| 20 | |
| 21 | def __init__(self, **kwargs): |
| 22 | self._max_vms = kwargs.get('max_vms', 32) |
| 23 | self._instances = {} |
| 24 | self._volumes = {} |
| 25 | |
| 26 | # machine state methods |
| 27 | def get_instances(self): |
| 28 | """return the instances dictionary that we believe are in cluster.""" |
| 29 | return self._instances |
| 30 | |
| 31 | def get_max_instances(self): |
| 32 | """return the maximum number of instances we can create.""" |
| 33 | return self._max_vms |
| 34 | |
| 35 | def set_instance_state(self, key, val): |
| 36 | """Store `val` in the dictionary indexed at `key`.""" |
| 37 | self._instances[key] = val |
| 38 | |
| 39 | def delete_instance_state(self, key): |
| 40 | """Delete state indexed at `key`.""" |
| 41 | del self._instances[key] |