# Copyright 2011 Quanta Research Cambridge, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
"""A class to store the state of various persistent objects in the Nova | |
cluster, e.g. instances, volumes. Use methods to query to state which than | |
can be compared to the current state of the objects in Nova""" | |
class State(object): | |
def __init__(self, **kwargs): | |
self._max_vms = kwargs.get('max_vms', 32) | |
self._instances = {} | |
self._volumes = {} | |
# machine state methods | |
def get_instances(self): | |
"""return the instances dictionary that we believe are in cluster.""" | |
return self._instances | |
def get_max_instances(self): | |
"""return the maximum number of instances we can create.""" | |
return self._max_vms | |
def set_instance_state(self, key, val): | |
"""Store `val` in the dictionary indexed at `key`.""" | |
self._instances[key] = val | |
def delete_instance_state(self, key): | |
"""Delete state indexed at `key`.""" | |
del self._instances[key] |