|
14 | 14 |
|
15 | 15 | import ipaddress |
16 | 16 | from copy import deepcopy |
| 17 | +from tempfile import NamedTemporaryFile |
17 | 18 |
|
18 | 19 | from ..utils import ( |
19 | 20 | find_rels_by_type, |
|
23 | 24 | from vcd_plugin_sdk.connection import VCloudConnect |
24 | 25 | from vcd_plugin_sdk.resources.network import VCloudNetwork, VCloudGateway |
25 | 26 |
|
| 27 | +from cloudify import ctx as ctx_from_import |
26 | 28 | from cloudify.exceptions import NonRecoverableError |
27 | 29 | from cloudify_common_sdk.utils import ( |
28 | 30 | get_ctx_node, |
29 | | - get_ctx_instance) |
| 31 | + get_ctx_instance, |
| 32 | + get_deployment_dir |
| 33 | +) |
30 | 34 |
|
31 | 35 |
|
32 | 36 | OLD_NETWORK_KEYS = [ |
@@ -95,6 +99,11 @@ def get_vcloud_cx(client_config, logger): |
95 | 99 | new_client_config['verify_ssl_certs'] = client_config.pop( |
96 | 100 | 'verify_ssl_certs') |
97 | 101 |
|
| 102 | + if 'log_file' not in new_client_config: |
| 103 | + new_temp = NamedTemporaryFile( |
| 104 | + dir=get_deployment_dir(ctx_from_import.deployment.id)) |
| 105 | + new_client_config['log_file'] = new_temp.name |
| 106 | + |
98 | 107 | # TODO: Figure out what to do with the rest of the stuff in client_config. |
99 | 108 | return VCloudConnect(logger, new_client_config, credentials) |
100 | 109 |
|
@@ -248,8 +257,10 @@ def convert_network_config(config): |
248 | 257 |
|
249 | 258 | if 'ip_range_start' not in config or 'ip_range_end' not in config: |
250 | 259 | ip_range_start, ip_range_end = get_ip_range(config) |
251 | | - config['ip_range_start'] = ip_range_start.compressed |
252 | | - config['ip_range_end'] = ip_range_end.compressed |
| 260 | + if ip_range_start: |
| 261 | + config['ip_range_start'] = ip_range_start.compressed |
| 262 | + if ip_range_end: |
| 263 | + config['ip_range_end'] = ip_range_end.compressed |
253 | 264 |
|
254 | 265 | if 'dns' in config: |
255 | 266 | primary_ip, secondary_ip = get_dns_ips(config['dns']) |
@@ -309,6 +320,10 @@ def get_network_cidr(config): |
309 | 320 | netmask = ipaddress.IPv4Address('0.0.0.0/{}'.format(netmask)) |
310 | 321 | if gateway_ip: |
311 | 322 | start = gateway_ip |
| 323 | + ctx_from_import.logger.info( |
| 324 | + 'Using these IPs for CIDR: {} {}'.format(start, end)) |
| 325 | + if not start or not end: |
| 326 | + return None |
312 | 327 | ip_range = [addr for addr in ipaddress.summarize_address_range(start, end)] |
313 | 328 | if len(ip_range) >= 1: |
314 | 329 | if netmask: |
|
0 commit comments