67
67
raise exception.Duplicate(_('Attempted to create'
68
68
' non-unique name %s') % instance.name)
70
bridge = db.network_get_by_instance(context.get_admin_context(),
71
instance['id'])['bridge']
73
NetworkHelper.find_network_with_bridge(self._session, bridge)
70
#ensure enough free memory is available
71
if not VMHelper.ensure_free_mem(self._session, instance):
72
name = instance['name']
73
LOG.exception(_('instance %(name)s: not enough free memory')
75
db.instance_set_state(context.get_admin_context(),
75
80
user = AuthManager().get_user(instance.user_id)
76
81
project = AuthManager().get_project(instance.project_id)
99
104
instance, kernel, ramdisk, pv_kernel)
100
105
VMHelper.create_vbd(self._session, vm_ref, vdi_ref, 0, True)
103
VMHelper.create_vif(self._session, vm_ref,
104
network_ref, instance.mac_address)
108
admin_context = context.get_admin_context()
110
# TODO(tr3buchet) - remove comment in multi-nic
111
# I've decided to go ahead and consider multiple IPs and networks
112
# at this stage even though they aren't implemented because these will
113
# be needed for multi-nic and there was no sense writing it for single
114
# network/single IP and then having to turn around and re-write it
115
IPs = db.fixed_ip_get_all_by_instance(admin_context, instance['id'])
116
for network in db.network_get_all_by_instance(admin_context,
118
network_IPs = [ip for ip in IPs if ip.network_id == network.id]
121
return {'netmask': network['netmask'],
125
mac_id = instance.mac_address.replace(':', '')
126
location = 'vm-data/networking/%s' % mac_id
127
mapping = {'label': network['label'],
128
'gateway': network['gateway'],
129
'mac': instance.mac_address,
130
'dns': [network['dns']],
131
'ips': [ip_dict(ip) for ip in network_IPs]}
132
self.write_to_param_xenstore(vm_ref, {location: mapping})
134
# TODO(tr3buchet) - remove comment in multi-nic
135
# this bit here about creating the vifs will be updated
136
# in multi-nic to handle multiple IPs on the same network
137
# and multiple networks
138
# for now it works as there is only one of each
139
bridge = network['bridge']
141
NetworkHelper.find_network_with_bridge(self._session, bridge)
144
VMHelper.create_vif(self._session, vm_ref,
145
network_ref, instance.mac_address)
105
147
LOG.debug(_('Starting VM %s...'), vm_ref)
106
148
self._session.call_xenapi('VM.start', vm_ref, False, False)
107
149
instance_name = instance.name
161
209
instance_name = instance_or_vm.name
162
210
vm = VMHelper.lookup(self._session, instance_name)
164
raise Exception(_('Instance not present %s') % instance_name)
212
raise exception.NotFound(
213
_('Instance not present %s') % instance_name)
167
216
def snapshot(self, instance, image_id):
389
438
# TODO: implement this!
390
439
return 'http://fakeajaxconsole/fake_url'
441
def reset_network(self, instance):
443
Creates uuid arg to pass to make_agent_call and calls it.
446
args = {'id': str(uuid.uuid4())}
447
resp = self._make_agent_call('resetnetwork', instance, '', args)
392
449
def list_from_xenstore(self, vm, path):
393
450
"""Runs the xenstore-ls command to get a listing of all records
394
451
from 'path' downward. Returns a dict with the sub-paths as keys,