Merge lp:~eday/nova/pep8-fixes-other into lp:~hudson-openstack/nova/trunk

Proposed by Eric Day
Status: Merged
Approved by: Eric Day
Approved revision: 379
Merged at revision: 379
Proposed branch: lp:~eday/nova/pep8-fixes-other
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~eday/nova/pep8-fixes-db
Diff against target: 1598 lines (+274/-236)
24 files modified
nova/auth/dbdriver.py (+27/-24)
nova/auth/fakeldap.py (+5/-6)
nova/auth/ldapdriver.py (+7/-5)
nova/auth/manager.py (+1/-1)
nova/cloudpipe/pipelib.py (+19/-11)
nova/compute/disk.py (+7/-8)
nova/compute/monitor.py (+52/-61)
nova/compute/power_state.py (+6/-7)
nova/image/service.py (+9/-8)
nova/image/services/glance/__init__.py (+4/-4)
nova/network/linux_net.py (+7/-3)
nova/network/manager.py (+2/-3)
nova/objectstore/bucket.py (+12/-8)
nova/objectstore/handler.py (+12/-9)
nova/objectstore/image.py (+23/-18)
nova/objectstore/stored.py (+2/-2)
nova/scheduler/driver.py (+2/-0)
nova/scheduler/manager.py (+2/-1)
nova/scheduler/simple.py (+1/-0)
nova/virt/fake.py (+1/-0)
nova/virt/images.py (+2/-2)
nova/virt/libvirt_conn.py (+56/-41)
nova/virt/xenapi.py (+15/-13)
nova/volume/driver.py (+0/-1)
To merge this branch: bzr merge lp:~eday/nova/pep8-fixes-other
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+39111@code.launchpad.net

Description of the change

