X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=osm_ro%2Fvimconn_vmware.py;h=a33ca4e69887205574835b338639f11c118a6289;hb=45483bf232a8ad3d7d5106f688adb2b6f54309f6;hp=5b044581d513b68e03ba03ef1a8002723169673e;hpb=05a8b7bc29197345f9718796c110d6cf3c2ad176;p=osm%2FRO.git
diff --git a/osm_ro/vimconn_vmware.py b/osm_ro/vimconn_vmware.py
index 5b044581..a33ca4e6 100644
--- a/osm_ro/vimconn_vmware.py
+++ b/osm_ro/vimconn_vmware.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##
-# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
-# This file is part of openmano
+# Copyright 2016-2017 VMware Inc.
+# This file is part of ETSI OSM
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,7 +18,7 @@
# under the License.
#
# For those usages not covered by the Apache License, Version 2.0 please
-# contact with: nfvlabs@tid.es
+# contact: osslegalrouting@vmware.com
##
"""
@@ -1444,7 +1444,12 @@ class vimconnector(vimconn.vimconnector):
if disk_list:
added_existing_disk = False
for disk in disk_list:
- if "image_id" in disk and disk["image_id"] is not None:
+ if 'device_type' in disk and disk['device_type'] == 'cdrom':
+ image_id = disk['image_id']
+ # Adding CD-ROM to VM
+ # will revisit code once specification ready to support this feature
+ self.insert_media_to_vm(vapp, image_id)
+ elif "image_id" in disk and disk["image_id"] is not None:
self.logger.debug("Adding existing disk from image {} to vm {} ".format(
disk["image_id"] , vapp_uuid))
self.add_existing_disk(catalogs=catalogs,
@@ -2746,6 +2751,11 @@ class vimconnector(vimconn.vimconnector):
#Unused in case of Underlay (data/ptp) network interface.
fence_mode="bridged"
is_inherited='false'
+ dns_list = dns_address.split(";")
+ dns1 = dns_list[0]
+ dns2_text = ""
+ if len(dns_list) >= 2:
+ dns2_text = "\n {}\n".format(dns_list[1])
data = """
Openmano created
@@ -2754,22 +2764,22 @@ class vimconnector(vimconn.vimconnector):
{1:s}
{2:s}
{3:s}
- {4:s}
- {5:s}
+ {4:s}{5:s}
+ {6:s}
- {6:s}
- {7:s}
+ {7:s}
+ {8:s}
-
- {9:s}
+
+ {10:s}
- {10:s}
+ {11:s}
""".format(escape(network_name), is_inherited, gateway_address,
- subnet_address, dns_address, dhcp_enabled,
+ subnet_address, dns1, dns2_text, dhcp_enabled,
dhcp_start_address, dhcp_end_address, available_networks,
fence_mode, isshared)
@@ -4788,3 +4798,114 @@ class vimconnector(vimconn.vimconnector):
break
return obj
+
+ def insert_media_to_vm(self, vapp, image_id):
+ """
+ Method to insert media CD-ROM (ISO image) from catalog to vm.
+ vapp - vapp object to get vm id
+ Image_id - image id for cdrom to be inerted to vm
+ """
+ # create connection object
+ vca = self.connect()
+ try:
+ # fetching catalog details
+ rest_url = "{}/api/catalog/{}".format(vca.host,image_id)
+ response = Http.get(url=rest_url,
+ headers=vca.vcloud_session.get_vcloud_headers(),
+ verify=vca.verify,
+ logger=vca.logger)
+
+ if response.status_code != 200:
+ self.logger.error("REST call {} failed reason : {}"\
+ "status code : {}".format(url_rest_call,
+ response.content,
+ response.status_code))
+ raise vimconn.vimconnException("insert_media_to_vm(): Failed to get "\
+ "catalog details")
+ # searching iso name and id
+ iso_name,media_id = self.get_media_details(vca, response.content)
+
+ if iso_name and media_id:
+ data ="""
+
+
+ """.format(iso_name, media_id,
+ vca.host,media_id)
+
+ for vms in vapp._get_vms():
+ vm_id = (vms.id).split(':')[-1]
+
+ headers = vca.vcloud_session.get_vcloud_headers()
+ headers['Content-Type'] = 'application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml'
+ rest_url = "{}/api/vApp/vm-{}/media/action/insertMedia".format(vca.host,vm_id)
+
+ response = Http.post(url=rest_url,
+ headers=headers,
+ data=data,
+ verify=vca.verify,
+ logger=vca.logger)
+
+ if response.status_code != 202:
+ self.logger.error("Failed to insert CD-ROM to vm")
+ raise vimconn.vimconnException("insert_media_to_vm() : Failed to insert"\
+ "ISO image to vm")
+ else:
+ task = taskType.parseString(response.content, True)
+ if isinstance(task, GenericTask):
+ vca.block_until_completed(task)
+ self.logger.info("insert_media_to_vm(): Sucessfully inserted media ISO"\
+ " image to vm {}".format(vm_id))
+ except Exception as exp:
+ self.logger.error("insert_media_to_vm() : exception occurred "\
+ "while inserting media CD-ROM")
+ raise vimconn.vimconnException(message=exp)
+
+
+ def get_media_details(self, vca, content):
+ """
+ Method to get catalog item details
+ vca - connection object
+ content - Catalog details
+ Return - Media name, media id
+ """
+ cataloghref_list = []
+ try:
+ if content:
+ vm_list_xmlroot = XmlElementTree.fromstring(content)
+ for child in vm_list_xmlroot.iter():
+ if 'CatalogItem' in child.tag:
+ cataloghref_list.append(child.attrib.get('href'))
+ if cataloghref_list is not None:
+ for href in cataloghref_list:
+ if href:
+ response = Http.get(url=href,
+ headers=vca.vcloud_session.get_vcloud_headers(),
+ verify=vca.verify,
+ logger=vca.logger)
+ if response.status_code != 200:
+ self.logger.error("REST call {} failed reason : {}"\
+ "status code : {}".format(href,
+ response.content,
+ response.status_code))
+ raise vimconn.vimconnException("get_media_details : Failed to get "\
+ "catalogitem details")
+ list_xmlroot = XmlElementTree.fromstring(response.content)
+ for child in list_xmlroot.iter():
+ if 'Entity' in child.tag:
+ if 'media' in child.attrib.get('href'):
+ name = child.attrib.get('name')
+ media_id = child.attrib.get('href').split('/').pop()
+ return name,media_id
+ else:
+ self.logger.debug("Media name and id not found")
+ return False,False
+ except Exception as exp:
+ self.logger.error("get_media_details : exception occurred "\
+ "getting media details")
+ raise vimconn.vimconnException(message=exp)
+