run instances works

This commit is contained in:
Vishvananda Ishaya
2010-08-24 01:14:10 -07:00
4 changed files with 42 additions and 34 deletions

View File

@@ -30,6 +30,7 @@ import sys
# not true the ugly line below can be removed
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
from nova import db
from nova import flags
from nova import rpc
from nova import utils
@@ -74,8 +75,8 @@ def del_lease(_mac, ip_address, _hostname, _interface):
def init_leases(interface):
"""Get the list of hosts for an interface."""
network = service.get_network_by_interface(interface)
return linux_net.get_dhcp_hosts(network)
network_ref = db.network_get_by_bridge(None, interface)
return linux_net.get_dhcp_hosts(None, network_ref['id'])
def main():

View File

@@ -577,13 +577,13 @@ class AuthManager(object):
def delete_project(self, project, context=None):
"""Deletes a project"""
network_ref = db.project_get_network(context,
Project.safe_id(project))
try:
network_ref = db.project_get_network(context,
Project.safe_id(project))
db.network_destroy(context, network_ref['id'])
except:
logging.exception('Could not destroy network: %s',
network_ref['id'])
logging.exception('Could not destroy network for %s',
project)
with self.driver() as drv:
drv.delete_project(Project.safe_id(project))

View File

@@ -83,7 +83,7 @@ class CloudController(object):
def setup(self):
""" Ensure the keychains and folders exist. """
# FIXME(ja): this should be moved to a nova-manage command,
# FIXME(ja): this should be moved to a nova-manage command,
# if not setup throw exceptions instead of running
# Create keys folder, if it doesn't exist
if not os.path.exists(FLAGS.keys_path):
@@ -398,7 +398,7 @@ class CloudController(object):
}
i['public_dns_name'] = None #network_model.get_public_ip_for_instance(
# i['instance_id'])
i['private_dns_name'] = instance.fixed_ip
i['private_dns_name'] = instance.fixed_ip['ip_str']
if not i['public_dns_name']:
i['public_dns_name'] = i['private_dns_name']
i['dns_name'] = None
@@ -497,18 +497,19 @@ class CloudController(object):
host = yield rpc.call(FLAGS.network_topic,
{"method": "set_network_host",
"args": {"project_id": context.project.id}})
defer.returnValue(db.queue_get_for(FLAGS.network_topic, host))
defer.returnValue(db.queue_get_for(context, FLAGS.network_topic, host))
@rbac.allow('projectmanager', 'sysadmin')
@defer.inlineCallbacks
def run_instances(self, context, **kwargs):
# make sure user can access the image
# vpn image is private so it doesn't show up on lists
if kwargs['image_id'] != FLAGS.vpn_image_id:
vpn = kwargs['image_id'] == FLAGS.vpn_image_id
if not vpn:
image = images.get(context, kwargs['image_id'])
# FIXME(ja): if image is cloudpipe, this breaks
# FIXME(ja): if image is vpn, this breaks
# get defaults from imagestore
image_id = image['imageId']
kernel_id = image.get('kernelId', FLAGS.default_kernel)
@@ -523,7 +524,6 @@ class CloudController(object):
images.get(context, ramdisk_id)
logging.debug("Going to run instances...")
reservation_id = utils.generate_uid('r')
launch_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
key_data = None
if kwargs.has_key('key_name'):
@@ -537,45 +537,51 @@ class CloudController(object):
security_group = "default"
network_ref = db.project_get_network(context, context.project.id)
reservation_id = utils.generate_uid('r')
base_options = {}
base_options['image_id'] = image_id
base_options['kernel_id'] = kernel_id
base_options['ramdisk_id'] = ramdisk_id
base_options['reservation_id'] = reservation_id
base_options['key_data'] = key_data
base_options['key_name'] = kwargs.get('key_name', None)
base_options['user_id'] = context.user.id
base_options['project_id'] = context.project.id
base_options['user_data'] = kwargs.get('user_data', '')
base_options['instance_type'] = kwargs.get('instance_type', 'm1.small')
base_options['security_group'] = security_group
for num in range(int(kwargs['max_count'])):
inst = {}
inst['image_id'] = image_id
inst['kernel_id'] = kernel_id
inst['ramdisk_id'] = ramdisk_id
instance_ref = db.instance_create(context, inst)
inst_id = instance_ref['id']
if db.instance_is_vpn(instance_ref['id']):
fixed_ip = db.fixed_ip_allocate(context, network_ref['id'])
else:
inst_id = db.instance_create(context, base_options)
if vpn:
fixed_ip = db.network_get_vpn_ip(context, network_ref['id'])
else:
fixed_ip = db.fixed_ip_allocate(context, network_ref['id'])
print fixed_ip['ip_str'], inst_id
db.fixed_ip_instance_associate(context, fixed_ip['ip_str'], inst_id)
print fixed_ip.instance
inst = {}
inst['mac_address'] = utils.generate_mac()
inst['user_data'] = kwargs.get('user_data', '')
inst['instance_type'] = kwargs.get('instance_type', 'm1.small')
inst['reservation_id'] = reservation_id
inst['key_data'] = key_data
inst['key_name'] = kwargs.get('key_name', None)
inst['user_id'] = context.user.id # FIXME(ja)
inst['project_id'] = context.project.id # FIXME(ja)
inst['launch_index'] = num
inst['security_group'] = security_group
inst['hostname'] = inst_id # FIXME(ja): id isn't assigned until create
inst['hostname'] = inst_id
db.instance_update(context, inst_id, inst)
# TODO(vish): This probably should be done in the scheduler
# network is setup when host is assigned
network_topic = yield self.get_network_topic()
network_topic = yield self._get_network_topic(context)
rpc.call(network_topic,
{"method": "setup_fixed_ip",
"args": {"fixed_ip_id": fixed_ip['id']}})
"args": {"address": fixed_ip['ip_str']}})
rpc.cast(FLAGS.compute_topic,
{"method": "run_instance",
"args": {"instance_id": inst_id}})
logging.debug("Casting to node for %s/%s's instance %s" %
(context.project.name, context.user.name, inst_id))
defer.returnValue(self._format_instances(context, reservation_id))
defer.returnValue(self._format_run_instances(context,
reservation_id))
@rbac.allow('projectmanager', 'sysadmin')

View File

@@ -316,6 +316,7 @@ class Network(Base, NovaBase):
vpn_public_ip_str = Column(String(255))
vpn_public_port = Column(Integer)
vpn_private_ip_str = Column(String(255))
dhcp_start = Column(String(255))
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))