merged orm
This commit is contained in:
@@ -26,6 +26,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import IPy
|
||||||
|
|
||||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||||
@@ -218,12 +220,44 @@ class ProjectCommands(object):
|
|||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(zip_file)
|
f.write(zip_file)
|
||||||
|
|
||||||
|
class FloatingIpCommands(object):
|
||||||
|
"""Class for managing floating ip."""
|
||||||
|
|
||||||
|
def create(self, host, range):
|
||||||
|
"""Creates floating ips for host by range
|
||||||
|
arguments: host ip_range"""
|
||||||
|
for address in IPy.IP(range):
|
||||||
|
db.floating_ip_create(None, {'address': str(address),
|
||||||
|
'host': host})
|
||||||
|
|
||||||
|
def delete(self, ip_range):
|
||||||
|
"""Deletes floating ips by range
|
||||||
|
arguments: range"""
|
||||||
|
for address in IPy.IP(ip_range):
|
||||||
|
db.floating_ip_destroy(None, str(address))
|
||||||
|
|
||||||
|
|
||||||
|
def list(self, host=None):
|
||||||
|
"""Lists all floating ips (optionally by host)
|
||||||
|
arguments: [host]"""
|
||||||
|
if host == None:
|
||||||
|
floating_ips = db.floating_ip_get_all(None)
|
||||||
|
else:
|
||||||
|
floating_ips = db.floating_ip_get_all_by_host(None, host)
|
||||||
|
for floating_ip in floating_ips:
|
||||||
|
instance = None
|
||||||
|
if floating_ip['fixed_ip']:
|
||||||
|
instance = floating_ip['fixed_ip']['instance']['str_id']
|
||||||
|
print "%s\t%s\t%s" % (floating_ip['host'],
|
||||||
|
floating_ip['address'],
|
||||||
|
instance)
|
||||||
|
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
('user', UserCommands),
|
('user', UserCommands),
|
||||||
('project', ProjectCommands),
|
('project', ProjectCommands),
|
||||||
('role', RoleCommands),
|
('role', RoleCommands),
|
||||||
('vpn', VpnCommands),
|
('vpn', VpnCommands),
|
||||||
|
('floating', FloatingIpCommands)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ class CloudController(object):
|
|||||||
v['status'] = '%s (%s, %s, %s, %s)' % (
|
v['status'] = '%s (%s, %s, %s, %s)' % (
|
||||||
volume['status'],
|
volume['status'],
|
||||||
volume['user_id'],
|
volume['user_id'],
|
||||||
'host',
|
volume['host'],
|
||||||
volume['instance_id'],
|
volume['instance_id'],
|
||||||
volume['mountpoint'])
|
volume['mountpoint'])
|
||||||
if volume['attach_status'] == 'attached':
|
if volume['attach_status'] == 'attached':
|
||||||
@@ -299,7 +299,7 @@ class CloudController(object):
|
|||||||
if volume_ref['attach_status'] == "attached":
|
if volume_ref['attach_status'] == "attached":
|
||||||
raise exception.ApiError("Volume is already attached")
|
raise exception.ApiError("Volume is already attached")
|
||||||
instance_ref = db.instance_get_by_str(context, instance_id)
|
instance_ref = db.instance_get_by_str(context, instance_id)
|
||||||
host = db.instance_get_host(context, instance_ref['id'])
|
host = instance_ref['host']
|
||||||
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
||||||
{"method": "attach_volume",
|
{"method": "attach_volume",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
@@ -323,7 +323,7 @@ class CloudController(object):
|
|||||||
if volume_ref['status'] == "available":
|
if volume_ref['status'] == "available":
|
||||||
raise exception.Error("Volume is already detached")
|
raise exception.Error("Volume is already detached")
|
||||||
try:
|
try:
|
||||||
host = db.instance_get_host(context, instance_ref['id'])
|
host = instance_ref['host']
|
||||||
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
||||||
{"method": "detach_volume",
|
{"method": "detach_volume",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
@@ -379,11 +379,11 @@ class CloudController(object):
|
|||||||
'code': instance['state'],
|
'code': instance['state'],
|
||||||
'name': instance['state_description']
|
'name': instance['state_description']
|
||||||
}
|
}
|
||||||
floating_addr = db.instance_get_floating_address(context,
|
floating_addr = None
|
||||||
instance['id'])
|
if instance['fixed_ip']['floating_ips']:
|
||||||
|
floating_addr = instance['fixed_ip']['floating_ips'][0]['str_id']
|
||||||
i['publicDnsName'] = floating_addr
|
i['publicDnsName'] = floating_addr
|
||||||
fixed_addr = db.instance_get_fixed_address(context,
|
fixed_addr = instance['fixed_ip']['str_id']
|
||||||
instance['id'])
|
|
||||||
i['privateDnsName'] = fixed_addr
|
i['privateDnsName'] = fixed_addr
|
||||||
if not i['publicDnsName']:
|
if not i['publicDnsName']:
|
||||||
i['publicDnsName'] = i['privateDnsName']
|
i['publicDnsName'] = i['privateDnsName']
|
||||||
@@ -420,10 +420,11 @@ class CloudController(object):
|
|||||||
iterator = db.floating_ip_get_by_project(context,
|
iterator = db.floating_ip_get_by_project(context,
|
||||||
context.project.id)
|
context.project.id)
|
||||||
for floating_ip_ref in iterator:
|
for floating_ip_ref in iterator:
|
||||||
address = floating_ip_ref['id_str']
|
address = floating_ip_ref['str_id']
|
||||||
instance_ref = db.floating_ip_get_instance(address)
|
instance_ref = db.floating_ip_get_instance(context, address)
|
||||||
|
instance_id = instance_ref['str_id']
|
||||||
address_rv = {'public_ip': address,
|
address_rv = {'public_ip': address,
|
||||||
'instance_id': instance_ref['id_str']}
|
'instance_id': instance_id}
|
||||||
if context.user.is_admin():
|
if context.user.is_admin():
|
||||||
details = "%s (%s)" % (address_rv['instance_id'],
|
details = "%s (%s)" % (address_rv['instance_id'],
|
||||||
floating_ip_ref['project_id'])
|
floating_ip_ref['project_id'])
|
||||||
@@ -448,9 +449,9 @@ class CloudController(object):
|
|||||||
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
||||||
network_topic = yield self._get_network_topic(context)
|
network_topic = yield self._get_network_topic(context)
|
||||||
rpc.cast(network_topic,
|
rpc.cast(network_topic,
|
||||||
{"method": "deallocate_floating_ip",
|
{"method": "deallocate_floating_ip",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
"floating_ip": floating_ip_ref['str_id']}})
|
"floating_address": floating_ip_ref['str_id']}})
|
||||||
defer.returnValue({'releaseResponse': ["Address released."]})
|
defer.returnValue({'releaseResponse': ["Address released."]})
|
||||||
|
|
||||||
@rbac.allow('netadmin')
|
@rbac.allow('netadmin')
|
||||||
@@ -461,11 +462,10 @@ class CloudController(object):
|
|||||||
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
||||||
network_topic = yield self._get_network_topic(context)
|
network_topic = yield self._get_network_topic(context)
|
||||||
rpc.cast(network_topic,
|
rpc.cast(network_topic,
|
||||||
{"method": "associate_floating_ip",
|
{"method": "associate_floating_ip",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
"floating_ip": floating_ip_ref['str_id'],
|
"floating_address": floating_ip_ref['str_id'],
|
||||||
"fixed_ip": fixed_ip_ref['str_id'],
|
"fixed_address": fixed_ip_ref['str_id']}})
|
||||||
"instance_id": instance_ref['id']}})
|
|
||||||
defer.returnValue({'associateResponse': ["Address associated."]})
|
defer.returnValue({'associateResponse': ["Address associated."]})
|
||||||
|
|
||||||
@rbac.allow('netadmin')
|
@rbac.allow('netadmin')
|
||||||
@@ -474,16 +474,16 @@ class CloudController(object):
|
|||||||
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
floating_ip_ref = db.floating_ip_get_by_address(context, public_ip)
|
||||||
network_topic = yield self._get_network_topic(context)
|
network_topic = yield self._get_network_topic(context)
|
||||||
rpc.cast(network_topic,
|
rpc.cast(network_topic,
|
||||||
{"method": "disassociate_floating_ip",
|
{"method": "disassociate_floating_ip",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
"floating_ip": floating_ip_ref['str_id']}})
|
"floating_address": floating_ip_ref['str_id']}})
|
||||||
defer.returnValue({'disassociateResponse': ["Address disassociated."]})
|
defer.returnValue({'disassociateResponse': ["Address disassociated."]})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_network_topic(self, context):
|
def _get_network_topic(self, context):
|
||||||
"""Retrieves the network host for a project"""
|
"""Retrieves the network host for a project"""
|
||||||
network_ref = db.project_get_network(context, context.project.id)
|
network_ref = db.project_get_network(context, context.project.id)
|
||||||
host = db.network_get_host(context, network_ref['id'])
|
host = network_ref['host']
|
||||||
if not host:
|
if not host:
|
||||||
host = yield rpc.call(FLAGS.network_topic,
|
host = yield rpc.call(FLAGS.network_topic,
|
||||||
{"method": "set_network_host",
|
{"method": "set_network_host",
|
||||||
@@ -543,7 +543,7 @@ class CloudController(object):
|
|||||||
base_options['security_group'] = security_group
|
base_options['security_group'] = security_group
|
||||||
|
|
||||||
for num in range(int(kwargs['max_count'])):
|
for num in range(int(kwargs['max_count'])):
|
||||||
inst_id = db.instance_create(context, base_options)
|
inst_id = db.instance_create(context, base_options)['id']
|
||||||
|
|
||||||
inst = {}
|
inst = {}
|
||||||
inst['mac_address'] = utils.generate_mac()
|
inst['mac_address'] = utils.generate_mac()
|
||||||
@@ -609,7 +609,7 @@ class CloudController(object):
|
|||||||
# we will need to cast here.
|
# we will need to cast here.
|
||||||
db.fixed_ip_deallocate(context, address)
|
db.fixed_ip_deallocate(context, address)
|
||||||
|
|
||||||
host = db.instance_get_host(context, instance_ref['id'])
|
host = instance_ref['host']
|
||||||
if host:
|
if host:
|
||||||
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
||||||
{"method": "terminate_instance",
|
{"method": "terminate_instance",
|
||||||
@@ -624,7 +624,7 @@ class CloudController(object):
|
|||||||
"""instance_id is a list of instance ids"""
|
"""instance_id is a list of instance ids"""
|
||||||
for id_str in instance_id:
|
for id_str in instance_id:
|
||||||
instance_ref = db.instance_get_by_str(context, id_str)
|
instance_ref = db.instance_get_by_str(context, id_str)
|
||||||
host = db.instance_get_host(context, instance_ref['id'])
|
host = instance_ref['host']
|
||||||
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
||||||
{"method": "reboot_instance",
|
{"method": "reboot_instance",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
@@ -635,11 +635,11 @@ class CloudController(object):
|
|||||||
def delete_volume(self, context, volume_id, **kwargs):
|
def delete_volume(self, context, volume_id, **kwargs):
|
||||||
# TODO: return error if not authorized
|
# TODO: return error if not authorized
|
||||||
volume_ref = db.volume_get_by_str(context, volume_id)
|
volume_ref = db.volume_get_by_str(context, volume_id)
|
||||||
host = db.volume_get_host(context, volume_ref['id'])
|
host = volume_ref['host']
|
||||||
rpc.cast(db.queue_get_for(context, FLAGS.compute_topic, host),
|
rpc.cast(db.queue_get_for(context, FLAGS.volume_topic, host),
|
||||||
{"method": "delete_volume",
|
{"method": "delete_volume",
|
||||||
"args": {"context": None,
|
"args": {"context": None,
|
||||||
"volume_id": volume_id}})
|
"volume_id": volume_ref['id']}})
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
@rbac.allow('all')
|
@rbac.allow('all')
|
||||||
|
|||||||
@@ -62,10 +62,11 @@ class Service(object, service.Service):
|
|||||||
|
|
||||||
|
|
||||||
def _create_service_ref(self):
|
def _create_service_ref(self):
|
||||||
self.service_id = db.service_create(None, {'host': self.host,
|
service_ref = db.service_create(None, {'host': self.host,
|
||||||
'binary': self.binary,
|
'binary': self.binary,
|
||||||
'topic': self.topic,
|
'topic': self.topic,
|
||||||
'report_count': 0})
|
'report_count': 0})
|
||||||
|
self.service_id = service_ref['id']
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
"""
|
"""
|
||||||
Tests For Compute
|
Tests For Compute
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
@@ -60,7 +62,7 @@ class ComputeTestCase(test.TrialTestCase):
|
|||||||
inst['instance_type'] = 'm1.tiny'
|
inst['instance_type'] = 'm1.tiny'
|
||||||
inst['mac_address'] = utils.generate_mac()
|
inst['mac_address'] = utils.generate_mac()
|
||||||
inst['ami_launch_index'] = 0
|
inst['ami_launch_index'] = 0
|
||||||
return db.instance_create(self.context, inst)
|
return db.instance_create(self.context, inst)['id']
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_run_terminate(self):
|
def test_run_terminate(self):
|
||||||
@@ -79,6 +81,24 @@ class ComputeTestCase(test.TrialTestCase):
|
|||||||
logging.info("After terminating instances: %s", instances)
|
logging.info("After terminating instances: %s", instances)
|
||||||
self.assertEqual(len(instances), 0)
|
self.assertEqual(len(instances), 0)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def test_run_terminate_timestamps(self):
|
||||||
|
"""Make sure it is possible to run and terminate instance"""
|
||||||
|
instance_id = self._create_instance()
|
||||||
|
instance_ref = db.instance_get(self.context, instance_id)
|
||||||
|
self.assertEqual(instance_ref['launched_at'], None)
|
||||||
|
self.assertEqual(instance_ref['terminated_at'], None)
|
||||||
|
launch = datetime.datetime.utcnow()
|
||||||
|
yield self.compute.run_instance(self.context, instance_id)
|
||||||
|
instance_ref = db.instance_get(self.context, instance_id)
|
||||||
|
self.assert_(instance_ref['launched_at'] > launch)
|
||||||
|
self.assertEqual(instance_ref['terminated_at'], None)
|
||||||
|
terminate = datetime.datetime.utcnow()
|
||||||
|
yield self.compute.terminate_instance(self.context, instance_id)
|
||||||
|
instance_ref = db.instance_get({'deleted': True}, instance_id)
|
||||||
|
self.assert_(instance_ref['launched_at'] < terminate)
|
||||||
|
self.assert_(instance_ref['terminated_at'] > terminate)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_reboot(self):
|
def test_reboot(self):
|
||||||
"""Ensure instance can be rebooted"""
|
"""Ensure instance can be rebooted"""
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ class NetworkTestCase(test.TrialTestCase):
|
|||||||
name))
|
name))
|
||||||
# create the necessary network data for the project
|
# create the necessary network data for the project
|
||||||
self.network.set_network_host(self.context, self.projects[i].id)
|
self.network.set_network_host(self.context, self.projects[i].id)
|
||||||
instance_id = db.instance_create(None,
|
instance_ref = db.instance_create(None,
|
||||||
{'mac_address': utils.generate_mac()})
|
{'mac_address': utils.generate_mac()})
|
||||||
self.instance_id = instance_id
|
self.instance_id = instance_ref['id']
|
||||||
instance_id = db.instance_create(None,
|
instance_ref = db.instance_create(None,
|
||||||
{'mac_address': utils.generate_mac()})
|
{'mac_address': utils.generate_mac()})
|
||||||
self.instance2_id = instance_id
|
self.instance2_id = instance_ref['id']
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable-msg=C0103
|
def tearDown(self): # pylint: disable-msg=C0103
|
||||||
super(NetworkTestCase, self).tearDown()
|
super(NetworkTestCase, self).tearDown()
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class ServiceTestCase(test.BaseTestCase):
|
|||||||
host,
|
host,
|
||||||
binary).AndRaise(exception.NotFound())
|
binary).AndRaise(exception.NotFound())
|
||||||
service.db.service_create(None,
|
service.db.service_create(None,
|
||||||
service_create).AndReturn(service_ref['id'])
|
service_create).AndReturn(service_ref)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
app = service.Service.create(host=host, binary=binary)
|
app = service.Service.create(host=host, binary=binary)
|
||||||
@@ -131,7 +131,7 @@ class ServiceTestCase(test.BaseTestCase):
|
|||||||
host,
|
host,
|
||||||
binary).AndRaise(exception.NotFound())
|
binary).AndRaise(exception.NotFound())
|
||||||
service.db.service_create(None,
|
service.db.service_create(None,
|
||||||
service_create).AndReturn(service_ref['id'])
|
service_create).AndReturn(service_ref)
|
||||||
service.db.service_get(None, service_ref['id']).AndReturn(service_ref)
|
service.db.service_get(None, service_ref['id']).AndReturn(service_ref)
|
||||||
service.db.service_update(None, service_ref['id'],
|
service.db.service_update(None, service_ref['id'],
|
||||||
mox.ContainsKeyValue('report_count', 1))
|
mox.ContainsKeyValue('report_count', 1))
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class VolumeTestCase(test.TrialTestCase):
|
|||||||
inst['instance_type'] = 'm1.tiny'
|
inst['instance_type'] = 'm1.tiny'
|
||||||
inst['mac_address'] = utils.generate_mac()
|
inst['mac_address'] = utils.generate_mac()
|
||||||
inst['ami_launch_index'] = 0
|
inst['ami_launch_index'] = 0
|
||||||
instance_id = db.instance_create(self.context, inst)
|
instance_id = db.instance_create(self.context, inst)['id']
|
||||||
mountpoint = "/dev/sdf"
|
mountpoint = "/dev/sdf"
|
||||||
volume_id = self._create_volume()
|
volume_id = self._create_volume()
|
||||||
yield self.volume.create_volume(self.context, volume_id)
|
yield self.volume.create_volume(self.context, volume_id)
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class LazyPluggable(object):
|
|||||||
fromlist = backend
|
fromlist = backend
|
||||||
|
|
||||||
self.__backend = __import__(name, None, None, fromlist)
|
self.__backend = __import__(name, None, None, fromlist)
|
||||||
logging.error('backend %s', self.__backend)
|
logging.info('backend %s', self.__backend)
|
||||||
return self.__backend
|
return self.__backend
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
|
|||||||
Reference in New Issue
Block a user