Another pep8 cleanup branch for nova/*, should be merged after lp:~eday/nova/pep8-fixes-db.

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

194 -import string # pylint: disable-msg=W0402
195 +import string # pylint: disable-msg=W0402

114 -SCOPE_ONELEVEL = 1 # not implemented
115 +SCOPE_ONELEVEL = 1 # Not implemented

Not sure what the "fix" is for the above comments... is there a PEP8 requirement for >1 space between a code line and a comment?

Other than that, looks good.

review: Needs Information
Revision history for this message
Eric Day (eday) wrote :

Yup, you get a message like:
bin/nova-manage:56:15: E261 at least two spaces before inline comment

Revision history for this message
Jay Pipes (jaypipes) wrote :

Heh, interesting. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/auth/dbdriver.py'
--- nova/auth/dbdriver.py 2010-10-14 05:18:01 +0000
+++ nova/auth/dbdriver.py 2010-10-22 00:19:41 +0000
@@ -47,19 +47,23 @@
4747
48 def get_user(self, uid):48 def get_user(self, uid):
49 """Retrieve user by id"""49 """Retrieve user by id"""
50 return self._db_user_to_auth_user(db.user_get(context.get_admin_context(), uid))50 user = db.user_get(context.get_admin_context(), uid)
51 return self._db_user_to_auth_user(user)
5152
52 def get_user_from_access_key(self, access):53 def get_user_from_access_key(self, access):
53 """Retrieve user by access key"""54 """Retrieve user by access key"""
54 return self._db_user_to_auth_user(db.user_get_by_access_key(context.get_admin_context(), access))55 user = db.user_get_by_access_key(context.get_admin_context(), access)
56 return self._db_user_to_auth_user(user)
5557
56 def get_project(self, pid):58 def get_project(self, pid):
57 """Retrieve project by id"""59 """Retrieve project by id"""
58 return self._db_project_to_auth_projectuser(db.project_get(context.get_admin_context(), pid))60 project = db.project_get(context.get_admin_context(), pid)
61 return self._db_project_to_auth_projectuser(project)
5962
60 def get_users(self):63 def get_users(self):
61 """Retrieve list of users"""64 """Retrieve list of users"""
62 return [self._db_user_to_auth_user(user) for user in db.user_get_all(context.get_admin_context())]65 return [self._db_user_to_auth_user(user)
66 for user in db.user_get_all(context.get_admin_context())]
6367
64 def get_projects(self, uid=None):68 def get_projects(self, uid=None):
65 """Retrieve list of projects"""69 """Retrieve list of projects"""
@@ -71,11 +75,10 @@
7175
72 def create_user(self, name, access_key, secret_key, is_admin):76 def create_user(self, name, access_key, secret_key, is_admin):
73 """Create a user"""77 """Create a user"""
74 values = { 'id' : name,78 values = {'id': name,
75 'access_key' : access_key,79 'access_key': access_key,
76 'secret_key' : secret_key,80 'secret_key': secret_key,
77 'is_admin' : is_admin81 'is_admin': is_admin}
78 }
79 try:82 try:
80 user_ref = db.user_create(context.get_admin_context(), values)83 user_ref = db.user_create(context.get_admin_context(), values)
81 return self._db_user_to_auth_user(user_ref)84 return self._db_user_to_auth_user(user_ref)
@@ -83,18 +86,19 @@
83 raise exception.Duplicate('User %s already exists' % name)86 raise exception.Duplicate('User %s already exists' % name)
8487
85 def _db_user_to_auth_user(self, user_ref):88 def _db_user_to_auth_user(self, user_ref):
86 return { 'id' : user_ref['id'],89 return {'id': user_ref['id'],
87 'name' : user_ref['id'],90 'name': user_ref['id'],
88 'access' : user_ref['access_key'],91 'access': user_ref['access_key'],
89 'secret' : user_ref['secret_key'],92 'secret': user_ref['secret_key'],
90 'admin' : user_ref['is_admin'] }93 'admin': user_ref['is_admin']}
9194
92 def _db_project_to_auth_projectuser(self, project_ref):95 def _db_project_to_auth_projectuser(self, project_ref):
93 return { 'id' : project_ref['id'],96 member_ids = [member['id'] for member in project_ref['members']]
94 'name' : project_ref['name'],97 return {'id': project_ref['id'],
95 'project_manager_id' : project_ref['project_manager'],98 'name': project_ref['name'],
96 'description' : project_ref['description'],99 'project_manager_id': project_ref['project_manager'],
97 'member_ids' : [member['id'] for member in project_ref['members']] }100 'description': project_ref['description'],
101 'member_ids': member_ids}
98102
99 def create_project(self, name, manager_uid,103 def create_project(self, name, manager_uid,
100 description=None, member_uids=None):104 description=None, member_uids=None):
@@ -121,10 +125,10 @@
121 % member_uid)125 % member_uid)
122 members.add(member)126 members.add(member)
123127
124 values = { 'id' : name,128 values = {'id': name,
125 'name' : name,129 'name': name,
126 'project_manager' : manager['id'],130 'project_manager': manager['id'],
127 'description': description }131 'description': description}
128132
129 try:133 try:
130 project = db.project_create(context.get_admin_context(), values)134 project = db.project_create(context.get_admin_context(), values)
@@ -244,4 +248,3 @@
244 if not project:248 if not project:
245 raise exception.NotFound('Project "%s" not found' % project_id)249 raise exception.NotFound('Project "%s" not found' % project_id)
246 return user, project250 return user, project
247
248251
=== modified file 'nova/auth/fakeldap.py'
--- nova/auth/fakeldap.py 2010-10-14 13:07:37 +0000
+++ nova/auth/fakeldap.py 2010-10-22 00:19:41 +0000
@@ -35,6 +35,7 @@
35 'Port that redis is running on.')35 'Port that redis is running on.')
36flags.DEFINE_integer('redis_db', 0, 'Multiple DB keeps tests away')36flags.DEFINE_integer('redis_db', 0, 'Multiple DB keeps tests away')
3737
38
38class Redis(object):39class Redis(object):
39 def __init__(self):40 def __init__(self):
40 if hasattr(self.__class__, '_instance'):41 if hasattr(self.__class__, '_instance'):
@@ -51,19 +52,19 @@
5152
5253
53SCOPE_BASE = 054SCOPE_BASE = 0
54SCOPE_ONELEVEL = 1 # not implemented55SCOPE_ONELEVEL = 1 # Not implemented
55SCOPE_SUBTREE = 256SCOPE_SUBTREE = 2
56MOD_ADD = 057MOD_ADD = 0
57MOD_DELETE = 158MOD_DELETE = 1
58MOD_REPLACE = 259MOD_REPLACE = 2
5960
6061
61class NO_SUCH_OBJECT(Exception): # pylint: disable-msg=C010362class NO_SUCH_OBJECT(Exception): # pylint: disable-msg=C0103
62 """Duplicate exception class from real LDAP module."""63 """Duplicate exception class from real LDAP module."""
63 pass64 pass
6465
6566
66class OBJECT_CLASS_VIOLATION(Exception): # pylint: disable-msg=C010367class OBJECT_CLASS_VIOLATION(Exception): # pylint: disable-msg=C0103
67 """Duplicate exception class from real LDAP module."""68 """Duplicate exception class from real LDAP module."""
68 pass69 pass
6970
@@ -251,8 +252,6 @@
251 return objects252 return objects
252253
253 @property254 @property
254 def __redis_prefix(self): # pylint: disable-msg=R0201255 def __redis_prefix(self): # pylint: disable-msg=R0201
255 """Get the prefix to use for all redis keys."""256 """Get the prefix to use for all redis keys."""
256 return 'ldap:'257 return 'ldap:'
257
258
259258
=== modified file 'nova/auth/ldapdriver.py'
--- nova/auth/ldapdriver.py 2010-09-25 03:32:00 +0000
+++ nova/auth/ldapdriver.py 2010-10-22 00:19:41 +0000
@@ -294,24 +294,26 @@
294294
295 def __find_dns(self, dn, query=None, scope=None):295 def __find_dns(self, dn, query=None, scope=None):
296 """Find dns by query"""296 """Find dns by query"""
297 if scope is None: # one of the flags is 0!!297 if scope is None:
298 # One of the flags is 0!
298 scope = self.ldap.SCOPE_SUBTREE299 scope = self.ldap.SCOPE_SUBTREE
299 try:300 try:
300 res = self.conn.search_s(dn, scope, query)301 res = self.conn.search_s(dn, scope, query)
301 except self.ldap.NO_SUCH_OBJECT:302 except self.ldap.NO_SUCH_OBJECT:
302 return []303 return []
303 # just return the DNs304 # Just return the DNs
304 return [dn for dn, _attributes in res]305 return [dn for dn, _attributes in res]
305306
306 def __find_objects(self, dn, query=None, scope=None):307 def __find_objects(self, dn, query=None, scope=None):
307 """Find objects by query"""308 """Find objects by query"""
308 if scope is None: # one of the flags is 0!!309 if scope is None:
310 # One of the flags is 0!
309 scope = self.ldap.SCOPE_SUBTREE311 scope = self.ldap.SCOPE_SUBTREE
310 try:312 try:
311 res = self.conn.search_s(dn, scope, query)313 res = self.conn.search_s(dn, scope, query)
312 except self.ldap.NO_SUCH_OBJECT:314 except self.ldap.NO_SUCH_OBJECT:
313 return []315 return []
314 # just return the attributes316 # Just return the attributes
315 return [attributes for dn, attributes in res]317 return [attributes for dn, attributes in res]
316318
317 def __find_role_dns(self, tree):319 def __find_role_dns(self, tree):
@@ -480,6 +482,6 @@
480class FakeLdapDriver(LdapDriver):482class FakeLdapDriver(LdapDriver):
481 """Fake Ldap Auth driver"""483 """Fake Ldap Auth driver"""
482484
483 def __init__(self): # pylint: disable-msg=W0231485 def __init__(self): # pylint: disable-msg=W0231
484 __import__('nova.auth.fakeldap')486 __import__('nova.auth.fakeldap')
485 self.ldap = sys.modules['nova.auth.fakeldap']487 self.ldap = sys.modules['nova.auth.fakeldap']
486488
=== modified file 'nova/auth/manager.py'
--- nova/auth/manager.py 2010-10-15 15:18:40 +0000
+++ nova/auth/manager.py 2010-10-22 00:19:41 +0000
@@ -23,7 +23,7 @@
23import logging23import logging
24import os24import os
25import shutil25import shutil
26import string # pylint: disable-msg=W040226import string # pylint: disable-msg=W0402
27import tempfile27import tempfile
28import uuid28import uuid
29import zipfile29import zipfile
3030
=== modified file 'nova/cloudpipe/pipelib.py'
--- nova/cloudpipe/pipelib.py 2010-10-01 12:57:17 +0000
+++ nova/cloudpipe/pipelib.py 2010-10-22 00:19:41 +0000
@@ -49,7 +49,7 @@
49 self.manager = manager.AuthManager()49 self.manager = manager.AuthManager()
5050
51 def launch_vpn_instance(self, project_id):51 def launch_vpn_instance(self, project_id):
52 logging.debug( "Launching VPN for %s" % (project_id))52 logging.debug("Launching VPN for %s" % (project_id))
53 project = self.manager.get_project(project_id)53 project = self.manager.get_project(project_id)
54 # Make a payload.zip54 # Make a payload.zip
55 tmpfolder = tempfile.mkdtemp()55 tmpfolder = tempfile.mkdtemp()
@@ -57,16 +57,18 @@
57 zippath = os.path.join(tmpfolder, filename)57 zippath = os.path.join(tmpfolder, filename)
58 z = zipfile.ZipFile(zippath, "w", zipfile.ZIP_DEFLATED)58 z = zipfile.ZipFile(zippath, "w", zipfile.ZIP_DEFLATED)
5959
60 z.write(FLAGS.boot_script_template,'autorun.sh')60 z.write(FLAGS.boot_script_template, 'autorun.sh')
61 z.close()61 z.close()
6262
63 key_name = self.setup_key_pair(project.project_manager_id, project_id)63 key_name = self.setup_key_pair(project.project_manager_id, project_id)
64 zippy = open(zippath, "r")64 zippy = open(zippath, "r")
65 context = context.RequestContext(user=project.project_manager, project=project)65 context = context.RequestContext(user=project.project_manager,
66 project=project)
6667
67 reservation = self.controller.run_instances(context,68 reservation = self.controller.run_instances(context,
68 # run instances expects encoded userdata, it is decoded in the get_metadata_call69 # Run instances expects encoded userdata, it is decoded in the
69 # autorun.sh also decodes the zip file, hence the double encoding70 # get_metadata_call. autorun.sh also decodes the zip file, hence
71 # the double encoding.
70 user_data=zippy.read().encode("base64").encode("base64"),72 user_data=zippy.read().encode("base64").encode("base64"),
71 max_count=1,73 max_count=1,
72 min_count=1,74 min_count=1,
@@ -79,12 +81,14 @@
79 def setup_key_pair(self, user_id, project_id):81 def setup_key_pair(self, user_id, project_id):
80 key_name = '%s%s' % (project_id, FLAGS.vpn_key_suffix)82 key_name = '%s%s' % (project_id, FLAGS.vpn_key_suffix)
81 try:83 try:
82 private_key, fingerprint = self.manager.generate_key_pair(user_id, key_name)84 private_key, fingerprint = self.manager.generate_key_pair(user_id,
85 key_name)
83 try:86 try:
84 key_dir = os.path.join(FLAGS.keys_path, user_id)87 key_dir = os.path.join(FLAGS.keys_path, user_id)
85 if not os.path.exists(key_dir):88 if not os.path.exists(key_dir):
86 os.makedirs(key_dir)89 os.makedirs(key_dir)
87 with open(os.path.join(key_dir, '%s.pem' % key_name),'w') as f:90 file_name = os.path.join(key_dir, '%s.pem' % key_name)
91 with open(file_name, 'w') as f:
88 f.write(private_key)92 f.write(private_key)
89 except:93 except:
90 pass94 pass
@@ -95,9 +99,13 @@
95 # def setup_secgroups(self, username):99 # def setup_secgroups(self, username):
96 # conn = self.euca.connection_for(username)100 # conn = self.euca.connection_for(username)
97 # try:101 # try:
98 # secgroup = conn.create_security_group("vpn-secgroup", "vpn-secgroup")102 # secgroup = conn.create_security_group("vpn-secgroup",
99 # secgroup.authorize(ip_protocol = "udp", from_port = "1194", to_port = "1194", cidr_ip = "0.0.0.0/0")103 # "vpn-secgroup")
100 # secgroup.authorize(ip_protocol = "tcp", from_port = "80", to_port = "80", cidr_ip = "0.0.0.0/0")104 # secgroup.authorize(ip_protocol = "udp", from_port = "1194",
101 # secgroup.authorize(ip_protocol = "tcp", from_port = "22", to_port = "22", cidr_ip = "0.0.0.0/0")105 # to_port = "1194", cidr_ip = "0.0.0.0/0")
106 # secgroup.authorize(ip_protocol = "tcp", from_port = "80",
107 # to_port = "80", cidr_ip = "0.0.0.0/0")
108 # secgroup.authorize(ip_protocol = "tcp", from_port = "22",
109 # to_port = "22", cidr_ip = "0.0.0.0/0")
102 # except:110 # except:
103 # pass111 # pass
104112
=== modified file 'nova/compute/disk.py'
--- nova/compute/disk.py 2010-10-18 20:40:03 +0000
+++ nova/compute/disk.py 2010-10-22 00:19:41 +0000
@@ -72,12 +72,12 @@
72 " by sector size: %d / %d", local_bytes, sector_size)72 " by sector size: %d / %d", local_bytes, sector_size)
73 local_sectors = local_bytes / sector_size73 local_sectors = local_bytes / sector_size
7474
75 mbr_last = 62 # a75 mbr_last = 62 # a
76 primary_first = mbr_last + 1 # b76 primary_first = mbr_last + 1 # b
77 primary_last = primary_first + primary_sectors - 1 # c77 primary_last = primary_first + primary_sectors - 1 # c
78 local_first = primary_last + 1 # d78 local_first = primary_last + 1 # d
79 local_last = local_first + local_sectors - 1 # e79 local_last = local_first + local_sectors - 1 # e
80 last_sector = local_last # e80 last_sector = local_last # e
8181
82 # create an empty file82 # create an empty file
83 yield execute('dd if=/dev/zero of=%s count=1 seek=%d bs=%d'83 yield execute('dd if=/dev/zero of=%s count=1 seek=%d bs=%d'
@@ -157,7 +157,7 @@
157@defer.inlineCallbacks157@defer.inlineCallbacks
158def _inject_key_into_fs(key, fs, execute=None):158def _inject_key_into_fs(key, fs, execute=None):
159 sshdir = os.path.join(os.path.join(fs, 'root'), '.ssh')159 sshdir = os.path.join(os.path.join(fs, 'root'), '.ssh')
160 yield execute('sudo mkdir -p %s' % sshdir) # existing dir doesn't matter160 yield execute('sudo mkdir -p %s' % sshdir) # existing dir doesn't matter
161 yield execute('sudo chown root %s' % sshdir)161 yield execute('sudo chown root %s' % sshdir)
162 yield execute('sudo chmod 700 %s' % sshdir)162 yield execute('sudo chmod 700 %s' % sshdir)
163 keyfile = os.path.join(sshdir, 'authorized_keys')163 keyfile = os.path.join(sshdir, 'authorized_keys')
@@ -169,4 +169,3 @@
169 netfile = os.path.join(os.path.join(os.path.join(169 netfile = os.path.join(os.path.join(os.path.join(
170 fs, 'etc'), 'network'), 'interfaces')170 fs, 'etc'), 'network'), 'interfaces')
171 yield execute('sudo tee %s' % netfile, net)171 yield execute('sudo tee %s' % netfile, net)
172
173172
=== modified file 'nova/compute/monitor.py'
--- nova/compute/monitor.py 2010-08-16 12:16:21 +0000
+++ nova/compute/monitor.py 2010-10-22 00:19:41 +0000
@@ -85,8 +85,7 @@
85 'RRA:MAX:0.5:6:800',85 'RRA:MAX:0.5:6:800',
86 'RRA:MAX:0.5:24:800',86 'RRA:MAX:0.5:24:800',
87 'RRA:MAX:0.5:444:800',87 'RRA:MAX:0.5:444:800',
88 ]88 ]}
89 }
9089
9190
92utcnow = datetime.datetime.utcnow91utcnow = datetime.datetime.utcnow
@@ -97,15 +96,12 @@
97 Updates the specified RRD file.96 Updates the specified RRD file.
98 """97 """
99 filename = os.path.join(instance.get_rrd_path(), '%s.rrd' % name)98 filename = os.path.join(instance.get_rrd_path(), '%s.rrd' % name)
100 99
101 if not os.path.exists(filename):100 if not os.path.exists(filename):
102 init_rrd(instance, name)101 init_rrd(instance, name)
103 102
104 timestamp = int(time.mktime(utcnow().timetuple()))103 timestamp = int(time.mktime(utcnow().timetuple()))
105 rrdtool.update (104 rrdtool.update(filename, '%d:%s' % (timestamp, data))
106 filename,
107 '%d:%s' % (timestamp, data)
108 )
109105
110106
111def init_rrd(instance, name):107def init_rrd(instance, name):
@@ -113,29 +109,28 @@
113 Initializes the specified RRD file.109 Initializes the specified RRD file.
114 """110 """
115 path = os.path.join(FLAGS.monitoring_rrd_path, instance.instance_id)111 path = os.path.join(FLAGS.monitoring_rrd_path, instance.instance_id)
116 112
117 if not os.path.exists(path):113 if not os.path.exists(path):
118 os.makedirs(path)114 os.makedirs(path)
119 115
120 filename = os.path.join(path, '%s.rrd' % name)116 filename = os.path.join(path, '%s.rrd' % name)
121 117
122 if not os.path.exists(filename):118 if not os.path.exists(filename):
123 rrdtool.create (119 rrdtool.create(
124 filename,120 filename,
125 '--step', '%d' % FLAGS.monitoring_instances_step,121 '--step', '%d' % FLAGS.monitoring_instances_step,
126 '--start', '0',122 '--start', '0',
127 *RRD_VALUES[name]123 *RRD_VALUES[name])
128 )124
129125
130
131def graph_cpu(instance, duration):126def graph_cpu(instance, duration):
132 """127 """
133 Creates a graph of cpu usage for the specified instance and duration.128 Creates a graph of cpu usage for the specified instance and duration.
134 """129 """
135 path = instance.get_rrd_path()130 path = instance.get_rrd_path()
136 filename = os.path.join(path, 'cpu-%s.png' % duration)131 filename = os.path.join(path, 'cpu-%s.png' % duration)
137 132
138 rrdtool.graph (133 rrdtool.graph(
139 filename,134 filename,
140 '--disable-rrdtool-tag',135 '--disable-rrdtool-tag',
141 '--imgformat', 'PNG',136 '--imgformat', 'PNG',
@@ -146,9 +141,8 @@
146 '-l', '0',141 '-l', '0',
147 '-u', '100',142 '-u', '100',
148 'DEF:cpu=%s:cpu:AVERAGE' % os.path.join(path, 'cpu.rrd'),143 'DEF:cpu=%s:cpu:AVERAGE' % os.path.join(path, 'cpu.rrd'),
149 'AREA:cpu#eacc00:% CPU',144 'AREA:cpu#eacc00:% CPU',)
150 )145
151
152 store_graph(instance.instance_id, filename)146 store_graph(instance.instance_id, filename)
153147
154148
@@ -158,8 +152,8 @@
158 """152 """
159 path = instance.get_rrd_path()153 path = instance.get_rrd_path()
160 filename = os.path.join(path, 'net-%s.png' % duration)154 filename = os.path.join(path, 'net-%s.png' % duration)
161 155
162 rrdtool.graph (156 rrdtool.graph(
163 filename,157 filename,
164 '--disable-rrdtool-tag',158 '--disable-rrdtool-tag',
165 '--imgformat', 'PNG',159 '--imgformat', 'PNG',
@@ -174,20 +168,19 @@
174 'DEF:rx=%s:rx:AVERAGE' % os.path.join(path, 'net.rrd'),168 'DEF:rx=%s:rx:AVERAGE' % os.path.join(path, 'net.rrd'),
175 'DEF:tx=%s:tx:AVERAGE' % os.path.join(path, 'net.rrd'),169 'DEF:tx=%s:tx:AVERAGE' % os.path.join(path, 'net.rrd'),
176 'AREA:rx#00FF00:In traffic',170 'AREA:rx#00FF00:In traffic',
177 'LINE1:tx#0000FF:Out traffic',171 'LINE1:tx#0000FF:Out traffic',)
178 )172
179
180 store_graph(instance.instance_id, filename)173 store_graph(instance.instance_id, filename)
181174
182 175
183def graph_disk(instance, duration):176def graph_disk(instance, duration):
184 """177 """
185 Creates a graph of disk usage for the specified duration.178 Creates a graph of disk usage for the specified duration.
186 """ 179 """
187 path = instance.get_rrd_path()180 path = instance.get_rrd_path()
188 filename = os.path.join(path, 'disk-%s.png' % duration)181 filename = os.path.join(path, 'disk-%s.png' % duration)
189 182
190 rrdtool.graph (183 rrdtool.graph(
191 filename,184 filename,
192 '--disable-rrdtool-tag',185 '--disable-rrdtool-tag',
193 '--imgformat', 'PNG',186 '--imgformat', 'PNG',
@@ -202,9 +195,8 @@
202 'DEF:rd=%s:rd:AVERAGE' % os.path.join(path, 'disk.rrd'),195 'DEF:rd=%s:rd:AVERAGE' % os.path.join(path, 'disk.rrd'),
203 'DEF:wr=%s:wr:AVERAGE' % os.path.join(path, 'disk.rrd'),196 'DEF:wr=%s:wr:AVERAGE' % os.path.join(path, 'disk.rrd'),
204 'AREA:rd#00FF00:Read',197 'AREA:rd#00FF00:Read',
205 'LINE1:wr#0000FF:Write',198 'LINE1:wr#0000FF:Write',)
206 )199
207
208 store_graph(instance.instance_id, filename)200 store_graph(instance.instance_id, filename)
209201
210202
@@ -224,17 +216,16 @@
224 is_secure=False,216 is_secure=False,
225 calling_format=boto.s3.connection.OrdinaryCallingFormat(),217 calling_format=boto.s3.connection.OrdinaryCallingFormat(),
226 port=FLAGS.s3_port,218 port=FLAGS.s3_port,
227 host=FLAGS.s3_host219 host=FLAGS.s3_host)
228 )
229 bucket_name = '_%s.monitor' % instance_id220 bucket_name = '_%s.monitor' % instance_id
230 221
231 # Object store isn't creating the bucket like it should currently222 # Object store isn't creating the bucket like it should currently
232 # when it is first requested, so have to catch and create manually.223 # when it is first requested, so have to catch and create manually.
233 try:224 try:
234 bucket = s3.get_bucket(bucket_name)225 bucket = s3.get_bucket(bucket_name)
235 except Exception:226 except Exception:
236 bucket = s3.create_bucket(bucket_name)227 bucket = s3.create_bucket(bucket_name)
237 228
238 key = boto.s3.Key(bucket)229 key = boto.s3.Key(bucket)
239 key.key = os.path.basename(filename)230 key.key = os.path.basename(filename)
240 key.set_contents_from_filename(filename)231 key.set_contents_from_filename(filename)
@@ -247,18 +238,18 @@
247 self.last_updated = datetime.datetime.min238 self.last_updated = datetime.datetime.min
248 self.cputime = 0239 self.cputime = 0
249 self.cputime_last_updated = None240 self.cputime_last_updated = None
250 241
251 init_rrd(self, 'cpu')242 init_rrd(self, 'cpu')
252 init_rrd(self, 'net')243 init_rrd(self, 'net')
253 init_rrd(self, 'disk')244 init_rrd(self, 'disk')
254 245
255 def needs_update(self):246 def needs_update(self):
256 """247 """
257 Indicates whether this instance is due to have its statistics updated.248 Indicates whether this instance is due to have its statistics updated.
258 """249 """
259 delta = utcnow() - self.last_updated250 delta = utcnow() - self.last_updated
260 return delta.seconds >= FLAGS.monitoring_instances_step251 return delta.seconds >= FLAGS.monitoring_instances_step
261 252
262 def update(self):253 def update(self):
263 """254 """
264 Updates the instances statistics and stores the resulting graphs255 Updates the instances statistics and stores the resulting graphs
@@ -271,7 +262,7 @@
271 if data != None:262 if data != None:
272 logging.debug('CPU: %s', data)263 logging.debug('CPU: %s', data)
273 update_rrd(self, 'cpu', data)264 update_rrd(self, 'cpu', data)
274 265
275 data = self.fetch_net_stats()266 data = self.fetch_net_stats()
276 logging.debug('NET: %s', data)267 logging.debug('NET: %s', data)
277 update_rrd(self, 'net', data)268 update_rrd(self, 'net', data)
@@ -279,7 +270,7 @@
279 data = self.fetch_disk_stats()270 data = self.fetch_disk_stats()
280 logging.debug('DISK: %s', data)271 logging.debug('DISK: %s', data)
281 update_rrd(self, 'disk', data)272 update_rrd(self, 'disk', data)
282 273
283 # TODO(devcamcar): Turn these into pool.ProcessPool.execute() calls274 # TODO(devcamcar): Turn these into pool.ProcessPool.execute() calls
284 # and make the methods @defer.inlineCallbacks.275 # and make the methods @defer.inlineCallbacks.
285 graph_cpu(self, '1d')276 graph_cpu(self, '1d')
@@ -297,13 +288,13 @@
297 logging.exception('unexpected error during update')288 logging.exception('unexpected error during update')
298289
299 self.last_updated = utcnow()290 self.last_updated = utcnow()
300 291
301 def get_rrd_path(self):292 def get_rrd_path(self):
302 """293 """
303 Returns the path to where RRD files are stored.294 Returns the path to where RRD files are stored.
304 """295 """
305 return os.path.join(FLAGS.monitoring_rrd_path, self.instance_id)296 return os.path.join(FLAGS.monitoring_rrd_path, self.instance_id)
306 297
307 def fetch_cpu_stats(self):298 def fetch_cpu_stats(self):
308 """299 """
309 Returns cpu usage statistics for this instance.300 Returns cpu usage statistics for this instance.
@@ -327,17 +318,17 @@
327 # Calculate the number of seconds between samples.318 # Calculate the number of seconds between samples.
328 d = self.cputime_last_updated - cputime_last_updated319 d = self.cputime_last_updated - cputime_last_updated
329 t = d.days * 86400 + d.seconds320 t = d.days * 86400 + d.seconds
330 321
331 logging.debug('t = %d', t)322 logging.debug('t = %d', t)
332323
333 # Calculate change over time in number of nanoseconds of CPU time used.324 # Calculate change over time in number of nanoseconds of CPU time used.
334 cputime_delta = self.cputime - cputime_last325 cputime_delta = self.cputime - cputime_last
335 326
336 logging.debug('cputime_delta = %s', cputime_delta)327 logging.debug('cputime_delta = %s', cputime_delta)
337328
338 # Get the number of virtual cpus in this domain.329 # Get the number of virtual cpus in this domain.
339 vcpus = int(info['num_cpu'])330 vcpus = int(info['num_cpu'])
340 331
341 logging.debug('vcpus = %d', vcpus)332 logging.debug('vcpus = %d', vcpus)
342333
343 # Calculate CPU % used and cap at 100.334 # Calculate CPU % used and cap at 100.
@@ -349,9 +340,9 @@
349 """340 """
350 rd = 0341 rd = 0
351 wr = 0342 wr = 0
352 343
353 disks = self.conn.get_disks(self.instance_id)344 disks = self.conn.get_disks(self.instance_id)
354 345
355 # Aggregate the read and write totals.346 # Aggregate the read and write totals.
356 for disk in disks:347 for disk in disks:
357 try:348 try:
@@ -363,7 +354,7 @@
363 logging.error('Cannot get blockstats for "%s" on "%s"',354 logging.error('Cannot get blockstats for "%s" on "%s"',
364 disk, self.instance_id)355 disk, self.instance_id)
365 raise356 raise
366 357
367 return '%d:%d' % (rd, wr)358 return '%d:%d' % (rd, wr)
368359
369 def fetch_net_stats(self):360 def fetch_net_stats(self):
@@ -372,9 +363,9 @@
372 """363 """
373 rx = 0364 rx = 0
374 tx = 0365 tx = 0
375 366
376 interfaces = self.conn.get_interfaces(self.instance_id)367 interfaces = self.conn.get_interfaces(self.instance_id)
377 368
378 # Aggregate the in and out totals.369 # Aggregate the in and out totals.
379 for interface in interfaces:370 for interface in interfaces:
380 try:371 try:
@@ -385,7 +376,7 @@
385 logging.error('Cannot get ifstats for "%s" on "%s"',376 logging.error('Cannot get ifstats for "%s" on "%s"',
386 interface, self.instance_id)377 interface, self.instance_id)
387 raise378 raise
388 379
389 return '%d:%d' % (rx, tx)380 return '%d:%d' % (rx, tx)
390381
391382
@@ -400,16 +391,16 @@
400 """391 """
401 self._instances = {}392 self._instances = {}
402 self._loop = task.LoopingCall(self.updateInstances)393 self._loop = task.LoopingCall(self.updateInstances)
403 394
404 def startService(self):395 def startService(self):
405 self._instances = {}396 self._instances = {}
406 self._loop.start(interval=FLAGS.monitoring_instances_delay)397 self._loop.start(interval=FLAGS.monitoring_instances_delay)
407 service.Service.startService(self)398 service.Service.startService(self)
408 399
409 def stopService(self):400 def stopService(self):
410 self._loop.stop()401 self._loop.stop()
411 service.Service.stopService(self)402 service.Service.stopService(self)
412 403
413 def updateInstances(self):404 def updateInstances(self):
414 """405 """
415 Update resource usage for all running instances.406 Update resource usage for all running instances.
@@ -420,20 +411,20 @@
420 logging.exception('unexpected exception getting connection')411 logging.exception('unexpected exception getting connection')
421 time.sleep(FLAGS.monitoring_instances_delay)412 time.sleep(FLAGS.monitoring_instances_delay)
422 return413 return
423 414
424 domain_ids = conn.list_instances()415 domain_ids = conn.list_instances()
425 try:416 try:
426 self.updateInstances_(conn, domain_ids)417 self.updateInstances_(conn, domain_ids)
427 except Exception, exn:418 except Exception, exn:
428 logging.exception('updateInstances_')419 logging.exception('updateInstances_')
429420
430 def updateInstances_(self, conn, domain_ids):421 def updateInstances_(self, conn, domain_ids):
431 for domain_id in domain_ids:422 for domain_id in domain_ids:
432 if not domain_id in self._instances: 423 if not domain_id in self._instances:
433 instance = Instance(conn, domain_id)424 instance = Instance(conn, domain_id)
434 self._instances[domain_id] = instance425 self._instances[domain_id] = instance
435 logging.debug('Found instance: %s', domain_id)426 logging.debug('Found instance: %s', domain_id)
436 427
437 for key in self._instances.keys():428 for key in self._instances.keys():
438 instance = self._instances[key]429 instance = self._instances[key]
439 if instance.needs_update():430 if instance.needs_update():
440431
=== modified file 'nova/compute/power_state.py'
--- nova/compute/power_state.py 2010-07-18 17:15:12 +0000
+++ nova/compute/power_state.py 2010-10-22 00:19:41 +0000
@@ -30,12 +30,11 @@
3030
31def name(code):31def name(code):
32 d = {32 d = {
33 NOSTATE : 'pending',33 NOSTATE: 'pending',
34 RUNNING : 'running',34 RUNNING: 'running',
35 BLOCKED : 'blocked',35 BLOCKED: 'blocked',
36 PAUSED : 'paused',36 PAUSED: 'paused',
37 SHUTDOWN: 'shutdown',37 SHUTDOWN: 'shutdown',
38 SHUTOFF : 'shutdown',38 SHUTOFF: 'shutdown',
39 CRASHED : 'crashed',39 CRASHED: 'crashed'}
40 }
41 return d[code]40 return d[code]
4241
=== modified file 'nova/image/service.py'
--- nova/image/service.py 2010-10-15 20:24:02 +0000
+++ nova/image/service.py 2010-10-22 00:19:41 +0000
@@ -30,7 +30,8 @@
30flags.DEFINE_string('glance_teller_port', '9191',30flags.DEFINE_string('glance_teller_port', '9191',
31 'Port for Glance\'s Teller service')31 'Port for Glance\'s Teller service')
32flags.DEFINE_string('glance_parallax_address', 'http://127.0.0.1',32flags.DEFINE_string('glance_parallax_address', 'http://127.0.0.1',
33 'IP address or URL where Glance\'s Parallax service resides')33 'IP address or URL where Glance\'s Parallax service '
34 'resides')
34flags.DEFINE_string('glance_parallax_port', '9292',35flags.DEFINE_string('glance_parallax_port', '9292',
35 'Port for Glance\'s Parallax service')36 'Port for Glance\'s Parallax service')
3637
@@ -120,10 +121,10 @@
120121
121 def delete(self, image_id):122 def delete(self, image_id):
122 """123 """
123 Delete the given image. 124 Delete the given image.
124 125
125 :raises NotFound if the image does not exist.126 :raises NotFound if the image does not exist.
126 127
127 """128 """
128 raise NotImplementedError129 raise NotImplementedError
129130
@@ -131,14 +132,14 @@
131class LocalImageService(BaseImageService):132class LocalImageService(BaseImageService):
132133
133 """Image service storing images to local disk.134 """Image service storing images to local disk.
134 135
135 It assumes that image_ids are integers."""136 It assumes that image_ids are integers."""
136137
137 def __init__(self):138 def __init__(self):
138 self._path = "/tmp/nova/images"139 self._path = "/tmp/nova/images"
139 try:140 try:
140 os.makedirs(self._path)141 os.makedirs(self._path)
141 except OSError: # exists142 except OSError: # Exists
142 pass143 pass
143144
144 def _path_to(self, image_id):145 def _path_to(self, image_id):
@@ -156,7 +157,7 @@
156157
157 def show(self, id):158 def show(self, id):
158 try:159 try:
159 return pickle.load(open(self._path_to(id))) 160 return pickle.load(open(self._path_to(id)))
160 except IOError:161 except IOError:
161 raise exception.NotFound162 raise exception.NotFound
162163
@@ -164,7 +165,7 @@
164 """165 """
165 Store the image data and return the new image id.166 Store the image data and return the new image id.
166 """167 """
167 id = random.randint(0, 2**32-1)168 id = random.randint(0, 2 ** 32 - 1)
168 data['id'] = id169 data['id'] = id
169 self.update(id, data)170 self.update(id, data)
170 return id171 return id
171172
=== modified file 'nova/image/services/glance/__init__.py'
--- nova/image/services/glance/__init__.py 2010-10-15 20:24:02 +0000
+++ nova/image/services/glance/__init__.py 2010-10-22 00:19:41 +0000
@@ -30,6 +30,7 @@
3030
31FLAGS = flags.FLAGS31FLAGS = flags.FLAGS
3232
33
33class TellerClient(object):34class TellerClient(object):
3435
35 def __init__(self):36 def __init__(self):
@@ -153,7 +154,6 @@
153154
154155
155class GlanceImageService(nova.image.service.BaseImageService):156class GlanceImageService(nova.image.service.BaseImageService):
156
157 """Provides storage and retrieval of disk image objects within Glance."""157 """Provides storage and retrieval of disk image objects within Glance."""
158158
159 def __init__(self):159 def __init__(self):
@@ -202,10 +202,10 @@
202202
203 def delete(self, image_id):203 def delete(self, image_id):
204 """204 """
205 Delete the given image. 205 Delete the given image.
206 206
207 :raises NotFound if the image does not exist.207 :raises NotFound if the image does not exist.
208 208
209 """209 """
210 self.parallax.delete_image_metadata(image_id)210 self.parallax.delete_image_metadata(image_id)
211211
212212
=== modified file 'nova/network/linux_net.py'
--- nova/network/linux_net.py 2010-10-20 20:54:53 +0000
+++ nova/network/linux_net.py 2010-10-22 00:19:41 +0000
@@ -53,6 +53,7 @@
5353
54DEFAULT_PORTS = [("tcp", 80), ("tcp", 22), ("udp", 1194), ("tcp", 443)]54DEFAULT_PORTS = [("tcp", 80), ("tcp", 22), ("udp", 1194), ("tcp", 443)]
5555
56
56def init_host():57def init_host():
57 """Basic networking setup goes here"""58 """Basic networking setup goes here"""
58 # NOTE(devcamcar): Cloud public DNAT entries, CloudPipe port59 # NOTE(devcamcar): Cloud public DNAT entries, CloudPipe port
@@ -72,6 +73,7 @@
72 _confirm_rule("POSTROUTING", "-t nat -s %(range)s -d %(range)s -j ACCEPT" %73 _confirm_rule("POSTROUTING", "-t nat -s %(range)s -d %(range)s -j ACCEPT" %
73 {'range': FLAGS.fixed_range})74 {'range': FLAGS.fixed_range})
7475
76
75def bind_floating_ip(floating_ip):77def bind_floating_ip(floating_ip):
76 """Bind ip to public interface"""78 """Bind ip to public interface"""
77 _execute("sudo ip addr add %s dev %s" % (floating_ip,79 _execute("sudo ip addr add %s dev %s" % (floating_ip,
@@ -103,7 +105,7 @@
103 _confirm_rule("FORWARD", "-d %s -p icmp -j ACCEPT"105 _confirm_rule("FORWARD", "-d %s -p icmp -j ACCEPT"
104 % (fixed_ip))106 % (fixed_ip))
105 for (protocol, port) in DEFAULT_PORTS:107 for (protocol, port) in DEFAULT_PORTS:
106 _confirm_rule("FORWARD","-d %s -p %s --dport %s -j ACCEPT"108 _confirm_rule("FORWARD", "-d %s -p %s --dport %s -j ACCEPT"
107 % (fixed_ip, protocol, port))109 % (fixed_ip, protocol, port))
108110
109111
@@ -189,7 +191,8 @@
189191
190 # if dnsmasq is already running, then tell it to reload192 # if dnsmasq is already running, then tell it to reload
191 if pid:193 if pid:
192 out, _err = _execute('cat /proc/%d/cmdline' % pid, check_exit_code=False)194 out, _err = _execute('cat /proc/%d/cmdline' % pid,
195 check_exit_code=False)
193 if conffile in out:196 if conffile in out:
194 try:197 try:
195 _execute('sudo kill -HUP %d' % pid)198 _execute('sudo kill -HUP %d' % pid)
@@ -233,7 +236,8 @@
233 """Delete and re-add iptables rule"""236 """Delete and re-add iptables rule"""
234 if FLAGS.use_nova_chains:237 if FLAGS.use_nova_chains:
235 chain = "nova_%s" % chain.lower()238 chain = "nova_%s" % chain.lower()
236 _execute("sudo iptables --delete %s %s" % (chain, cmd), check_exit_code=False)239 _execute("sudo iptables --delete %s %s" % (chain, cmd),
240 check_exit_code=False)
237 _execute("sudo iptables -I %s %s" % (chain, cmd))241 _execute("sudo iptables -I %s %s" % (chain, cmd))
238242
239243
240244
=== modified file 'nova/network/manager.py'
--- nova/network/manager.py 2010-10-14 23:44:58 +0000
+++ nova/network/manager.py 2010-10-22 00:19:41 +0000
@@ -49,7 +49,8 @@
49flags.DEFINE_integer('vpn_start', 1000, 'First Vpn port for private networks')49flags.DEFINE_integer('vpn_start', 1000, 'First Vpn port for private networks')
50flags.DEFINE_integer('network_size', 256,50flags.DEFINE_integer('network_size', 256,
51 'Number of addresses in each private subnet')51 'Number of addresses in each private subnet')
52flags.DEFINE_string('floating_range', '4.4.4.0/24', 'Floating IP address block')52flags.DEFINE_string('floating_range', '4.4.4.0/24',
53 'Floating IP address block')
53flags.DEFINE_string('fixed_range', '10.0.0.0/8', 'Fixed IP address block')54flags.DEFINE_string('fixed_range', '10.0.0.0/8', 'Fixed IP address block')
54flags.DEFINE_integer('cnt_vpn_clients', 5,55flags.DEFINE_integer('cnt_vpn_clients', 5,
55 'Number of addresses reserved for vpn clients')56 'Number of addresses reserved for vpn clients')
@@ -287,7 +288,6 @@
287 self.db.network_update(context, network_id, net)288 self.db.network_update(context, network_id, net)
288289
289290
290
291class FlatDHCPManager(NetworkManager):291class FlatDHCPManager(NetworkManager):
292 """Flat networking with dhcp"""292 """Flat networking with dhcp"""
293293
@@ -432,4 +432,3 @@
432 """Number of reserved ips at the top of the range"""432 """Number of reserved ips at the top of the range"""
433 parent_reserved = super(VlanManager, self)._top_reserved_ips433 parent_reserved = super(VlanManager, self)._top_reserved_ips
434 return parent_reserved + FLAGS.cnt_vpn_clients434 return parent_reserved + FLAGS.cnt_vpn_clients
435
436435
=== modified file 'nova/objectstore/bucket.py'
--- nova/objectstore/bucket.py 2010-10-14 05:07:43 +0000
+++ nova/objectstore/bucket.py 2010-10-22 00:19:41 +0000
@@ -69,7 +69,8 @@
69 """Create a new bucket owned by a project.69 """Create a new bucket owned by a project.
7070
71 @bucket_name: a string representing the name of the bucket to create71 @bucket_name: a string representing the name of the bucket to create
72 @context: a nova.auth.api.ApiContext object representing who owns the bucket.72 @context: a nova.auth.api.ApiContext object representing who owns the
73 bucket.
7374
74 Raises:75 Raises:
75 NotAuthorized: if the bucket is already exists or has invalid name76 NotAuthorized: if the bucket is already exists or has invalid name
@@ -77,12 +78,12 @@
77 path = os.path.abspath(os.path.join(78 path = os.path.abspath(os.path.join(
78 FLAGS.buckets_path, bucket_name))79 FLAGS.buckets_path, bucket_name))
79 if not path.startswith(os.path.abspath(FLAGS.buckets_path)) or \80 if not path.startswith(os.path.abspath(FLAGS.buckets_path)) or \
80 os.path.exists(path):81 os.path.exists(path):
81 raise exception.NotAuthorized()82 raise exception.NotAuthorized()
8283
83 os.makedirs(path)84 os.makedirs(path)
8485
85 with open(path+'.json', 'w') as f:86 with open(path + '.json', 'w') as f:
86 json.dump({'ownerId': context.project_id}, f)87 json.dump({'ownerId': context.project_id}, f)
8788
88 @property89 @property
@@ -99,22 +100,25 @@
99 @property100 @property
100 def owner_id(self):101 def owner_id(self):
101 try:102 try:
102 with open(self.path+'.json') as f:103 with open(self.path + '.json') as f:
103 return json.load(f)['ownerId']104 return json.load(f)['ownerId']
104 except:105 except:
105 return None106 return None
106107
107 def is_authorized(self, context):108 def is_authorized(self, context):
108 try:109 try:
109 return context.user.is_admin() or self.owner_id == context.project_id110 return context.user.is_admin() or \
111 self.owner_id == context.project_id
110 except Exception, e:112 except Exception, e:
111 return False113 return False
112114
113 def list_keys(self, prefix='', marker=None, max_keys=1000, terse=False):115 def list_keys(self, prefix='', marker=None, max_keys=1000, terse=False):
114 object_names = []116 object_names = []
117 path_length = len(self.path)
115 for root, dirs, files in os.walk(self.path):118 for root, dirs, files in os.walk(self.path):
116 for file_name in files:119 for file_name in files:
117 object_names.append(os.path.join(root, file_name)[len(self.path)+1:])120 object_name = os.path.join(root, file_name)[path_length + 1:]
121 object_names.append(object_name)
118 object_names.sort()122 object_names.sort()
119 contents = []123 contents = []
120124
@@ -164,7 +168,7 @@
164 if len(os.listdir(self.path)) > 0:168 if len(os.listdir(self.path)) > 0:
165 raise exception.NotEmpty()169 raise exception.NotEmpty()
166 os.rmdir(self.path)170 os.rmdir(self.path)
167 os.remove(self.path+'.json')171 os.remove(self.path + '.json')
168172
169 def __getitem__(self, key):173 def __getitem__(self, key):
170 return stored.Object(self, key)174 return stored.Object(self, key)
171175
=== modified file 'nova/objectstore/handler.py'
--- nova/objectstore/handler.py 2010-10-19 23:57:24 +0000
+++ nova/objectstore/handler.py 2010-10-22 00:19:41 +0000
@@ -136,6 +136,7 @@
136 logging.debug("Authentication Failure: %s", ex)136 logging.debug("Authentication Failure: %s", ex)
137 raise exception.NotAuthorized()137 raise exception.NotAuthorized()
138138
139
139class ErrorHandlingResource(resource.Resource):140class ErrorHandlingResource(resource.Resource):
140 """Maps exceptions to 404 / 401 codes. Won't work for141 """Maps exceptions to 404 / 401 codes. Won't work for
141 exceptions thrown after NOT_DONE_YET is returned.142 exceptions thrown after NOT_DONE_YET is returned.
@@ -162,7 +163,7 @@
162 def __init__(self):163 def __init__(self):
163 ErrorHandlingResource.__init__(self)164 ErrorHandlingResource.__init__(self)
164165
165 def getChild(self, name, request): # pylint: disable-msg=C0103166 def getChild(self, name, request): # pylint: disable-msg=C0103
166 """Returns either the image or bucket resource"""167 """Returns either the image or bucket resource"""
167 request.context = get_context(request)168 request.context = get_context(request)
168 if name == '':169 if name == '':
@@ -172,7 +173,7 @@
172 else:173 else:
173 return BucketResource(name)174 return BucketResource(name)
174175
175 def render_GET(self, request): # pylint: disable-msg=R0201176 def render_GET(self, request): # pylint: disable-msg=R0201
176 """Renders the GET request for a list of buckets as XML"""177 """Renders the GET request for a list of buckets as XML"""
177 logging.debug('List of buckets requested')178 logging.debug('List of buckets requested')
178 buckets = [b for b in bucket.Bucket.all() \179 buckets = [b for b in bucket.Bucket.all() \
@@ -321,11 +322,13 @@
321 if not self.img.is_authorized(request.context, True):322 if not self.img.is_authorized(request.context, True):
322 raise exception.NotAuthorized()323 raise exception.NotAuthorized()
323 return static.File(self.img.image_path,324 return static.File(self.img.image_path,
324 defaultType='application/octet-stream'325 defaultType='application/octet-stream').\
325 ).render_GET(request)326 render_GET(request)
327
326328
327class ImagesResource(resource.Resource):329class ImagesResource(resource.Resource):
328 """A web resource representing a list of images"""330 """A web resource representing a list of images"""
331
329 def getChild(self, name, _request):332 def getChild(self, name, _request):
330 """Returns itself or an ImageResource if no name given"""333 """Returns itself or an ImageResource if no name given"""
331 if name == '':334 if name == '':
@@ -333,7 +336,7 @@
333 else:336 else:
334 return ImageResource(name)337 return ImageResource(name)
335338
336 def render_GET(self, request): # pylint: disable-msg=R0201339 def render_GET(self, request): # pylint: disable-msg=R0201
337 """ returns a json listing of all images340 """ returns a json listing of all images
338 that a user has permissions to see """341 that a user has permissions to see """
339342
@@ -362,7 +365,7 @@
362 request.finish()365 request.finish()
363 return server.NOT_DONE_YET366 return server.NOT_DONE_YET
364367
365 def render_PUT(self, request): # pylint: disable-msg=R0201368 def render_PUT(self, request): # pylint: disable-msg=R0201
366 """ create a new registered image """369 """ create a new registered image """
367370
368 image_id = get_argument(request, 'image_id', u'')371 image_id = get_argument(request, 'image_id', u'')
@@ -383,7 +386,7 @@
383 p.start()386 p.start()
384 return ''387 return ''
385388
386 def render_POST(self, request): # pylint: disable-msg=R0201389 def render_POST(self, request): # pylint: disable-msg=R0201
387 """Update image attributes: public/private"""390 """Update image attributes: public/private"""
388391
389 # image_id required for all requests392 # image_id required for all requests
@@ -397,7 +400,7 @@
397 if operation:400 if operation:
398 # operation implies publicity toggle401 # operation implies publicity toggle
399 logging.debug("handling publicity toggle")402 logging.debug("handling publicity toggle")
400 image_object.set_public(operation=='add')403 image_object.set_public(operation == 'add')
401 else:404 else:
402 # other attributes imply update405 # other attributes imply update
403 logging.debug("update user fields")406 logging.debug("update user fields")
@@ -407,7 +410,7 @@
407 image_object.update_user_editable_fields(clean_args)410 image_object.update_user_editable_fields(clean_args)
408 return ''411 return ''
409412
410 def render_DELETE(self, request): # pylint: disable-msg=R0201413 def render_DELETE(self, request): # pylint: disable-msg=R0201
411 """Delete a registered image"""414 """Delete a registered image"""
412 image_id = get_argument(request, "image_id", u"")415 image_id = get_argument(request, "image_id", u"")
413 image_object = image.Image(image_id)416 image_object = image.Image(image_id)
414417
=== modified file 'nova/objectstore/image.py'
--- nova/objectstore/image.py 2010-10-14 05:07:43 +0000
+++ nova/objectstore/image.py 2010-10-22 00:19:41 +0000
@@ -48,8 +48,8 @@
48 self.image_id = image_id48 self.image_id = image_id
49 self.path = os.path.abspath(os.path.join(FLAGS.images_path, image_id))49 self.path = os.path.abspath(os.path.join(FLAGS.images_path, image_id))
50 if not self.path.startswith(os.path.abspath(FLAGS.images_path)) or \50 if not self.path.startswith(os.path.abspath(FLAGS.images_path)) or \
51 not os.path.isdir(self.path):51 not os.path.isdir(self.path):
52 raise exception.NotFound52 raise exception.NotFound
5353
54 @property54 @property
55 def image_path(self):55 def image_path(self):
@@ -127,8 +127,8 @@
127 a string of the image id for the kernel127 a string of the image id for the kernel
128128
129 @type ramdisk: bool or str129 @type ramdisk: bool or str
130 @param ramdisk: either TRUE meaning this partition is a ramdisk image or130 @param ramdisk: either TRUE meaning this partition is a ramdisk image
131 a string of the image id for the ramdisk131 or a string of the image id for the ramdisk
132132
133133
134 @type public: bool134 @type public: bool
@@ -160,8 +160,7 @@
160 'isPublic': public,160 'isPublic': public,
161 'architecture': 'x86_64',161 'architecture': 'x86_64',
162 'imageType': image_type,162 'imageType': image_type,
163 'state': 'available'163 'state': 'available'}
164 }
165164
166 if type(kernel) is str and len(kernel) > 0:165 if type(kernel) is str and len(kernel) > 0:
167 info['kernelId'] = kernel166 info['kernelId'] = kernel
@@ -180,7 +179,7 @@
180 os.makedirs(image_path)179 os.makedirs(image_path)
181180
182 bucket_name = image_location.split("/")[0]181 bucket_name = image_location.split("/")[0]
183 manifest_path = image_location[len(bucket_name)+1:]182 manifest_path = image_location[len(bucket_name) + 1:]
184 bucket_object = bucket.Bucket(bucket_name)183 bucket_object = bucket.Bucket(bucket_name)
185184
186 manifest = ElementTree.fromstring(bucket_object[manifest_path].read())185 manifest = ElementTree.fromstring(bucket_object[manifest_path].read())
@@ -204,10 +203,9 @@
204 'imageId': image_id,203 'imageId': image_id,
205 'imageLocation': image_location,204 'imageLocation': image_location,
206 'imageOwnerId': context.project_id,205 'imageOwnerId': context.project_id,
207 'isPublic': False, # FIXME: grab public from manifest206 'isPublic': False, # FIXME: grab public from manifest
208 'architecture': 'x86_64', # FIXME: grab architecture from manifest207 'architecture': 'x86_64', # FIXME: grab architecture from manifest
209 'imageType' : image_type208 'imageType': image_type}
210 }
211209
212 if kernel_id:210 if kernel_id:
213 info['kernelId'] = kernel_id211 info['kernelId'] = kernel_id
@@ -230,24 +228,29 @@
230 write_state('decrypting')228 write_state('decrypting')
231229
232 # FIXME: grab kernelId and ramdiskId from bundle manifest230 # FIXME: grab kernelId and ramdiskId from bundle manifest
233 encrypted_key = binascii.a2b_hex(manifest.find("image/ec2_encrypted_key").text)231 hex_key = manifest.find("image/ec2_encrypted_key").text
234 encrypted_iv = binascii.a2b_hex(manifest.find("image/ec2_encrypted_iv").text)232 encrypted_key = binascii.a2b_hex(hex_key)
233 hex_iv = manifest.find("image/ec2_encrypted_iv").text
234 encrypted_iv = binascii.a2b_hex(hex_iv)
235 cloud_private_key = os.path.join(FLAGS.ca_path, "private/cakey.pem")235 cloud_private_key = os.path.join(FLAGS.ca_path, "private/cakey.pem")
236236
237 decrypted_filename = os.path.join(image_path, 'image.tar.gz')237 decrypted_filename = os.path.join(image_path, 'image.tar.gz')
238 Image.decrypt_image(encrypted_filename, encrypted_key, encrypted_iv, cloud_private_key, decrypted_filename)238 Image.decrypt_image(encrypted_filename, encrypted_key, encrypted_iv,
239 cloud_private_key, decrypted_filename)
239240
240 write_state('untarring')241 write_state('untarring')
241242
242 image_file = Image.untarzip_image(image_path, decrypted_filename)243 image_file = Image.untarzip_image(image_path, decrypted_filename)
243 shutil.move(os.path.join(image_path, image_file), os.path.join(image_path, 'image'))244 shutil.move(os.path.join(image_path, image_file),
245 os.path.join(image_path, 'image'))
244246
245 write_state('available')247 write_state('available')
246 os.unlink(decrypted_filename)248 os.unlink(decrypted_filename)
247 os.unlink(encrypted_filename)249 os.unlink(encrypted_filename)
248250
249 @staticmethod251 @staticmethod
250 def decrypt_image(encrypted_filename, encrypted_key, encrypted_iv, cloud_private_key, decrypted_filename):252 def decrypt_image(encrypted_filename, encrypted_key, encrypted_iv,
253 cloud_private_key, decrypted_filename):
251 key, err = utils.execute(254 key, err = utils.execute(
252 'openssl rsautl -decrypt -inkey %s' % cloud_private_key,255 'openssl rsautl -decrypt -inkey %s' % cloud_private_key,
253 process_input=encrypted_key,256 process_input=encrypted_key,
@@ -259,13 +262,15 @@
259 process_input=encrypted_iv,262 process_input=encrypted_iv,
260 check_exit_code=False)263 check_exit_code=False)
261 if err:264 if err:
262 raise exception.Error("Failed to decrypt initialization vector: %s" % err)265 raise exception.Error("Failed to decrypt initialization "
266 "vector: %s" % err)
263 _out, err = utils.execute(267 _out, err = utils.execute(
264 'openssl enc -d -aes-128-cbc -in %s -K %s -iv %s -out %s'268 'openssl enc -d -aes-128-cbc -in %s -K %s -iv %s -out %s'
265 % (encrypted_filename, key, iv, decrypted_filename),269 % (encrypted_filename, key, iv, decrypted_filename),
266 check_exit_code=False)270 check_exit_code=False)
267 if err:271 if err:
268 raise exception.Error("Failed to decrypt image file %s : %s" % (encrypted_filename, err))272 raise exception.Error("Failed to decrypt image file %s : %s" %
273 (encrypted_filename, err))
269274
270 @staticmethod275 @staticmethod
271 def untarzip_image(path, filename):276 def untarzip_image(path, filename):
272277
=== modified file 'nova/objectstore/stored.py'
--- nova/objectstore/stored.py 2010-08-16 12:16:21 +0000
+++ nova/objectstore/stored.py 2010-10-22 00:19:41 +0000
@@ -50,8 +50,8 @@
50 return os.path.getmtime(self.path)50 return os.path.getmtime(self.path)
5151
52 def read(self):52 def read(self):
53 """ read all contents of key into memory and return """53 """ read all contents of key into memory and return """
54 return self.file.read()54 return self.file.read()
5555
56 @property56 @property
57 def file(self):57 def file(self):
5858
=== modified file 'nova/scheduler/driver.py'
--- nova/scheduler/driver.py 2010-09-23 09:24:54 +0000
+++ nova/scheduler/driver.py 2010-10-22 00:19:41 +0000
@@ -31,10 +31,12 @@
31flags.DEFINE_integer('service_down_time', 60,31flags.DEFINE_integer('service_down_time', 60,
32 'maximum time since last checkin for up service')32 'maximum time since last checkin for up service')
3333
34
34class NoValidHost(exception.Error):35class NoValidHost(exception.Error):
35 """There is no valid host for the command."""36 """There is no valid host for the command."""
36 pass37 pass
3738
39
38class Scheduler(object):40class Scheduler(object):
39 """The base class that all Scheduler clases should inherit from."""41 """The base class that all Scheduler clases should inherit from."""
4042
4143
=== modified file 'nova/scheduler/manager.py'
--- nova/scheduler/manager.py 2010-10-14 05:05:21 +0000
+++ nova/scheduler/manager.py 2010-10-22 00:19:41 +0000
@@ -56,7 +56,8 @@
56 driver_method = 'schedule_%s' % method56 driver_method = 'schedule_%s' % method
57 elevated = context.elevated()57 elevated = context.elevated()
58 try:58 try:
59 host = getattr(self.driver, driver_method)(elevated, *args, **kwargs)59 host = getattr(self.driver, driver_method)(elevated, *args,
60 **kwargs)
60 except AttributeError:61 except AttributeError:
61 host = self.driver.schedule(elevated, topic, *args, **kwargs)62 host = self.driver.schedule(elevated, topic, *args, **kwargs)
6263
6364
=== modified file 'nova/scheduler/simple.py'
--- nova/scheduler/simple.py 2010-09-12 03:00:56 +0000
+++ nova/scheduler/simple.py 2010-10-22 00:19:41 +0000
@@ -36,6 +36,7 @@
36flags.DEFINE_integer("max_networks", 1000,36flags.DEFINE_integer("max_networks", 1000,
37 "maximum number of networks to allow per host")37 "maximum number of networks to allow per host")
3838
39
39class SimpleScheduler(chance.ChanceScheduler):40class SimpleScheduler(chance.ChanceScheduler):
40 """Implements Naive Scheduler that tries to find least loaded host."""41 """Implements Naive Scheduler that tries to find least loaded host."""
4142
4243
=== modified file 'nova/virt/fake.py'
--- nova/virt/fake.py 2010-09-20 09:46:18 +0000
+++ nova/virt/fake.py 2010-10-22 00:19:41 +0000
@@ -226,6 +226,7 @@
226 def get_console_output(self, instance):226 def get_console_output(self, instance):
227 return 'FAKE CONSOLE OUTPUT'227 return 'FAKE CONSOLE OUTPUT'
228228
229
229class FakeInstance(object):230class FakeInstance(object):
230 def __init__(self):231 def __init__(self):
231 self._state = power_state.NOSTATE232 self._state = power_state.NOSTATE
232233
=== modified file 'nova/virt/images.py'
--- nova/virt/images.py 2010-10-07 14:03:43 +0000
+++ nova/virt/images.py 2010-10-22 00:19:41 +0000
@@ -62,8 +62,8 @@
62 headers['Authorization'] = 'AWS %s:%s' % (access, signature)62 headers['Authorization'] = 'AWS %s:%s' % (access, signature)
6363
64 cmd = ['/usr/bin/curl', '--fail', '--silent', url]64 cmd = ['/usr/bin/curl', '--fail', '--silent', url]
65 for (k,v) in headers.iteritems():65 for (k, v) in headers.iteritems():
66 cmd += ['-H', '%s: %s' % (k,v)]66 cmd += ['-H', '%s: %s' % (k, v)]
6767
68 cmd += ['-o', path]68 cmd += ['-o', path]
69 return process.SharedPool().execute(executable=cmd[0], args=cmd[1:])69 return process.SharedPool().execute(executable=cmd[0], args=cmd[1:])
7070
=== modified file 'nova/virt/libvirt_conn.py'
--- nova/virt/libvirt_conn.py 2010-10-18 20:32:45 +0000
+++ nova/virt/libvirt_conn.py 2010-10-22 00:19:41 +0000
@@ -62,7 +62,8 @@
62 'Template file for injected network')62 'Template file for injected network')
63flags.DEFINE_string('libvirt_type',63flags.DEFINE_string('libvirt_type',
64 'kvm',64 'kvm',
65 'Libvirt domain type (valid options are: kvm, qemu, uml, xen)')65 'Libvirt domain type (valid options are: '
66 'kvm, qemu, uml, xen)')
66flags.DEFINE_string('libvirt_uri',67flags.DEFINE_string('libvirt_uri',
67 '',68 '',
68 'Override the default libvirt URI (which is dependent'69 'Override the default libvirt URI (which is dependent'
@@ -96,7 +97,8 @@
96 def _conn(self):97 def _conn(self):
97 if not self._wrapped_conn or not self._test_connection():98 if not self._wrapped_conn or not self._test_connection():
98 logging.debug('Connecting to libvirt: %s' % self.libvirt_uri)99 logging.debug('Connecting to libvirt: %s' % self.libvirt_uri)
99 self._wrapped_conn = self._connect(self.libvirt_uri, self.read_only)100 self._wrapped_conn = self._connect(self.libvirt_uri,
101 self.read_only)
100 return self._wrapped_conn102 return self._wrapped_conn
101103
102 def _test_connection(self):104 def _test_connection(self):
@@ -150,6 +152,7 @@
150 # WE'LL save this for when we do shutdown,152 # WE'LL save this for when we do shutdown,
151 # instead of destroy - but destroy returns immediately153 # instead of destroy - but destroy returns immediately
152 timer = task.LoopingCall(f=None)154 timer = task.LoopingCall(f=None)
155
153 def _wait_for_shutdown():156 def _wait_for_shutdown():
154 try:157 try:
155 state = self.get_info(instance['name'])['state']158 state = self.get_info(instance['name'])['state']
@@ -164,6 +167,7 @@
164 power_state.SHUTDOWN)167 power_state.SHUTDOWN)
165 timer.stop()168 timer.stop()
166 d.callback(None)169 d.callback(None)
170
167 timer.f = _wait_for_shutdown171 timer.f = _wait_for_shutdown
168 timer.start(interval=0.5, now=True)172 timer.start(interval=0.5, now=True)
169 return d173 return d
@@ -201,6 +205,7 @@
201205
202 d = defer.Deferred()206 d = defer.Deferred()
203 timer = task.LoopingCall(f=None)207 timer = task.LoopingCall(f=None)
208
204 def _wait_for_reboot():209 def _wait_for_reboot():
205 try:210 try:
206 state = self.get_info(instance['name'])['state']211 state = self.get_info(instance['name'])['state']
@@ -217,6 +222,7 @@
217 power_state.SHUTDOWN)222 power_state.SHUTDOWN)
218 timer.stop()223 timer.stop()
219 d.callback(None)224 d.callback(None)
225
220 timer.f = _wait_for_reboot226 timer.f = _wait_for_reboot
221 timer.start(interval=0.5, now=True)227 timer.start(interval=0.5, now=True)
222 yield d228 yield d
@@ -229,7 +235,8 @@
229 instance['id'],235 instance['id'],
230 power_state.NOSTATE,236 power_state.NOSTATE,
231 'launching')237 'launching')
232 yield NWFilterFirewall(self._conn).setup_nwfilters_for_instance(instance)238 yield NWFilterFirewall(self._conn).\
239 setup_nwfilters_for_instance(instance)
233 yield self._create_image(instance, xml)240 yield self._create_image(instance, xml)
234 yield self._conn.createXML(xml, 0)241 yield self._conn.createXML(xml, 0)
235 # TODO(termie): this should actually register242 # TODO(termie): this should actually register
@@ -238,6 +245,7 @@
238245
239 local_d = defer.Deferred()246 local_d = defer.Deferred()
240 timer = task.LoopingCall(f=None)247 timer = task.LoopingCall(f=None)
248
241 def _wait_for_boot():249 def _wait_for_boot():
242 try:250 try:
243 state = self.get_info(instance['name'])['state']251 state = self.get_info(instance['name'])['state']
@@ -265,8 +273,9 @@
265273
266 if virsh_output.startswith('/dev/'):274 if virsh_output.startswith('/dev/'):
267 logging.info('cool, it\'s a device')275 logging.info('cool, it\'s a device')
268 d = process.simple_execute("sudo dd if=%s iflag=nonblock" % virsh_output, check_exit_code=False)276 d = process.simple_execute("sudo dd if=%s iflag=nonblock" %
269 d.addCallback(lambda r:r[0])277 virsh_output, check_exit_code=False)
278 d.addCallback(lambda r: r[0])
270 return d279 return d
271 else:280 else:
272 return ''281 return ''
@@ -285,11 +294,15 @@
285294
286 @exception.wrap_exception295 @exception.wrap_exception
287 def get_console_output(self, instance):296 def get_console_output(self, instance):
288 console_log = os.path.join(FLAGS.instances_path, instance['name'], 'console.log')297 console_log = os.path.join(FLAGS.instances_path, instance['name'],
289 d = process.simple_execute('sudo chown %d %s' % (os.getuid(), console_log))298 'console.log')
299 d = process.simple_execute('sudo chown %d %s' % (os.getuid(),
300 console_log))
290 if FLAGS.libvirt_type == 'xen':301 if FLAGS.libvirt_type == 'xen':
291 # Xen is spethial302 # Xen is spethial
292 d.addCallback(lambda _: process.simple_execute("virsh ttyconsole %s" % instance['name']))303 d.addCallback(lambda _:
304 process.simple_execute("virsh ttyconsole %s" %
305 instance['name']))
293 d.addCallback(self._flush_xen_console)306 d.addCallback(self._flush_xen_console)
294 d.addCallback(self._append_to_file, console_log)307 d.addCallback(self._append_to_file, console_log)
295 else:308 else:
@@ -297,7 +310,6 @@
297 d.addCallback(self._dump_file)310 d.addCallback(self._dump_file)
298 return d311 return d
299312
300
301 @defer.inlineCallbacks313 @defer.inlineCallbacks
302 def _create_image(self, inst, libvirt_xml):314 def _create_image(self, inst, libvirt_xml):
303 # syntactic nicety315 # syntactic nicety
@@ -309,7 +321,6 @@
309 yield process.simple_execute('mkdir -p %s' % basepath())321 yield process.simple_execute('mkdir -p %s' % basepath())
310 yield process.simple_execute('chmod 0777 %s' % basepath())322 yield process.simple_execute('chmod 0777 %s' % basepath())
311323
312
313 # TODO(termie): these are blocking calls, it would be great324 # TODO(termie): these are blocking calls, it would be great
314 # if they weren't.325 # if they weren't.
315 logging.info('instance %s: Creating image', inst['name'])326 logging.info('instance %s: Creating image', inst['name'])
@@ -317,17 +328,21 @@
317 f.write(libvirt_xml)328 f.write(libvirt_xml)
318 f.close()329 f.close()
319330
320 os.close(os.open(basepath('console.log'), os.O_CREAT | os.O_WRONLY, 0660))331 os.close(os.open(basepath('console.log'), os.O_CREAT | os.O_WRONLY,
332 0660))
321333
322 user = manager.AuthManager().get_user(inst['user_id'])334 user = manager.AuthManager().get_user(inst['user_id'])
323 project = manager.AuthManager().get_project(inst['project_id'])335 project = manager.AuthManager().get_project(inst['project_id'])
324336
325 if not os.path.exists(basepath('disk')):337 if not os.path.exists(basepath('disk')):
326 yield images.fetch(inst.image_id, basepath('disk-raw'), user, project)338 yield images.fetch(inst.image_id, basepath('disk-raw'), user,
339 project)
327 if not os.path.exists(basepath('kernel')):340 if not os.path.exists(basepath('kernel')):
328 yield images.fetch(inst.kernel_id, basepath('kernel'), user, project)341 yield images.fetch(inst.kernel_id, basepath('kernel'), user,
342 project)
329 if not os.path.exists(basepath('ramdisk')):343 if not os.path.exists(basepath('ramdisk')):
330 yield images.fetch(inst.ramdisk_id, basepath('ramdisk'), user, project)344 yield images.fetch(inst.ramdisk_id, basepath('ramdisk'), user,
345 project)
331346
332 execute = lambda cmd, process_input=None, check_exit_code=True: \347 execute = lambda cmd, process_input=None, check_exit_code=True: \
333 process.simple_execute(cmd=cmd,348 process.simple_execute(cmd=cmd,
@@ -339,8 +354,8 @@
339 network_ref = db.network_get_by_instance(context.get_admin_context(),354 network_ref = db.network_get_by_instance(context.get_admin_context(),
340 inst['id'])355 inst['id'])
341 if network_ref['injected']:356 if network_ref['injected']:
342 address = db.instance_get_fixed_address(context.get_admin_context(),357 admin_context = context.get_admin_context()
343 inst['id'])358 address = db.instance_get_fixed_address(admin_context, inst['id'])
344 with open(FLAGS.injected_network_template) as f:359 with open(FLAGS.injected_network_template) as f:
345 net = f.read() % {'address': address,360 net = f.read() % {'address': address,
346 'netmask': network_ref['netmask'],361 'netmask': network_ref['netmask'],
@@ -354,7 +369,8 @@
354 if net:369 if net:
355 logging.info('instance %s: injecting net into image %s',370 logging.info('instance %s: injecting net into image %s',
356 inst['name'], inst.image_id)371 inst['name'], inst.image_id)
357 yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute)372 yield disk.inject_data(basepath('disk-raw'), key, net,
373 execute=execute)
358374
359 if os.path.exists(basepath('disk')):375 if os.path.exists(basepath('disk')):
360 yield process.simple_execute('rm -f %s' % basepath('disk'))376 yield process.simple_execute('rm -f %s' % basepath('disk'))
@@ -377,7 +393,8 @@
377 network = db.project_get_network(context.get_admin_context(),393 network = db.project_get_network(context.get_admin_context(),
378 instance['project_id'])394 instance['project_id'])
379 # FIXME(vish): stick this in db395 # FIXME(vish): stick this in db
380 instance_type = instance_types.INSTANCE_TYPES[instance['instance_type']]396 instance_type = instance['instance_type']
397 instance_type = instance_types.INSTANCE_TYPES[instance_type]
381 ip_address = db.instance_get_fixed_address(context.get_admin_context(),398 ip_address = db.instance_get_fixed_address(context.get_admin_context(),
382 instance['id'])399 instance['id'])
383 # Assume that the gateway also acts as the dhcp server.400 # Assume that the gateway also acts as the dhcp server.
@@ -391,7 +408,7 @@
391 'bridge_name': network['bridge'],408 'bridge_name': network['bridge'],
392 'mac_address': instance['mac_address'],409 'mac_address': instance['mac_address'],
393 'ip_address': ip_address,410 'ip_address': ip_address,
394 'dhcp_server': dhcp_server }411 'dhcp_server': dhcp_server}
395 libvirt_xml = self.libvirt_xml % xml_info412 libvirt_xml = self.libvirt_xml % xml_info
396 logging.debug('instance %s: finished toXML method', instance['name'])413 logging.debug('instance %s: finished toXML method', instance['name'])
397414
@@ -506,7 +523,6 @@
506 domain = self._conn.lookupByName(instance_name)523 domain = self._conn.lookupByName(instance_name)
507 return domain.interfaceStats(interface)524 return domain.interfaceStats(interface)
508525
509
510 def refresh_security_group(self, security_group_id):526 def refresh_security_group(self, security_group_id):
511 fw = NWFilterFirewall(self._conn)527 fw = NWFilterFirewall(self._conn)
512 fw.ensure_security_group_filter(security_group_id)528 fw.ensure_security_group_filter(security_group_id)
@@ -557,7 +573,6 @@
557 def __init__(self, get_connection):573 def __init__(self, get_connection):
558 self._conn = get_connection574 self._conn = get_connection
559575
560
561 nova_base_filter = '''<filter name='nova-base' chain='root'>576 nova_base_filter = '''<filter name='nova-base' chain='root'>
562 <uuid>26717364-50cf-42d1-8185-29bf893ab110</uuid>577 <uuid>26717364-50cf-42d1-8185-29bf893ab110</uuid>
563 <filterref filter='no-mac-spoofing'/>578 <filterref filter='no-mac-spoofing'/>
@@ -578,7 +593,8 @@
578 srcportstart='68'593 srcportstart='68'
579 dstportstart='67'/>594 dstportstart='67'/>
580 </rule>595 </rule>
581 <rule action='accept' direction='in' priority='100'>596 <rule action='accept' direction='in'
597 priority='100'>
582 <udp srcipaddr='$DHCPSERVER'598 <udp srcipaddr='$DHCPSERVER'
583 srcportstart='67'599 srcportstart='67'
584 dstportstart='68'/>600 dstportstart='68'/>
@@ -588,8 +604,8 @@
588 def nova_base_ipv4_filter(self):604 def nova_base_ipv4_filter(self):
589 retval = "<filter name='nova-base-ipv4' chain='ipv4'>"605 retval = "<filter name='nova-base-ipv4' chain='ipv4'>"
590 for protocol in ['tcp', 'udp', 'icmp']:606 for protocol in ['tcp', 'udp', 'icmp']:
591 for direction,action,priority in [('out','accept', 399),607 for direction, action, priority in [('out', 'accept', 399),
592 ('inout','drop', 400)]:608 ('inout', 'drop', 400)]:
593 retval += """<rule action='%s' direction='%s' priority='%d'>609 retval += """<rule action='%s' direction='%s' priority='%d'>
594 <%s />610 <%s />
595 </rule>""" % (action, direction,611 </rule>""" % (action, direction,
@@ -597,12 +613,11 @@
597 retval += '</filter>'613 retval += '</filter>'
598 return retval614 return retval
599615
600
601 def nova_base_ipv6_filter(self):616 def nova_base_ipv6_filter(self):
602 retval = "<filter name='nova-base-ipv6' chain='ipv6'>"617 retval = "<filter name='nova-base-ipv6' chain='ipv6'>"
603 for protocol in ['tcp', 'udp', 'icmp']:618 for protocol in ['tcp', 'udp', 'icmp']:
604 for direction,action,priority in [('out','accept',399),619 for direction, action, priority in [('out', 'accept', 399),
605 ('inout','drop',400)]:620 ('inout', 'drop', 400)]:
606 retval += """<rule action='%s' direction='%s' priority='%d'>621 retval += """<rule action='%s' direction='%s' priority='%d'>
607 <%s-ipv6 />622 <%s-ipv6 />
608 </rule>""" % (action, direction,623 </rule>""" % (action, direction,
@@ -610,7 +625,6 @@
610 retval += '</filter>'625 retval += '</filter>'
611 return retval626 return retval
612627
613
614 def nova_project_filter(self, project, net, mask):628 def nova_project_filter(self, project, net, mask):
615 retval = "<filter name='nova-project-%s' chain='ipv4'>" % project629 retval = "<filter name='nova-project-%s' chain='ipv4'>" % project
616 for protocol in ['tcp', 'udp', 'icmp']:630 for protocol in ['tcp', 'udp', 'icmp']:
@@ -620,14 +634,12 @@
620 retval += '</filter>'634 retval += '</filter>'
621 return retval635 return retval
622636
623
624 def _define_filter(self, xml):637 def _define_filter(self, xml):
625 if callable(xml):638 if callable(xml):
626 xml = xml()639 xml = xml()
627 d = threads.deferToThread(self._conn.nwfilterDefineXML, xml)640 d = threads.deferToThread(self._conn.nwfilterDefineXML, xml)
628 return d641 return d
629642
630
631 @staticmethod643 @staticmethod
632 def _get_net_and_mask(cidr):644 def _get_net_and_mask(cidr):
633 net = IPy.IP(cidr)645 net = IPy.IP(cidr)
@@ -646,9 +658,9 @@
646 yield self._define_filter(self.nova_dhcp_filter)658 yield self._define_filter(self.nova_dhcp_filter)
647 yield self._define_filter(self.nova_base_filter)659 yield self._define_filter(self.nova_base_filter)
648660
649 nwfilter_xml = ("<filter name='nova-instance-%s' chain='root'>\n" +661 nwfilter_xml = "<filter name='nova-instance-%s' chain='root'>\n" \
650 " <filterref filter='nova-base' />\n"662 " <filterref filter='nova-base' />\n" % \
651 ) % instance['name']663 instance['name']
652664
653 if FLAGS.allow_project_net_traffic:665 if FLAGS.allow_project_net_traffic:
654 network_ref = db.project_get_network(context.get_admin_context(),666 network_ref = db.project_get_network(context.get_admin_context(),
@@ -658,14 +670,14 @@
658 net, mask)670 net, mask)
659 yield self._define_filter(project_filter)671 yield self._define_filter(project_filter)
660672
661 nwfilter_xml += (" <filterref filter='nova-project-%s' />\n"673 nwfilter_xml += " <filterref filter='nova-project-%s' />\n" % \
662 ) % instance['project_id']674 instance['project_id']
663675
664 for security_group in instance.security_groups:676 for security_group in instance.security_groups:
665 yield self.ensure_security_group_filter(security_group['id'])677 yield self.ensure_security_group_filter(security_group['id'])
666678
667 nwfilter_xml += (" <filterref filter='nova-secgroup-%d' />\n"679 nwfilter_xml += " <filterref filter='nova-secgroup-%d' />\n" % \
668 ) % security_group['id']680 security_group['id']
669 nwfilter_xml += "</filter>"681 nwfilter_xml += "</filter>"
670682
671 yield self._define_filter(nwfilter_xml)683 yield self._define_filter(nwfilter_xml)
@@ -675,7 +687,6 @@
675 return self._define_filter(687 return self._define_filter(
676 self.security_group_to_nwfilter_xml(security_group_id))688 self.security_group_to_nwfilter_xml(security_group_id))
677689
678
679 def security_group_to_nwfilter_xml(self, security_group_id):690 def security_group_to_nwfilter_xml(self, security_group_id):
680 security_group = db.security_group_get(context.get_admin_context(),691 security_group = db.security_group_get(context.get_admin_context(),
681 security_group_id)692 security_group_id)
@@ -684,12 +695,15 @@
684 rule_xml += "<rule action='accept' direction='in' priority='300'>"695 rule_xml += "<rule action='accept' direction='in' priority='300'>"
685 if rule.cidr:696 if rule.cidr:
686 net, mask = self._get_net_and_mask(rule.cidr)697 net, mask = self._get_net_and_mask(rule.cidr)
687 rule_xml += "<%s srcipaddr='%s' srcipmask='%s' " % (rule.protocol, net, mask)698 rule_xml += "<%s srcipaddr='%s' srcipmask='%s' " % \
699 (rule.protocol, net, mask)
688 if rule.protocol in ['tcp', 'udp']:700 if rule.protocol in ['tcp', 'udp']:
689 rule_xml += "dstportstart='%s' dstportend='%s' " % \701 rule_xml += "dstportstart='%s' dstportend='%s' " % \
690 (rule.from_port, rule.to_port)702 (rule.from_port, rule.to_port)
691 elif rule.protocol == 'icmp':703 elif rule.protocol == 'icmp':
692 logging.info('rule.protocol: %r, rule.from_port: %r, rule.to_port: %r' % (rule.protocol, rule.from_port, rule.to_port))704 logging.info('rule.protocol: %r, rule.from_port: %r, '
705 'rule.to_port: %r' %
706 (rule.protocol, rule.from_port, rule.to_port))
693 if rule.from_port != -1:707 if rule.from_port != -1:
694 rule_xml += "type='%s' " % rule.from_port708 rule_xml += "type='%s' " % rule.from_port
695 if rule.to_port != -1:709 if rule.to_port != -1:
@@ -697,5 +711,6 @@
697711
698 rule_xml += '/>\n'712 rule_xml += '/>\n'
699 rule_xml += "</rule>\n"713 rule_xml += "</rule>\n"
700 xml = '''<filter name='nova-secgroup-%s' chain='ipv4'>%s</filter>''' % (security_group_id, rule_xml,)714 xml = "<filter name='nova-secgroup-%s' chain='ipv4'>%s</filter>" % \
715 (security_group_id, rule_xml,)
701 return xml716 return xml
702717
=== modified file 'nova/virt/xenapi.py'
--- nova/virt/xenapi.py 2010-10-04 20:32:00 +0000
+++ nova/virt/xenapi.py 2010-10-22 00:19:41 +0000
@@ -75,12 +75,11 @@
7575
7676
77XENAPI_POWER_STATE = {77XENAPI_POWER_STATE = {
78 'Halted' : power_state.SHUTDOWN,78 'Halted': power_state.SHUTDOWN,
79 'Running' : power_state.RUNNING,79 'Running': power_state.RUNNING,
80 'Paused' : power_state.PAUSED,80 'Paused': power_state.PAUSED,
81 'Suspended': power_state.SHUTDOWN, # FIXME81 'Suspended': power_state.SHUTDOWN, # FIXME
82 'Crashed' : power_state.CRASHED82 'Crashed': power_state.CRASHED}
83}
8483
8584
86def get_connection(_):85def get_connection(_):
@@ -90,12 +89,15 @@
90 # library when not using XenAPI.89 # library when not using XenAPI.
91 global XenAPI90 global XenAPI
92 if XenAPI is None:91 if XenAPI is None:
93 XenAPI = __import__('XenAPI')92 XenAPI = __import__('XenAPI')
94 url = FLAGS.xenapi_connection_url93 url = FLAGS.xenapi_connection_url
95 username = FLAGS.xenapi_connection_username94 username = FLAGS.xenapi_connection_username
96 password = FLAGS.xenapi_connection_password95 password = FLAGS.xenapi_connection_password
97 if not url or password is None:96 if not url or password is None:
98 raise Exception('Must specify xenapi_connection_url, xenapi_connection_username (optionally), and xenapi_connection_password to use connection_type=xenapi') 97 raise Exception('Must specify xenapi_connection_url, '
98 'xenapi_connection_username (optionally), and '
99 'xenapi_connection_password to use '
100 'connection_type=xenapi')
99 return XenAPIConnection(url, username, password)101 return XenAPIConnection(url, username, password)
100102
101103
@@ -141,7 +143,7 @@
141 def _create_vm(self, instance, kernel, ramdisk):143 def _create_vm(self, instance, kernel, ramdisk):
142 """Create a VM record. Returns a Deferred that gives the new144 """Create a VM record. Returns a Deferred that gives the new
143 VM reference."""145 VM reference."""
144 146
145 instance_type = instance_types.INSTANCE_TYPES[instance.instance_type]147 instance_type = instance_types.INSTANCE_TYPES[instance.instance_type]
146 mem = str(long(instance_type['memory_mb']) * 1024 * 1024)148 mem = str(long(instance_type['memory_mb']) * 1024 * 1024)
147 vcpus = str(instance_type['vcpus'])149 vcpus = str(instance_type['vcpus'])
@@ -183,7 +185,7 @@
183 def _create_vbd(self, vm_ref, vdi_ref, userdevice, bootable):185 def _create_vbd(self, vm_ref, vdi_ref, userdevice, bootable):
184 """Create a VBD record. Returns a Deferred that gives the new186 """Create a VBD record. Returns a Deferred that gives the new
185 VBD reference."""187 VBD reference."""
186 188
187 vbd_rec = {}189 vbd_rec = {}
188 vbd_rec['VM'] = vm_ref190 vbd_rec['VM'] = vm_ref
189 vbd_rec['VDI'] = vdi_ref191 vbd_rec['VDI'] = vdi_ref
@@ -207,10 +209,10 @@
207 def _create_vif(self, vm_ref, network_ref, mac_address):209 def _create_vif(self, vm_ref, network_ref, mac_address):
208 """Create a VIF record. Returns a Deferred that gives the new210 """Create a VIF record. Returns a Deferred that gives the new
209 VIF reference."""211 VIF reference."""
210 212
211 vif_rec = {}213 vif_rec = {}
212 vif_rec['device'] = '0'214 vif_rec['device'] = '0'
213 vif_rec['network']= network_ref215 vif_rec['network'] = network_ref
214 vif_rec['VM'] = vm_ref216 vif_rec['VM'] = vm_ref
215 vif_rec['MAC'] = mac_address217 vif_rec['MAC'] = mac_address
216 vif_rec['MTU'] = '1500'218 vif_rec['MTU'] = '1500'
@@ -303,7 +305,7 @@
303305
304 def _lookup_blocking(self, i):306 def _lookup_blocking(self, i):
305 vms = self._conn.xenapi.VM.get_by_name_label(i)307 vms = self._conn.xenapi.VM.get_by_name_label(i)
306 n = len(vms) 308 n = len(vms)
307 if n == 0:309 if n == 0:
308 return None310 return None
309 elif n > 1:311 elif n > 1:
310312
=== modified file 'nova/volume/driver.py'
--- nova/volume/driver.py 2010-09-12 15:16:59 +0000
+++ nova/volume/driver.py 2010-10-22 00:19:41 +0000
@@ -61,7 +61,6 @@
61 "Try number %s", tries)61 "Try number %s", tries)
62 yield self._execute("sleep %s" % tries ** 2)62 yield self._execute("sleep %s" % tries ** 2)
6363
64
65 @defer.inlineCallbacks64 @defer.inlineCallbacks
66 def create_volume(self, volume_name, size):65 def create_volume(self, volume_name, size):
67 """Creates a logical volume"""66 """Creates a logical volume"""