run instances works
This commit is contained in:
@@ -30,6 +30,7 @@ import sys
|
|||||||
# not true the ugly line below can be removed
|
# not true the ugly line below can be removed
|
||||||
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
|
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
|
||||||
|
|
||||||
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
from nova import utils
|
from nova import utils
|
||||||
@@ -74,8 +75,8 @@ def del_lease(_mac, ip_address, _hostname, _interface):
|
|||||||
|
|
||||||
def init_leases(interface):
|
def init_leases(interface):
|
||||||
"""Get the list of hosts for an interface."""
|
"""Get the list of hosts for an interface."""
|
||||||
network = service.get_network_by_interface(interface)
|
network_ref = db.network_get_by_bridge(None, interface)
|
||||||
return linux_net.get_dhcp_hosts(network)
|
return linux_net.get_dhcp_hosts(None, network_ref['id'])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -577,13 +577,13 @@ class AuthManager(object):
|
|||||||
|
|
||||||
def delete_project(self, project, context=None):
|
def delete_project(self, project, context=None):
|
||||||
"""Deletes a project"""
|
"""Deletes a project"""
|
||||||
|
try:
|
||||||
network_ref = db.project_get_network(context,
|
network_ref = db.project_get_network(context,
|
||||||
Project.safe_id(project))
|
Project.safe_id(project))
|
||||||
try:
|
|
||||||
db.network_destroy(context, network_ref['id'])
|
db.network_destroy(context, network_ref['id'])
|
||||||
except:
|
except:
|
||||||
logging.exception('Could not destroy network: %s',
|
logging.exception('Could not destroy network for %s',
|
||||||
network_ref['id'])
|
project)
|
||||||
with self.driver() as drv:
|
with self.driver() as drv:
|
||||||
drv.delete_project(Project.safe_id(project))
|
drv.delete_project(Project.safe_id(project))
|
||||||
|
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ class CloudController(object):
|
|||||||
}
|
}
|
||||||
i['public_dns_name'] = None #network_model.get_public_ip_for_instance(
|
i['public_dns_name'] = None #network_model.get_public_ip_for_instance(
|
||||||
# i['instance_id'])
|
# 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']:
|
if not i['public_dns_name']:
|
||||||
i['public_dns_name'] = i['private_dns_name']
|
i['public_dns_name'] = i['private_dns_name']
|
||||||
i['dns_name'] = None
|
i['dns_name'] = None
|
||||||
@@ -497,18 +497,19 @@ class CloudController(object):
|
|||||||
host = yield rpc.call(FLAGS.network_topic,
|
host = yield rpc.call(FLAGS.network_topic,
|
||||||
{"method": "set_network_host",
|
{"method": "set_network_host",
|
||||||
"args": {"project_id": context.project.id}})
|
"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')
|
@rbac.allow('projectmanager', 'sysadmin')
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def run_instances(self, context, **kwargs):
|
def run_instances(self, context, **kwargs):
|
||||||
# make sure user can access the image
|
# make sure user can access the image
|
||||||
# vpn image is private so it doesn't show up on lists
|
# 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'])
|
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
|
# get defaults from imagestore
|
||||||
image_id = image['imageId']
|
image_id = image['imageId']
|
||||||
kernel_id = image.get('kernelId', FLAGS.default_kernel)
|
kernel_id = image.get('kernelId', FLAGS.default_kernel)
|
||||||
@@ -523,7 +524,6 @@ class CloudController(object):
|
|||||||
images.get(context, ramdisk_id)
|
images.get(context, ramdisk_id)
|
||||||
|
|
||||||
logging.debug("Going to run instances...")
|
logging.debug("Going to run instances...")
|
||||||
reservation_id = utils.generate_uid('r')
|
|
||||||
launch_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
|
launch_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
|
||||||
key_data = None
|
key_data = None
|
||||||
if kwargs.has_key('key_name'):
|
if kwargs.has_key('key_name'):
|
||||||
@@ -537,45 +537,51 @@ class CloudController(object):
|
|||||||
security_group = "default"
|
security_group = "default"
|
||||||
|
|
||||||
network_ref = db.project_get_network(context, context.project.id)
|
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'])):
|
for num in range(int(kwargs['max_count'])):
|
||||||
inst = {}
|
inst_id = db.instance_create(context, base_options)
|
||||||
inst['image_id'] = image_id
|
|
||||||
inst['kernel_id'] = kernel_id
|
if vpn:
|
||||||
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:
|
|
||||||
fixed_ip = db.network_get_vpn_ip(context, network_ref['id'])
|
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['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['launch_index'] = num
|
||||||
inst['security_group'] = security_group
|
inst['hostname'] = inst_id
|
||||||
inst['hostname'] = inst_id # FIXME(ja): id isn't assigned until create
|
|
||||||
db.instance_update(context, inst_id, inst)
|
db.instance_update(context, inst_id, inst)
|
||||||
|
|
||||||
|
|
||||||
# TODO(vish): This probably should be done in the scheduler
|
# TODO(vish): This probably should be done in the scheduler
|
||||||
# network is setup when host is assigned
|
# 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,
|
rpc.call(network_topic,
|
||||||
{"method": "setup_fixed_ip",
|
{"method": "setup_fixed_ip",
|
||||||
"args": {"fixed_ip_id": fixed_ip['id']}})
|
"args": {"address": fixed_ip['ip_str']}})
|
||||||
|
|
||||||
rpc.cast(FLAGS.compute_topic,
|
rpc.cast(FLAGS.compute_topic,
|
||||||
{"method": "run_instance",
|
{"method": "run_instance",
|
||||||
"args": {"instance_id": inst_id}})
|
"args": {"instance_id": inst_id}})
|
||||||
logging.debug("Casting to node for %s/%s's instance %s" %
|
logging.debug("Casting to node for %s/%s's instance %s" %
|
||||||
(context.project.name, context.user.name, inst_id))
|
(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')
|
@rbac.allow('projectmanager', 'sysadmin')
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ class Network(Base, NovaBase):
|
|||||||
vpn_public_ip_str = Column(String(255))
|
vpn_public_ip_str = Column(String(255))
|
||||||
vpn_public_port = Column(Integer)
|
vpn_public_port = Column(Integer)
|
||||||
vpn_private_ip_str = Column(String(255))
|
vpn_private_ip_str = Column(String(255))
|
||||||
|
dhcp_start = Column(String(255))
|
||||||
|
|
||||||
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
|
project_id = Column(String(255)) #, ForeignKey('projects.id'), nullable=False)
|
||||||
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
|
node_name = Column(String(255)) #, ForeignKey('physical_node.id'))
|
||||||
|
|||||||
Reference in New Issue
Block a user