|
@@ -570,10 +570,10 @@ class OpenStackInstanceService(BaseInstanceService):
|
|
|
isinstance(instance_type, InstanceType) else \
|
|
isinstance(instance_type, InstanceType) else \
|
|
|
self.provider.compute.instance_types.find(
|
|
self.provider.compute.instance_types.find(
|
|
|
name=instance_type)[0].id
|
|
name=instance_type)[0].id
|
|
|
- network_id = subnet.network_id if isinstance(subnet, Subnet) else None
|
|
|
|
|
- if not network_id and subnet:
|
|
|
|
|
- network_id = (self.provider.network.subnets.get(subnet).network_id
|
|
|
|
|
- if isinstance(subnet, str) else None)
|
|
|
|
|
|
|
+ subnet_id = subnet.id if isinstance(subnet, Subnet) else subnet
|
|
|
|
|
+ net_id = subnet.network_id if isinstance(subnet, Subnet) else None
|
|
|
|
|
+ if not net_id and subnet_id:
|
|
|
|
|
+ net_id = self.provider.network.subnets.get(subnet_id).network_id
|
|
|
zone_id = zone.id if isinstance(zone, PlacementZone) else zone
|
|
zone_id = zone.id if isinstance(zone, PlacementZone) else zone
|
|
|
key_pair_name = key_pair.name if \
|
|
key_pair_name = key_pair.name if \
|
|
|
isinstance(key_pair, KeyPair) else key_pair
|
|
isinstance(key_pair, KeyPair) else key_pair
|
|
@@ -589,7 +589,22 @@ class OpenStackInstanceService(BaseInstanceService):
|
|
|
if launch_config:
|
|
if launch_config:
|
|
|
bdm = self._to_block_device_mapping(launch_config)
|
|
bdm = self._to_block_device_mapping(launch_config)
|
|
|
|
|
|
|
|
- log.debug("Launching in network %s" % network_id)
|
|
|
|
|
|
|
+ log.debug("Creating network port for %s" % name)
|
|
|
|
|
+ port_def = {
|
|
|
|
|
+ "port": {
|
|
|
|
|
+ "admin_state_up": True,
|
|
|
|
|
+ "name": name,
|
|
|
|
|
+ "network_id": net_id,
|
|
|
|
|
+ "fixed_ips": [
|
|
|
|
|
+ {
|
|
|
|
|
+ "subnet_id": subnet_id
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ port_id = self.provider.neutron.create_port(port_def)['port']['id']
|
|
|
|
|
+ nics = [{'net-id': net_id, 'port-id': port_id}] if port_id else None
|
|
|
|
|
+ log.debug("Launching in subnet %s" % subnet_id)
|
|
|
os_instance = self.provider.nova.servers.create(
|
|
os_instance = self.provider.nova.servers.create(
|
|
|
name,
|
|
name,
|
|
|
None if self._has_root_device(launch_config) else image_id,
|
|
None if self._has_root_device(launch_config) else image_id,
|
|
@@ -601,7 +616,7 @@ class OpenStackInstanceService(BaseInstanceService):
|
|
|
security_groups=security_groups_list,
|
|
security_groups=security_groups_list,
|
|
|
userdata=user_data,
|
|
userdata=user_data,
|
|
|
block_device_mapping_v2=bdm,
|
|
block_device_mapping_v2=bdm,
|
|
|
- nics=[{'net-id': network_id}] if network_id else None)
|
|
|
|
|
|
|
+ nics=nics)
|
|
|
return OpenStackInstance(self.provider, os_instance)
|
|
return OpenStackInstance(self.provider, os_instance)
|
|
|
|
|
|
|
|
def _to_block_device_mapping(self, launch_config):
|
|
def _to_block_device_mapping(self, launch_config):
|