summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Willey <todd@rubidine.com>2010-06-29 01:02:48 -0400
committerTodd Willey <todd@rubidine.com>2010-06-29 01:02:48 -0400
commit3972cf90c2982ea906fe91c6ae461d3fab7c8958 (patch)
treeab3a3fa6b83bf893a04adca2f342936c1cca3ba6
parentfcab63e31676938e6a691499caa1a3c3c5a84037 (diff)
Get rid of RedisModel
-rw-r--r--nova/compute/model.py2
-rw-r--r--nova/compute/network.py36
-rw-r--r--nova/datastore.py86
-rw-r--r--nova/volume/storage.py21
4 files changed, 36 insertions, 109 deletions
diff --git a/nova/compute/model.py b/nova/compute/model.py
index eb7b33f50..4cd851088 100644
--- a/nova/compute/model.py
+++ b/nova/compute/model.py
@@ -287,6 +287,8 @@ class BasicModel(object):
"""
# TODO(ja): implement hmset in redis-py and use it
# instead of multiple calls to hset
+ if self.is_new_record():
+ self["create_time"] = utils.isotime()
for key, val in self.state.iteritems():
# if (not self.initial_state.has_key(key)
# or self.initial_state[key] != val):
diff --git a/nova/compute/network.py b/nova/compute/network.py
index 0e5ff9b70..7b37cde6d 100644
--- a/nova/compute/network.py
+++ b/nova/compute/network.py
@@ -154,14 +154,6 @@ class BaseNetwork(model.BasicModel):
def default_state(self):
return {'network_id': self.network_id, 'network_str': self.network_str}
-# NOTE(todd): Unused?
-# @classmethod
-# def get_all_hosts(cls):
-# for vlan in Vlan.all():
-# network_str = vlan.subnet()
-# for host in model.Host.associated_to("network", network_str):
-# yield host
-
@classmethod
def create(cls, user_id, project_id, security_group, vlan, network_str):
network_id = "%s:%s" % (project_id, security_group)
@@ -282,6 +274,8 @@ class BridgedNetwork(BaseNetwork):
netmask
"""
+ override_type = 'network'
+
@classmethod
def get_network_for_project(cls, user_id, project_id, security_group):
vlan = get_vlan_for_project(project_id)
@@ -309,6 +303,7 @@ class DHCPNetwork(BridgedNetwork):
dhcp_range_end: the last ip to give out
"""
bridge_gets_ip = True
+ override_type = 'network'
def __init__(self, *args, **kwargs):
super(DHCPNetwork, self).__init__(*args, **kwargs)
@@ -318,6 +313,10 @@ class DHCPNetwork(BridgedNetwork):
self.dhcp_range_end = self.network[-(1 + FLAGS.cnt_vpn_clients)]
try:
os.makedirs(FLAGS.networks_path)
+ # NOTE(todd): I guess this is a lazy way to not have to check if the
+ # directory exists, but shouldn't we be smarter about
+ # telling the difference between existing directory and
+ # permission denied? (Errno 17 vs 13, OSError)
except Exception, err:
pass
@@ -352,26 +351,34 @@ class DHCPNetwork(BridgedNetwork):
else:
linux_net.start_dnsmasq(self)
-class PublicAddress(datastore.RedisModel):
- object_type="address"
+class PublicAddress(model.BasicModel):
+ override_type = "address"
def __init__(self, address):
- super(PublicAddress, self).__init__(address)
+ self.address = address
+ super(PublicAddress, self).__init__()
+
+ @property
+ def identifier(self):
+ return self.address
+
+ def default_state(self):
+ return {'address': self.address}
@classmethod
def create(cls, user_id, project_id, address):
- addr = cls(address=address)
- addr['address'] = address
+ addr = cls(address)
addr['user_id'] = user_id
addr['project_id'] = project_id
addr['instance_id'] = 'available'
addr['private_ip'] = 'available'
- addr["create_time"] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
addr.save()
return addr
DEFAULT_PORTS = [("tcp",80), ("tcp",22), ("udp",1194), ("tcp",443)]
class PublicNetworkController(BaseNetwork):
+ override_type = 'network'
+
def __init__(self, *args, **kwargs):
network_id = "public:default"
super(PublicNetworkController, self).__init__(network_id, FLAGS.public_range)
@@ -476,7 +483,6 @@ class PublicNetworkController(BaseNetwork):
# FIXME(todd): does this present a race condition, or is there some piece of
# architecture that mitigates it (only one queue listener per net)?
-# TODO(todd): probably make this a class method on Vlan
def get_vlan_for_project(project_id):
"""
Allocate vlan IDs to individual users.
diff --git a/nova/datastore.py b/nova/datastore.py
index 6b8a01ca5..5a9b80c62 100644
--- a/nova/datastore.py
+++ b/nova/datastore.py
@@ -66,92 +66,6 @@ class Redis(object):
return cls._instance
-class RedisModel(object):
- """ Wrapper around redis-backed properties """
- object_type = 'generic'
- def __init__(self, object_id):
- """ loads an object from the datastore if exists """
- self.object_id = object_id
- self.initial_state = {}
- self.state = Redis.instance().hgetall(self.__redis_key)
- if self.state:
- self.initial_state = self.state
- else:
- self.set_default_state()
-
- def set_default_state(self):
- self.state = {'state': 0,
- 'state_description': 'pending',
- 'node_name': 'unassigned',
- 'project_id': 'unassigned',
- 'user_id': 'unassigned'}
- self.state[self.object_type+"_id"] = self.object_id
- self.state["create_time"] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
-
- @property
- def project(self):
- if self.state.get('project_id', None):
- return self.state['project_id']
- return self.state.get('owner_id', 'unassigned')
-
- @property
- def __redis_key(self):
- """ Magic string for keys """
- return '%s:%s' % (self.object_type, self.object_id)
-
- def __repr__(self):
- return "<%s:%s>" % (self.object_type, self.object_id)
-
- def __str__(self):
- return str(self.state)
-
- def keys(self):
- return self.state.keys()
-
- def copy(self):
- copyDict = {}
- for item in self.keys():
- copyDict[item] = self[item]
- return copyDict
-
- def get(self, item, default):
- return self.state.get(item, default)
-
- def __getitem__(self, item):
- return self.state[item]
-
- def __setitem__(self, item, val):
- self.state[item] = val
- return self.state[item]
-
- def __delitem__(self, item):
- """ We don't support this """
- raise Exception("Silly monkey, we NEED all our properties.")
-
- def save(self):
- """ update the directory with the state from this instance """
- # TODO(ja): implement hmset in redis-py and use it
- # instead of multiple calls to hset
- for key, val in self.state.iteritems():
- # if (not self.initial_state.has_key(key)
- # or self.initial_state[key] != val):
- Redis.instance().hset(self.__redis_key, key, val)
- if self.initial_state == {}:
- self.first_save()
- self.initial_state = self.state
- return True
-
- def first_save(self):
- pass
-
- def destroy(self):
- """ deletes all related records from datastore.
- does NOT do anything to running state.
- """
- Redis.instance().delete(self.__redis_key)
- return True
-
-
def slugify(key, prefix=None):
"""
Key has to be a valid filename. Slugify solves that.
diff --git a/nova/volume/storage.py b/nova/volume/storage.py
index 9c58358bd..273a6afd1 100644
--- a/nova/volume/storage.py
+++ b/nova/volume/storage.py
@@ -41,6 +41,7 @@ from nova import flags
from nova import rpc
from nova import utils
from nova import validate
+from nova.compute import model
FLAGS = flags.FLAGS
@@ -151,18 +152,23 @@ class FakeBlockStore(BlockStore):
pass
-class Volume(datastore.RedisModel):
-
- object_type = 'volume'
+class Volume(model.BasicModel):
def __init__(self, volume_id=None):
- super(Volume, self).__init__(object_id=volume_id)
+ self.volume_id = volume_id
+ super(Volume, self).__init__()
+
+ @property
+ def identifier(self):
+ self.volume_id
+
+ def default_state(self):
+ return {"volume_id": self.volume_id}
@classmethod
def create(cls, size, user_id, project_id):
volume_id = utils.generate_uid('vol')
- vol = cls(volume_id=volume_id)
- vol['volume_id'] = volume_id
+ vol = cls(volume_id)
vol['node_name'] = FLAGS.storage_name
vol['size'] = size
vol['user_id'] = user_id
@@ -171,7 +177,6 @@ class Volume(datastore.RedisModel):
vol["instance_id"] = 'none'
vol["mountpoint"] = 'none'
vol['attach_time'] = 'none'
- vol["create_time"] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
vol['status'] = "creating" # creating | available | in-use
vol['attach_status'] = "detached" # attaching | attached | detaching | detached
vol['delete_on_termination'] = 'False'
@@ -190,7 +195,7 @@ class Volume(datastore.RedisModel):
self['mountpoint'] = mountpoint
self['status'] = "in-use"
self['attach_status'] = "attaching"
- self['attach_time'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
+ self['attach_time'] = utils.utctime()
self['delete_on_termination'] = 'False'
self.save()