name_dict[ interface["name"] ] = "overlay"
vnfc_interfaces[ vnfc["name"] ] = name_dict
# check bood-data info
- if "boot-data" in vnfc:
- # check that user-data is incompatible with users and config-files
- if (vnfc["boot-data"].get("users") or vnfc["boot-data"].get("config-files")) and vnfc["boot-data"].get("user-data"):
- raise NfvoException(
- "Error at vnf:VNFC:boot-data, fields 'users' and 'config-files' are not compatible with 'user-data'",
- HTTP_Bad_Request)
+ # if "boot-data" in vnfc:
+ # # check that user-data is incompatible with users and config-files
+ # if (vnfc["boot-data"].get("users") or vnfc["boot-data"].get("config-files")) and vnfc["boot-data"].get("user-data"):
+ # raise NfvoException(
+ # "Error at vnf:VNFC:boot-data, fields 'users' and 'config-files' are not compatible with 'user-data'",
+ # HTTP_Bad_Request)
#check if the info in external_connections matches with the one in the vnfcs
name_list=[]
def unify_cloud_config(cloud_config_preserve, cloud_config):
- ''' join the cloud config information into cloud_config_preserve.
+ """ join the cloud config information into cloud_config_preserve.
In case of conflict cloud_config_preserve preserves
- None is admited
- '''
+ None is allowed
+ """
if not cloud_config_preserve and not cloud_config:
return None
new_cloud_config["boot-data-drive"] = cloud_config_preserve["boot-data-drive"]
# user-data
- if cloud_config and cloud_config.get("user-data") != None:
- new_cloud_config["user-data"] = cloud_config["user-data"]
- if cloud_config_preserve and cloud_config_preserve.get("user-data") != None:
- new_cloud_config["user-data"] = cloud_config_preserve["user-data"]
+ new_cloud_config["user-data"] = []
+ if cloud_config and cloud_config.get("user-data"):
+ if isinstance(cloud_config["user-data"], list):
+ new_cloud_config["user-data"] += cloud_config["user-data"]
+ else:
+ new_cloud_config["user-data"].append(cloud_config["user-data"])
+ if cloud_config_preserve and cloud_config_preserve.get("user-data"):
+ if isinstance(cloud_config_preserve["user-data"], list):
+ new_cloud_config["user-data"] += cloud_config_preserve["user-data"]
+ else:
+ new_cloud_config["user-data"].append(cloud_config_preserve["user-data"])
+ if not new_cloud_config["user-data"]:
+ del new_cloud_config["user-data"]
# config files
new_cloud_config["config-files"] = []
import time
import yaml
import random
+import sys
from novaclient import client as nClient, exceptions as nvExceptions
from keystoneauth1.identity import v2, v3
from neutronclient.neutron import client as neClient
from neutronclient.common import exceptions as neExceptions
from requests.exceptions import ConnectionError
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
-'''contain the openstack virtual machine status to openmano status'''
+
+"""contain the openstack virtual machine status to openmano status"""
vmStatus2manoFormat={'ACTIVE':'ACTIVE',
'PAUSED':'PAUSED',
'SUSPENDED': 'SUSPENDED',
except (ksExceptions.ClientException, nvExceptions.ClientException, gl1Exceptions.CommunicationError, ConnectionError) as e:
self._format_exception(e)
+ @staticmethod
+ def _create_mimemultipart(content_list):
+ """Creates a MIMEmultipart text combining the content_list
+ :param content_list: list of text scripts to be combined
+ :return: str of the created MIMEmultipart. If the list is empty returns None, if the list contains only one
+ element MIMEmultipart is not created and this content is returned
+ """
+ if not content_list:
+ return None
+ elif len(content_list) == 1:
+ return content_list[0]
+ combined_message = MIMEMultipart()
+ for content in content_list:
+ if content.startswith('#include'):
+ format = 'text/x-include-url'
+ elif content.startswith('#include-once'):
+ format = 'text/x-include-once-url'
+ elif content.startswith('#!'):
+ format = 'text/x-shellscript'
+ elif content.startswith('#cloud-config'):
+ format = 'text/cloud-config'
+ elif content.startswith('#cloud-config-archive'):
+ format = 'text/cloud-config-archive'
+ elif content.startswith('#upstart-job'):
+ format = 'text/upstart-job'
+ elif content.startswith('#part-handler'):
+ format = 'text/part-handler'
+ elif content.startswith('#cloud-boothook'):
+ format = 'text/cloud-boothook'
+ else: # by default
+ format = 'text/x-shellscript'
+ sub_message = MIMEText(content, format, sys.getdefaultencoding())
+ combined_message.attach(sub_message)
+ return combined_message.as_string()
+
def __wait_for_vm(self, vm_id, status):
"""wait until vm is in the desired status and return True.
If the VM gets in ERROR status, return false.
#cloud config
userdata=None
config_drive = None
+ userdata_list = []
if isinstance(cloud_config, dict):
if cloud_config.get("user-data"):
- userdata=cloud_config["user-data"]
+ if isinstance(cloud_config["user-data"], str):
+ userdata_list.append(cloud_config["user-data"])
+ else:
+ for u in cloud_config["user-data"]:
+ userdata_list.append(u)
if cloud_config.get("boot-data-drive") != None:
config_drive = cloud_config["boot-data-drive"]
if cloud_config.get("config-files") or cloud_config.get("users") or cloud_config.get("key-pairs"):
- if userdata:
- raise vimconn.vimconnConflictException("Cloud-config cannot contain both 'userdata' and 'config-files'/'users'/'key-pairs'")
userdata_dict={}
#default user
if cloud_config.get("key-pairs"):
if file.get("owner"):
file_info["owner"] = file["owner"]
userdata_dict["write_files"].append(file_info)
- userdata = "#cloud-config\n"
- userdata += yaml.safe_dump(userdata_dict, indent=4, default_flow_style=False)
+ userdata_list.append("#cloud-config\n" + yaml.safe_dump(userdata_dict, indent=4,
+ default_flow_style=False))
+ userdata = self._create_mimemultipart(userdata_list)
self.logger.debug("userdata: %s", userdata)
elif isinstance(cloud_config, str):
userdata = cloud_config