예제 #1
0
    def get_images(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _hyper = ''
            
            _fmsg = "An error has occurred, but no error message was captured"

            _vmc_attr_list = self.osci.get_object(obj_attr_list["cloud_name"], "VMC", False, obj_attr_list["vmc"], False)
            _map_uuid_to_name = str2dic(_vmc_attr_list["images_uuid2name"])
            _map_name_to_uuid = str2dic(_vmc_attr_list["images_name2uuid"])
                
            if self.is_cloud_image_uuid(obj_attr_list["imageid1"]) :
                
                obj_attr_list["boot_volume_imageid1"] = obj_attr_list["imageid1"]                
                if obj_attr_list["imageid1"] in _map_uuid_to_name :
                    obj_attr_list["imageid1"] = _map_uuid_to_name[obj_attr_list["imageid1"]]
                    _status = 0                    
                else :
                    _fmsg = "image does not exist"
                    _status = 1817                    
            else :
                if obj_attr_list["imageid1"] in _map_name_to_uuid :
                    obj_attr_list["boot_volume_imageid1"] = _map_name_to_uuid[obj_attr_list["imageid1"]]
                    _status = 0                    
                else :
                    _fmsg = "image does not exist"
                    _status = 1817
#                    obj_attr_list["boot_volume_imageid1"] = self.generate_random_uuid(obj_attr_list["imageid1"])
            
        except Exception, e :
            _status = 23
            _fmsg = str(e)
예제 #2
0
    def vmcapture(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_crs = int(time())

            if obj_attr_list["captured_image_name"] == "auto":
                obj_attr_list["captured_image_name"] = obj_attr_list[
                    "name"] + "_at_" + str(_time_mark_crs)

            obj_attr_list[
                "mgt_102_capture_request_sent"] = _time_mark_crs - obj_attr_list[
                    "mgt_101_capture_request_originated"]

            self.common_messages("VM", obj_attr_list, "capturing", 0, '')

            _img_uuid = self.generate_random_uuid(
                obj_attr_list["captured_image_name"])
            _img_name = obj_attr_list["captured_image_name"]

            _vmc_attr_list = self.osci.get_object(obj_attr_list["cloud_name"],
                                                  "VMC", False,
                                                  obj_attr_list["vmc"], False)
            _map_uuid_to_name = str2dic(_vmc_attr_list["images_uuid2name"])
            _map_name_to_uuid = str2dic(_vmc_attr_list["images_name2uuid"])

            _map_uuid_to_name[_img_uuid] = _img_name
            _map_name_to_uuid[_img_name] = _img_uuid

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              obj_attr_list["vmc"], \
                                              False, \
                                              "images_uuid2name", \
                                              dic2str(_map_uuid_to_name), \
                                              False)

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              obj_attr_list["vmc"], \
                                              False, \
                                              "images_name2uuid", \
                                              dic2str(_map_name_to_uuid), \
                                              False)

            _time_mark_crc = int(time())
            obj_attr_list[
                "mgt_103_capture_request_completed"] = _time_mark_crc - _time_mark_crs

            _status = 0

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #3
0
    def imgdelete(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            self.common_messages("IMG", obj_attr_list, "deleting", 0, '')
            _img_name = obj_attr_list["name"]

            _vmc_attr_list = self.osci.get_object(obj_attr_list["cloud_name"],
                                                  "VMC", True,
                                                  obj_attr_list["vmc_name"],
                                                  False)
            _map_uuid_to_name = str2dic(_vmc_attr_list["images_uuid2name"])
            _map_name_to_uuid = str2dic(_vmc_attr_list["images_name2uuid"])

            if _img_name in _map_name_to_uuid:
                _img_uuid = _map_name_to_uuid[_img_name]
                obj_attr_list["boot_volume_imageid1"] = _img_uuid
                del _map_name_to_uuid[_img_name]
                del _map_uuid_to_name[_img_uuid]

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              _vmc_attr_list["uuid"], \
                                              False, \
                                              "images_uuid2name", \
                                              dic2str(_map_uuid_to_name), \
                                              False)

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              _vmc_attr_list["uuid"], \
                                              False, \
                                              "images_name2uuid", \
                                              dic2str(_map_name_to_uuid), \
                                              False)

            _status = 0

        except CldOpsException as obj:
            _status = obj.status
            _fmsg = str(obj.msg)

        except Exception as e:
            _status = 23
            _fmsg = str(e)

        finally:
            _status, _msg = self.common_messages("IMG", obj_attr_list,
                                                 "deleted", _status, _fmsg)
            return _status, _msg
예제 #4
0
    def vmcapture(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_crs = int(time())
            
            if obj_attr_list["captured_image_name"] == "auto" :
                obj_attr_list["captured_image_name"] = obj_attr_list["name"] + "_at_" + str(_time_mark_crs)
            
            obj_attr_list["mgt_102_capture_request_sent"] = _time_mark_crs - obj_attr_list["mgt_101_capture_request_originated"]
                      
            self.common_messages("VM", obj_attr_list, "capturing", 0, '')

            _img_uuid = self.generate_random_uuid(obj_attr_list["captured_image_name"])
            _img_name = obj_attr_list["captured_image_name"]
            
            _vmc_attr_list = self.osci.get_object(obj_attr_list["cloud_name"], "VMC", False, obj_attr_list["vmc"], False)
            _map_uuid_to_name = str2dic(_vmc_attr_list["images_uuid2name"])
            _map_name_to_uuid = str2dic(_vmc_attr_list["images_name2uuid"])

            _map_uuid_to_name[_img_uuid] = _img_name
            _map_name_to_uuid[_img_name] = _img_uuid
            
            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              obj_attr_list["vmc"], \
                                              False, \
                                              "images_uuid2name", \
                                              dic2str(_map_uuid_to_name), \
                                              False)

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              obj_attr_list["vmc"], \
                                              False, \
                                              "images_name2uuid", \
                                              dic2str(_map_name_to_uuid), \
                                              False)
            
            _time_mark_crc = int(time())
            obj_attr_list["mgt_103_capture_request_completed"] = _time_mark_crc - _time_mark_crs
            
            _status = 0
            
        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #5
0
    def check_images(self, vmc_name, vm_templates, vm_defaults) :
        '''
        TBD
        '''

        self.common_messages("IMG", { "name": vmc_name }, "checking", 0, '')

        _map_name_to_id = {}
        _map_id_to_name = {}

        _registered_image_list = []
        _registered_imageid_list = []

        for _vm_role in vm_templates.keys() :            
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid != "to_replace" :
                if _imageid in _map_name_to_id :                     
#                    vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                    True
                else :
                    if vm_defaults["docker_repo"] == "https://hub.docker.com/r/" and _imageid == "ibmcb/ubuntu_cb_nullworkload" :
                        if _imageid not in _registered_imageid_list :
                            _registered_imageid_list.append(_imageid)                        
#                    if check_url(vm_defaults["docker_repo"] + '/' + _imageid) :                    
#                        _map_name_to_id[_imageid] = "aaaa0" + ''.join(["%s" % randint(0, 9) for num in range(0, 59)])
#                        vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
#                        _registered_imageid_list.append(_map_name_to_id[_imageid])

        _detected_imageids = self.base_check_images(vmc_name, vm_templates, _registered_imageid_list, _map_id_to_name)

        if not _detected_imageids :
            return _detected_imageids

        return _detected_imageids
예제 #6
0
    def populate_interface(self, obj_attr_list) :
        '''
        A way to specify an alternative IP address for a hypervisor
        This alternative 'interface' represents a faster NIC
        (such as RDMA) to be used for other types of traffic
        '''

        for op in ["migrate", "protect"] :
            if str(obj_attr_list[op + "_supported"]).lower() != "true" :
                continue
        
            if op + "_interfaces" in obj_attr_list :
                interfaces = obj_attr_list[op + "_interfaces"]
                _ivmcs = str2dic(interfaces)
            else :
                interfaces = ""
                _ivmcs = {}
                
            for _host_uuid in obj_attr_list["hosts"].split(',') :
                obj_attr_list["host_list"][_host_uuid][op + "_interface"] = "default"
                
                if interfaces.strip() == "" :
                    continue
                
                hostname = obj_attr_list["host_list"][_host_uuid]["cloud_hostname"]
                if hostname in _ivmcs : 
                    iface = _ivmcs[hostname]
                    try :
                        obj_attr_list["host_list"][_host_uuid][op + "_interface"] = gethostbyname(iface)
                    except Exception, msg :
                        _fmsg = "Could not lookup interface " + iface + " for hostname " + hostname + " (probably bad /etc/hosts): " + str(msg)
                        raise CldOpsException(_fmsg, 1295)
예제 #7
0
    def vmcregister(self, obj_attr_list) :
        '''
        TBD
        '''
        _time_mark_prs = int(time())

        obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])            

        if "cleanup_on_attach" in obj_attr_list and obj_attr_list["cleanup_on_attach"] == "True" :
            self.vmccleanup(obj_attr_list)

        obj_attr_list["cloud_hostname"] = obj_attr_list["name"]
        
        _fmsg = "VMC " + obj_attr_list["uuid"] + " could not be registered "
        _fmsg += " on TAcloud \"" + obj_attr_list["cloud_name"] + "\"."

        self.connect(obj_attr_list["access"])
        _status, _fmsg, info = self.tacconn.node_register(obj_attr_list["name"])
        obj_attr_list.update(info)
        obj_attr_list["arrival"] = int(time())
        
        # A way to specify an alternative IP address for a hypervisor
        # This alternative 'destination' represents a faster NIC
        # (such as infiniband) to be used for other types of traffic
        _replication_vmcs = obj_attr_list["replication_vmcs"]
        if _replication_vmcs.strip() != "" :
            _rvmcs = str2dic(_replication_vmcs)
            if obj_attr_list["name"] in _rvmcs :
                try :
                    obj_attr_list["svm_destination"] = gethostbyname(_rvmcs[obj_attr_list["name"]])
                except Exception, msg :
                    _fmsg = "Could not lookup 'svm_destinations' " + _rvmcs[obj_attr_list["name"]] + " (probably bad /etc/hosts): " + str(msg)
                    raise CldOpsException(_fmsg, 1295)
예제 #8
0
    def process_script_output(self, obj_attr_list, current_step) :
        '''
        TBD
        '''

        _temp_dict = None
        if "execute_" + current_step + "_stdout" in obj_attr_list :
            if obj_attr_list["execute_" + current_step + "_stdout"].count("staging") or \
            obj_attr_list["execute_" + current_step + "_stdout"].count("tenant") :
                _temp_dict = str2dic(obj_attr_list["execute_" + current_step + "_stdout"].replace('\n',''), False)

        if _temp_dict :

            if obj_attr_list["name"].count("ai_") and current_step == "provision_originated":
                if "vm_extra_parms" not in obj_attr_list :
                    obj_attr_list["vm_extra_parms"] = ''                    
                else :
                    obj_attr_list["vm_extra_parms"] += ','
                                        
                for _key in _temp_dict.keys() :
                    if not _key.count("staging") :
                        obj_attr_list["vm_extra_parms"] += _key + '=' + _temp_dict[_key] + ','
                    else :
                        obj_attr_list["vm_attach_action"] = _temp_dict["vm_staging"]
                        
                obj_attr_list["vm_extra_parms"] = obj_attr_list["vm_extra_parms"][0:-1]
                obj_attr_list.update(_temp_dict)
            
            if obj_attr_list["name"].count("vm_") :
                obj_attr_list.update(_temp_dict)               


        return True
예제 #9
0
    def get_virtual_hardware_config(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _vhw_config = {}
            _vhw_config["pico32"] = "vcpus:1,vmemory:192,vstorage:2048,vnics:1"
            _vhw_config[
                "nano32"] = "vcpus:1,vmemory:512,vstorage:61440,vnics:1"
            _vhw_config[
                "micro32"] = "vcpus:1,vmemory:1024,vstorage:61440,vnics:1"
            _vhw_config[
                "copper32"] = "vcpus:1,vmemory:2048,vstorage:61440,vnics:1"
            _vhw_config[
                "bronze32"] = "vcpus:1,vmemory:2048,vstorage:179200,vnics:1"
            _vhw_config[
                "iron32"] = "vcpus:2,vmemory:2048,vstorage:179200,vnics:1"
            _vhw_config[
                "silver32"] = "vcpus:4,vmemory:2048,vstorage:358400,vnics:1"
            _vhw_config[
                "gold32"] = "vcpus:8,vmemory:4096,vstorage:358400,vnics:1"
            _vhw_config[
                "copper64"] = "vcpus:2,vmemory:4096,vstorage:61440,vnics:1"
            _vhw_config[
                "bronze64"] = "vcpus:2,vmemory:4096,vstorage:870400,vnics:1"
            _vhw_config[
                "silver64"] = "vcpus:4,vmemory:8192,vstorage:1048576,vnics:1"
            _vhw_config[
                "gold64"] = "vcpus:8,vmemory:16384,vstorage:1048576,vnics:1"
            _vhw_config[
                "rhodium64"] = "vcpus:16,vmemory:16384,vstorage:2097152,vnics:1"
            _vhw_config[
                "platinum64"] = "vcpus:24,vmemory:32768,vstorage:2097152,vnics:1"

            _vhw_config[
                "premium"] = "cpu_upper:1000,cpu_lower:1000,memory_upper:100,memory_lower:100"
            _vhw_config[
                "standard"] = "cpu_upper:1000,cpu_lower:500,memory_upper:100,memory_lower:50"
            _vhw_config[
                "value"] = "cpu_upper:-1,cpu_lower:0,memory_upper:100,memory_lower:0"

            if "size" not in obj_attr_list:
                obj_attr_list["size"] = "micro32"
            else:
                obj_attr_list["size"] = choice(
                    obj_attr_list["size"].strip().split(','))

            if "class" not in obj_attr_list:
                obj_attr_list["class"] = "standard"

            _curr_vhw_config = _vhw_config[obj_attr_list[
                "size"]] + ',' + _vhw_config[obj_attr_list["class"]]
            _curr_vhw_config = str2dic(_curr_vhw_config)
            obj_attr_list.update(_curr_vhw_config)
            _status = 0

        except Exception, e:
            _status = 23
            _fmsg = str(e)
예제 #10
0
    def check_images(self, vmc_name, vm_templates, access) :
        '''
        TBD
        '''
        self.common_messages("IMG", { "name": vmc_name }, "checking", 0, '')

        if access == "private" :    
            _registered_image_list = self.imageman.list_private_images()
        else :    
            _registered_image_list = self.imageman.list_public_images()   

        _registered_imageid_list = []

        _map_name_to_id = {}
        _map_id_to_name = {}

        for _registered_image in _registered_image_list :
            _registered_imageid_list.append(_registered_image["id"])
            _map_name_to_id[str(_registered_image["name"].encode('utf-8').strip())] = str(_registered_image["id"])

        for _vm_role in vm_templates.keys() :            
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid != "to_replace" :
                if _imageid in _map_name_to_id :                     
                    vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                else :
                    _map_name_to_id[_imageid] = '0' + ''.join(["%s" % randint(0, 9) for num in range(0, 5)]) + '0'
                    vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])                        

                _map_id_to_name[_map_name_to_id[_imageid]] = _imageid

        _detected_imageids = self.base_check_images(vmc_name, vm_templates, _registered_imageid_list, _map_id_to_name)

        return _detected_imageids
예제 #11
0
    def vmcreate(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            if obj_attr_list["role"] != "predictablevm" :
                obj_attr_list["cloud_uuid"] = self.generate_random_uuid()
            else :
                obj_attr_list["cloud_uuid"] = "11111111-1111-1111-1111-111111111111"

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"] + '-' + "vm_" + obj_attr_list["name"].split("_")[1] + '-' + obj_attr_list["role"]
            
            obj_attr_list["cloud_mac"] = self.generate_random_mac_address()
            self.get_virtual_hardware_config(obj_attr_list)

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            if obj_attr_list["role"] != "willfail" :
                True
            else :
                _status = 7778
                _msg = "Failed to create VM image"
                raise CldOpsException(_msg, _status)

            if "host_name" not in obj_attr_list :
                obj_attr_list["host_name"] = "simhost" + obj_attr_list["vmc_name"][-1]
                obj_attr_list["host_name"] += str(randint(0, int(obj_attr_list["hosts_per_vmc"])-1))

            if "meta_tags" in obj_attr_list :
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else :
                    obj_attr_list["meta_tags"] = "empty"
            else :
                obj_attr_list["meta_tags"] = "empty"
 
            self.take_action_if_requested("VM", obj_attr_list, "provision_started")
 
            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            obj_attr_list["arrival"] = int(time())

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #12
0
    def imgdelete(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            self.common_messages("IMG", obj_attr_list, "deleting", 0, '')
            _img_name = obj_attr_list["name"]

            _vmc_attr_list = self.osci.get_object(obj_attr_list["cloud_name"], "VMC", True, obj_attr_list["vmc_name"], False)
            _map_uuid_to_name = str2dic(_vmc_attr_list["images_uuid2name"])
            _map_name_to_uuid = str2dic(_vmc_attr_list["images_name2uuid"])                

            if _img_name in _map_name_to_uuid :
                _img_uuid = _map_name_to_uuid[_img_name]
                obj_attr_list["boot_volume_imageid1"] = _img_uuid
                del _map_name_to_uuid[_img_name]
                del _map_uuid_to_name[_img_uuid]
                
            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              _vmc_attr_list["uuid"], \
                                              False, \
                                              "images_uuid2name", \
                                              dic2str(_map_uuid_to_name), \
                                              False)

            self.osci.update_object_attribute(obj_attr_list["cloud_name"], \
                                              "VMC", \
                                              _vmc_attr_list["uuid"], \
                                              False, \
                                              "images_name2uuid", \
                                              dic2str(_map_name_to_uuid), \
                                              False)

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #13
0
    def vmcreate(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            if obj_attr_list["role"] != "predictablevm" :
                obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()
            else :
                obj_attr_list["cloud_vm_uuid"] = "11111111-1111-1111-1111-111111111111"

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"] + '-' + "vm_" + obj_attr_list["name"].split("_")[1] + '-' + obj_attr_list["role"]
            
            obj_attr_list["cloud_mac"] = self.generate_random_mac_address()
            self.get_virtual_hardware_config(obj_attr_list)

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            if obj_attr_list["role"] != "willfail" :
                True
            else :
                _status = 7778
                _msg = "Failed to create VM image"
                raise CldOpsException(_msg, _status)

            self.take_action_if_requested("VM", obj_attr_list, "provision_started")

            self.vm_placement(obj_attr_list)

            if "meta_tags" in obj_attr_list :
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else :
                    obj_attr_list["meta_tags"] = "empty"
            else :
                obj_attr_list["meta_tags"] = "empty"
  
            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            obj_attr_list["arrival"] = int(time())

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #14
0
    def check_images(self, vmc_name, vm_templates, vm_defaults):
        '''
        TBD
        '''
        self.common_messages("IMG", {"name": vmc_name}, "checking", 0, '')

        _map_name_to_id = {}
        _map_id_to_name = {}

        _wanted_images = []
        for _vm_role in vm_templates.keys():
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid not in _wanted_images and _imageid != "to_replace":
                if self.is_cloud_image_uuid(_imageid):
                    _wanted_images.append(_imageid)
                else:
                    if _imageid in _map_name_to_id:
                        vm_templates[_vm_role] = vm_templates[
                            _vm_role].replace(_imageid,
                                              _map_name_to_id[_imageid])
                    else:
                        _x_img = self.ec2conn.get_all_images(
                            filters={"name": _imageid + '*'})
                        if _x_img:
                            _map_name_to_id[_imageid] = _x_img[0].id
                            vm_templates[_vm_role] = vm_templates[
                                _vm_role].replace(_imageid,
                                                  _map_name_to_id[_imageid])
                            _wanted_images.append(_x_img[0].id)
                        else:
                            _map_name_to_id[_imageid] = "ami-" + '0' + ''.join(
                                ["%s" % randint(0, 9) for num in range(0, 6)])
                            vm_templates[_vm_role] = vm_templates[
                                _vm_role].replace(_imageid,
                                                  _map_name_to_id[_imageid])

                        _map_id_to_name[_map_name_to_id[_imageid]] = _imageid

        _registered_image_list = self.ec2conn.get_all_images(
            image_ids=_wanted_images)

        _registered_imageid_list = []

        for _registered_image in _registered_image_list:
            _registered_imageid_list.append(_registered_image.id)

        _detected_imageids = self.base_check_images(vmc_name, vm_templates,
                                                    _registered_imageid_list,
                                                    _map_id_to_name,
                                                    vm_defaults)

        return _detected_imageids
예제 #15
0
    def check_images(self, vmc_name, vm_templates, vmc_defaults, vm_defaults):
        '''
        TBD
        '''
        self.common_messages("IMG", {"name": vmc_name}, "checking", 0, '')

        _map_name_to_id = {}
        _map_uuid_to_name = {}

        _registered_imageid_list = []
        if True:
            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid != "to_replace":
                    if not self.is_cloud_image_uuid(_imageid):
                        if _imageid in _map_name_to_id:
                            vm_templates[_vm_role] = vm_templates[
                                _vm_role].replace(_imageid,
                                                  _map_name_to_id[_imageid])
                        else:
                            _map_name_to_id[
                                _imageid] = self.generate_random_uuid(_imageid)
                            _map_uuid_to_name[
                                _map_name_to_id[_imageid]] = _imageid
                            vm_templates[_vm_role] = vm_templates[
                                _vm_role].replace(_imageid,
                                                  _map_name_to_id[_imageid])

                        if _map_name_to_id[
                                _imageid] not in _registered_imageid_list:
                            _registered_imageid_list.append(
                                _map_name_to_id[_imageid])
                    else:
                        if _imageid not in _registered_imageid_list:
                            _registered_imageid_list.append(_imageid)

        _map_name_to_id["baseimg"] = self.generate_random_uuid("baseimg")
        _map_uuid_to_name[self.generate_random_uuid("baseimg")] = "baseimg"

        _detected_imageids = self.base_check_images(vmc_name, vm_templates,
                                                    _registered_imageid_list,
                                                    _map_uuid_to_name,
                                                    vm_defaults)

        if "images_uuid2name" not in vmc_defaults:
            vmc_defaults["images_uuid2name"] = dic2str(_map_uuid_to_name)

        if "images_name2uuid" not in vmc_defaults:
            vmc_defaults["images_name2uuid"] = dic2str(_map_name_to_id)

        return _detected_imageids
예제 #16
0
    def check_images(self, vmc_name, vm_templates, vm_defaults):
        '''
        TBD
        '''

        for _endpoint in list(self.lxdconn.keys()):

            self.common_messages("IMG", {
                "name": vmc_name,
                "endpoint": _endpoint
            }, "checking", 0, '')

            _map_name_to_id = {}
            _map_id_to_name = {}

            _registered_image_list = self.lxdconn[_endpoint].images.all()
            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image.fingerprint)
                if len(_registered_image.aliases):
                    _map_name_to_id[_registered_image.aliases[0]
                                    ["name"]] = _registered_image.fingerprint

            for _vm_role in list(vm_templates.keys()):
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid != "to_replace":
                    if _imageid in _map_name_to_id and _map_name_to_id[
                            _imageid] != _imageid:
                        vm_templates[_vm_role] = vm_templates[
                            _vm_role].replace(_imageid,
                                              _map_name_to_id[_imageid])
                    else:
                        _map_name_to_id[_imageid] = "aaaa0" + ''.join(
                            ["%s" % randint(0, 9) for num in range(0, 59)])
                        vm_templates[_vm_role] = vm_templates[
                            _vm_role].replace(_imageid,
                                              _map_name_to_id[_imageid])

                    _map_id_to_name[_map_name_to_id[_imageid]] = _imageid

            _detected_imageids = self.base_check_images(
                vmc_name, vm_templates, _registered_imageid_list,
                _map_id_to_name, vm_defaults)

            if not _detected_imageids:
                return _detected_imageids

        return _detected_imageids
예제 #17
0
    def vmdestroy(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_drs = int(time())

            if "mgt_901_deprovisioning_request_originated" not in obj_attr_list:
                obj_attr_list[
                    "mgt_901_deprovisioning_request_originated"] = _time_mark_drs

            obj_attr_list["mgt_902_deprovisioning_request_sent"] = \
                _time_mark_drs - int(obj_attr_list["mgt_901_deprovisioning_request_originated"])

            _msg = "Sending a termination request for " + obj_attr_list[
                "name"] + ""
            _msg += " (cloud-assigned uuid " + obj_attr_list[
                "cloud_vm_uuid"] + ")"
            _msg += "...."
            cbdebug(_msg, True)

            if obj_attr_list["host"] != "NA":
                self.host_resource_update(obj_attr_list, "destroy")

            _time_mark_drc = int(time())
            obj_attr_list["mgt_903_deprovisioning_request_completed"] = \
                _time_mark_drc - _time_mark_drs

            self.take_action_if_requested("VM", obj_attr_list,
                                          "deprovision_finished")

            if "execute_deprovision_finished_stdout" in obj_attr_list:
                if obj_attr_list["execute_deprovision_finished_stdout"].count(
                        "tenant"):
                    _temp_dict = str2dic(
                        obj_attr_list["execute_deprovision_finished_stdout"].
                        replace('\n', ''))
                    obj_attr_list.update(_temp_dict)

            _status = 0

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #18
0
    def check_images(self, vmc_name, vm_templates, http_conn_id):
        '''
        TBD
        '''
        self.common_messages("IMG", {"name": vmc_name}, "checking", 0, '')

        _map_name_to_id = {}
        _map_id_to_name = {}

        _registered_image_list = []
        _registered_images = self.gceconn.images().list(
            project=self.images_project).execute(
                http=self.http_conn[http_conn_id])
        if "items" in _registered_images:
            _registered_image_list = _registered_images["items"]

        _registered_imageid_list = []

        for _registered_image in _registered_image_list:
            _registered_imageid_list.append(_registered_image["id"])
            _map_name_to_id[
                _registered_image["name"]] = _registered_image["id"]

        for _vm_role in vm_templates.keys():
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]

            if _imageid != "to_replace":
                if _imageid in _map_name_to_id:
                    vm_templates[_vm_role] = vm_templates[_vm_role].replace(
                        _imageid, _map_name_to_id[_imageid])
                else:
                    _map_name_to_id[_imageid] = "00000" + ''.join(
                        ["%s" % randint(0, 9) for num in range(0, 14)])
                    vm_templates[_vm_role] = vm_templates[_vm_role].replace(
                        _imageid, _map_name_to_id[_imageid])

                _map_id_to_name[_map_name_to_id[_imageid]] = _imageid

        _detected_imageids = self.base_check_images(vmc_name, vm_templates,
                                                    _registered_imageid_list,
                                                    _map_id_to_name)

        return _detected_imageids
예제 #19
0
    def noderegister(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            obj_attr_list["uuid"] = "undefined"

            _fmsg = "Hypervisor node \"" + obj_attr_list["name"] + "\" ("
            _fmsg = obj_attr_list["uuid"] + ") could not be registered "
            _fmsg += " on this Parallel Libvirt Manager."

            self.connect(obj_attr_list["access"])
            _status, _msg, _info = self.plmconn.node_register(
                obj_attr_list["name"], obj_attr_list["function"])
            obj_attr_list.update(_info)
            obj_attr_list["uuid"] = obj_attr_list["cloud_uuid"]
            obj_attr_list["arrival"] = int(time())

            # A way to specify an alternative IP address for a hypervisor
            # This alternative 'destination' represents a faster NIC
            # (such as infiniband) to be used for other types of traffic

            if "replication_nodes" in obj_attr_list:
                _replication_nodes = obj_attr_list["replication_nodes"]
            else:
                _replication_nodes = ""

            if _replication_nodes.strip() != "":
                _rnodes = str2dic(_replication_nodes)
                if obj_attr_list["name"] in _rnodes:
                    obj_attr_list["svm_destination"] = gethostbyname(
                        _rnodes[obj_attr_list["name"]])

            if "svm_destination" not in obj_attr_list:
                obj_attr_list["svm_destination"] = obj_attr_list["cloud_ip"]

            cbdebug(_msg, True)
            return _status, _msg, obj_attr_list

        except PLMException, obj:
            status = obj.status
            _fmsg = "PLM Exception: " + obj.msg
            return status, _fmsg, None
예제 #20
0
    def get_virtual_hardware_config(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _vhw_config = {}
            _vhw_config["pico32"] = "vcpus:1,vmemory:192,vstorage:2048,vnics:1"
            _vhw_config["nano32"] = "vcpus:1,vmemory:512,vstorage:61440,vnics:1"
            _vhw_config["micro32"] = "vcpus:1,vmemory:1024,vstorage:61440,vnics:1"
            _vhw_config["copper32"] = "vcpus:1,vmemory:2048,vstorage:61440,vnics:1"
            _vhw_config["bronze32"] = "vcpus:1,vmemory:2048,vstorage:179200,vnics:1"
            _vhw_config["iron32"] = "vcpus:2,vmemory:2048,vstorage:179200,vnics:1"
            _vhw_config["silver32"] = "vcpus:4,vmemory:2048,vstorage:358400,vnics:1"
            _vhw_config["gold32"] = "vcpus:8,vmemory:4096,vstorage:358400,vnics:1"
            _vhw_config["copper64"] = "vcpus:2,vmemory:4096,vstorage:61440,vnics:1"
            _vhw_config["bronze64"]  = "vcpus:2,vmemory:4096,vstorage:870400,vnics:1"
            _vhw_config["silver64"] = "vcpus:4,vmemory:8192,vstorage:1048576,vnics:1"
            _vhw_config["gold64"] = "vcpus:8,vmemory:16384,vstorage:1048576,vnics:1"
            _vhw_config["rhodium64"] = "vcpus:16,vmemory:16384,vstorage:2097152,vnics:1"
            _vhw_config["platinum64"] = "vcpus:24,vmemory:32768,vstorage:2097152,vnics:1"
                
            _vhw_config["premium"] = "cpu_upper:1000,cpu_lower:1000,memory_upper:100,memory_lower:100"
            _vhw_config["standard"] = "cpu_upper:1000,cpu_lower:500,memory_upper:100,memory_lower:50"
            _vhw_config["value"] = "cpu_upper:-1,cpu_lower:0,memory_upper:100,memory_lower:0"
            
            if "size" not in obj_attr_list :
                obj_attr_list["size"] = "micro32"
            else :
                obj_attr_list["size"] = choice(obj_attr_list["size"].strip().split(','))

            if "class" not in obj_attr_list :
                obj_attr_list["class"] = "standard"
            
            _curr_vhw_config = _vhw_config[obj_attr_list["size"]] + ',' + _vhw_config[obj_attr_list["class"]]
            _curr_vhw_config = str2dic(_curr_vhw_config)
            obj_attr_list.update(_curr_vhw_config)
            _status = 0
        
        except Exception, e :
            _status = 23
            _fmsg = str(e)
예제 #21
0
파일: plm_ops.py 프로젝트: Leonid99/cbtool
    def noderegister(self, obj_attr_list) :
        '''
        TBD
        '''
        try :    
            obj_attr_list["uuid"] = "undefined"
            
            _fmsg = "Hypervisor node \"" + obj_attr_list["name"] + "\" ("
            _fmsg = obj_attr_list["uuid"] + ") could not be registered "
            _fmsg += " on this Parallel Libvirt Manager."
    
            self.connect(obj_attr_list["access"])
            _status, _msg, _info = self.plmconn.node_register(obj_attr_list["name"], obj_attr_list["function"])
            obj_attr_list.update(_info)
            obj_attr_list["uuid"] = obj_attr_list["cloud_uuid"]
            obj_attr_list["arrival"] = int(time())
            
            # A way to specify an alternative IP address for a hypervisor
            # This alternative 'destination' represents a faster NIC
            # (such as infiniband) to be used for other types of traffic
            
            if "replication_nodes" in obj_attr_list :
                _replication_nodes = obj_attr_list["replication_nodes"]
            else :
                _replication_nodes = ""
    
            if _replication_nodes.strip() != "" :
                _rnodes = str2dic(_replication_nodes)
                if obj_attr_list["name"] in _rnodes :
                    obj_attr_list["svm_destination"] = gethostbyname(_rnodes[obj_attr_list["name"]])
                
            if "svm_destination" not in obj_attr_list :
                obj_attr_list["svm_destination"] = obj_attr_list["cloud_ip"]

            cbdebug(_msg, True)
            return _status, _msg, obj_attr_list

        except PLMException, obj :
            status = obj.status
            _fmsg = "PLM Exception: " + obj.msg
            return status, _fmsg, None
예제 #22
0
    def vmdestroy(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _time_mark_drs = int(time())
            
            if "mgt_901_deprovisioning_request_originated" not in obj_attr_list :
                obj_attr_list["mgt_901_deprovisioning_request_originated"] = _time_mark_drs
                
            obj_attr_list["mgt_902_deprovisioning_request_sent"] = \
                _time_mark_drs - int(obj_attr_list["mgt_901_deprovisioning_request_originated"])

            _msg = "Sending a termination request for "  + obj_attr_list["name"] + ""
            _msg += " (cloud-assigned uuid " + obj_attr_list["cloud_vm_uuid"] + ")"
            _msg += "...."
            cbdebug(_msg, True)

            if obj_attr_list["host"] != "NA" :
                self.host_resource_update(obj_attr_list, "destroy")

            _time_mark_drc = int(time())
            obj_attr_list["mgt_903_deprovisioning_request_completed"] = \
                _time_mark_drc - _time_mark_drs

            self.take_action_if_requested("VM", obj_attr_list, "deprovision_finished")

            if "execute_deprovision_finished_stdout" in obj_attr_list :
                if obj_attr_list["execute_deprovision_finished_stdout"].count("tenant") :
                    _temp_dict = str2dic(obj_attr_list["execute_deprovision_finished_stdout"].replace('\n',''))
                    obj_attr_list.update(_temp_dict)
                    
            _status = 0
            
        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #23
0
    def check_images(self, vmc_name, vm_templates, vmc_defaults) :
        '''
        TBD
        '''
        self.common_messages("IMG", { "name": vmc_name }, "checking", 0, '')
  
        _map_name_to_id = {}
        _map_uuid_to_name = {}
        
        _registered_imageid_list = []
        if True :
            for _vm_role in vm_templates.keys() :
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid != "to_replace" :
                    if not self.is_cloud_image_uuid(_imageid) :
                        if _imageid in _map_name_to_id :
                            vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                        else :
                            _map_name_to_id[_imageid] = self.generate_random_uuid(_imageid)
                            _map_uuid_to_name[_map_name_to_id[_imageid]] = _imageid                                              
                            vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
    
                        if _map_name_to_id[_imageid] not in _registered_imageid_list :
                            _registered_imageid_list.append(_map_name_to_id[_imageid])  
                    else :
                        if _imageid not in _registered_imageid_list :
                            _registered_imageid_list.append(_imageid)

        _map_name_to_id["baseimg"] = self.generate_random_uuid("baseimg")
        _map_uuid_to_name[self.generate_random_uuid("baseimg")] = "baseimg"

        _detected_imageids = self.base_check_images(vmc_name, vm_templates, _registered_imageid_list, _map_uuid_to_name)

        if "images_uuid2name" not in vmc_defaults :
            vmc_defaults["images_uuid2name"] = dic2str(_map_uuid_to_name)

        if "images_name2uuid" not in vmc_defaults :            
            vmc_defaults["images_name2uuid"] = dic2str(_map_name_to_id)
                
        return _detected_imageids
예제 #24
0
    def check_images(self, vmc_name, vm_templates) :
        '''
        TBD
        '''
        self.common_messages("IMG", { "name": vmc_name }, "checking", 0, '')

        _map_name_to_id = {}
        _map_id_to_name = {}
        
        _wanted_images = []
        for _vm_role in vm_templates.keys() :
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid not in _wanted_images and _imageid != "to_replace" :
                if self.is_cloud_image_uuid(_imageid) :
                    _wanted_images.append(_imageid)
                else :
                    if _imageid in _map_name_to_id :
                        vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                    else :                        
                        _x_img = self.ec2conn.get_all_images(filters = {"name": _imageid + '*'})
                        if _x_img:
                            _map_name_to_id[_imageid] = _x_img[0].id    
                            vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                            _wanted_images.append(_x_img[0].id)
                        else :
                            _map_name_to_id[_imageid] = "ami-" + '0' + ''.join(["%s" % randint(0, 9) for num in range(0, 6)])
                            vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])

                        _map_id_to_name[_map_name_to_id[_imageid]] = _imageid
                        
        _registered_image_list = self.ec2conn.get_all_images(image_ids=_wanted_images)
                        
        _registered_imageid_list = []

        for _registered_image in _registered_image_list :
            _registered_imageid_list.append(_registered_image.id)

        _detected_imageids = self.base_check_images(vmc_name, vm_templates, _registered_imageid_list, _map_id_to_name)

        return _detected_imageids
예제 #25
0
    def process_script_output(self, obj_attr_list, current_step):
        '''
        TBD
        '''

        _temp_dict = None
        if "execute_" + current_step + "_stdout" in obj_attr_list:
            if obj_attr_list["execute_" + current_step + "_stdout"].count("staging") or \
            obj_attr_list["execute_" + current_step + "_stdout"].count("tenant") :
                _temp_dict = str2dic(
                    obj_attr_list["execute_" + current_step +
                                  "_stdout"].replace('\n', ''), False)

        if _temp_dict:

            if obj_attr_list["name"].count(
                    "ai_") and current_step == "provision_originated":
                if "vm_extra_parms" not in obj_attr_list:
                    obj_attr_list["vm_extra_parms"] = ''
                else:
                    obj_attr_list["vm_extra_parms"] += ','

                for _key in _temp_dict.keys():
                    if not _key.count("staging"):
                        obj_attr_list[
                            "vm_extra_parms"] += _key + '=' + _temp_dict[
                                _key] + ','
                    else:
                        obj_attr_list["vm_attach_action"] = _temp_dict[
                            "vm_staging"]

                obj_attr_list["vm_extra_parms"] = obj_attr_list[
                    "vm_extra_parms"][0:-1]
                obj_attr_list.update(_temp_dict)

            if obj_attr_list["name"].count("vm_"):
                obj_attr_list.update(_temp_dict)

        return True
예제 #26
0
    def check_images(self, vmc_name, vm_templates) :
        '''
        TBD
        '''

        for _endpoint in self.lxdconn.keys() :

            self.common_messages("IMG", { "name": vmc_name, "endpoint" : _endpoint }, "checking", 0, '')

            _map_name_to_id = {}
            _map_id_to_name = {}

            _registered_image_list = self.lxdconn[_endpoint].images.all()
            _registered_imageid_list = []
                
            for _registered_image in _registered_image_list :
                _registered_imageid_list.append(_registered_image.fingerprint)
                if len(_registered_image.aliases) :
                    _map_name_to_id[_registered_image.aliases[0]["name"]] = _registered_image.fingerprint
                
            for _vm_role in vm_templates.keys() :            
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
                if _imageid != "to_replace" :
                    if _imageid in _map_name_to_id :                     
                        vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])
                    else :
                        _map_name_to_id[_imageid] = "aaaa0" + ''.join(["%s" % randint(0, 9) for num in range(0, 59)])
                        vm_templates[_vm_role] = vm_templates[_vm_role].replace(_imageid, _map_name_to_id[_imageid])                        

                    _map_id_to_name[_map_name_to_id[_imageid]] = _imageid
                
            _detected_imageids = self.base_check_images(vmc_name, vm_templates, _registered_imageid_list, _map_id_to_name)

            if not _detected_imageids :
                return _detected_imageids  

        return _detected_imageids
예제 #27
0
    def populate_interface(self, obj_attr_list):
        '''
        A way to specify an alternative IP address for a hypervisor
        This alternative 'interface' represents a faster NIC
        (such as RDMA) to be used for other types of traffic
        '''

        for op in ["migrate", "protect"]:
            if str(obj_attr_list[op + "_supported"]).lower() != "true":
                continue

            if op + "_interfaces" in obj_attr_list:
                interfaces = obj_attr_list[op + "_interfaces"]
                _ivmcs = str2dic(interfaces)
            else:
                interfaces = ""
                _ivmcs = {}

            for _host_uuid in obj_attr_list["hosts"].split(','):
                obj_attr_list["host_list"][_host_uuid][
                    op + "_interface"] = "default"

                if interfaces.strip() == "":
                    continue

                hostname = obj_attr_list["host_list"][_host_uuid][
                    "cloud_hostname"]
                if hostname in _ivmcs:
                    iface = _ivmcs[hostname]
                    try:
                        obj_attr_list["host_list"][_host_uuid][
                            op + "_interface"] = gethostbyname(iface)
                    except Exception, msg:
                        _fmsg = "Could not lookup interface " + iface + " for hostname " + hostname + " (probably bad /etc/hosts): " + str(
                            msg)
                        raise CldOpsException(_fmsg, 1295)
예제 #28
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates, vm_defaults) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.connect(access, credentials, vmc_name)

            _msg = "Checking if the ssh key pair \"" + key_name + "\" is created"
            _msg += " on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _key_pair_found = False
            for _key_pair in self.ec2conn.get_all_key_pairs() :
                if _key_pair.name == key_name :
                    _key_pair_found = True

            if not _key_pair_found :
                _msg = "ERROR! Please create the ssh key pair \"" + key_name + "\" in "
                _msg += "Amazon EC2 before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = "Checking if the security group \"" + security_group_name
            _msg += "\" is created on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _security_group_found = False
            for security_group in self.ec2conn.get_all_security_groups() :
                if security_group.name == security_group_name :
                    _security_group_found = True

            if not _security_group_found :
                _msg = "ERROR! Please create the security group \"" + security_group_name + "\" in "
                _msg += "Amazon EC2 before proceeding."
                _fmsg = _msg
                cberr(_msg, True)
            
            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _wanted_images = []
            for _vm_role in vm_templates.keys() :
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid.count("ami-") and _imageid not in _wanted_images :
                    _wanted_images.append(_imageid)

            _registered_image_list = self.ec2conn.get_all_images(image_ids=_wanted_images)
            _registered_imageid_list = []

            for _registered_image in _registered_image_list :
                _registered_imageid_list.append(_registered_image.id)

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys() :
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
                if _imageid.count("ami-") :
                    if _imageid not in _required_imageid_list :
                        _required_imageid_list[_imageid] = []
                    _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys() :
                
                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list :
                    if str(_registered_imageid).count(_imageid) :
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else :
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected :
                    True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
                else :
                    _msg = "xWARNING Image id for VM roles \""
                    _msg += ','.join(_required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"
            
            if not len(_detected_imageids) :
                _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
                _msg += " in this EC2 cloud. Please register at least one "
                _msg += "of the following images: " + ','.join(_undetected_imageids.keys())
                _fmsg = _msg 
                cberr(_msg, True)
            else :
                _msg = _msg.replace("yx",'')
                _msg = _msg.replace('x',"         ")
                _msg = _msg[:-2]
                if len(_msg) :
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found and len(_detected_imageids)) :
                _fmsg += ": Check the previous errors, fix it (using EC2's web"
                _fmsg += " GUI (AWS Console) or ec2-* CLI utilities"
                _status = 1178
                raise CldOpsException(_fmsg, _status) 

            _status = 0

        except CldOpsException, obj :
            _fmsg = str(obj.msg)
            _status = 2
예제 #29
0
    def vmcreate(self, obj_attr_list):
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _instance = False

            self.determine_instance_name(obj_attr_list)
            self.determine_key_name(obj_attr_list)
            obj_attr_list["last_known_state"] = "about to connect to " + self.get_description() + " manager"

            obj_attr_list["userdata"] = self.populate_cloudconfig(obj_attr_list)
            if obj_attr_list["userdata"]:
                obj_attr_list["config_drive"] = True
            else:
                obj_attr_list["config_drive"] = None

            _mark_a = time()
            self.vm_placement(obj_attr_list)
            self.annotate_time_breakdown(obj_attr_list, "vm_placement_time", _mark_a)

            _meta = {}
            if "meta_tags" in obj_attr_list:
                if obj_attr_list["meta_tags"] != "empty" and \
                        obj_attr_list["meta_tags"].count(':') and \
                        obj_attr_list["meta_tags"].count(','):
                    _meta = str2dic(obj_attr_list["meta_tags"])

            _fip = None

            _meta["experiment_id"] = obj_attr_list["experiment_id"]

            if "cloud_floating_ip_uuid" in obj_attr_list:
                _meta["cloud_floating_ip_uuid"] = obj_attr_list["cloud_floating_ip_uuid"]

            _time_mark_prs = int(time())

            obj_attr_list["mgt_002_provisioning_request_sent"] = \
                _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            self.vvcreate(obj_attr_list)

            self.common_messages("VM", obj_attr_list, "creating", 0, '')

            self.pre_vmcreate_process(obj_attr_list)

            # zstack create vm
            cond = self.zsk_gen_query_conditions('name', '=', obj_attr_list["size"])
            ins_offering_uuid = \
            self.zsk_query_resource(obj_attr_list["access"], 'instance-offerings', cond)['inventories'][0]['uuid']

            self.get_images(obj_attr_list)
            cond = self.zsk_gen_query_conditions('name', '=', obj_attr_list["imagename"])
            image_uuid = self.zsk_query_resource(obj_attr_list["access"], 'images', cond)['inventories'][0]['uuid']

            cond = self.zsk_gen_query_conditions('name', '=', obj_attr_list["netname"])
            net_uuid = self.zsk_query_resource(obj_attr_list["access"], 'l3-networks', cond)['inventories'][0]['uuid']

            cond = self.zsk_gen_query_conditions('name', '=', obj_attr_list["disk_size"])
            disk_uuid = \
            self.zsk_query_resource(obj_attr_list["access"], 'disk-offerings', cond)['inventories'][0]['uuid']

            _instance = self.zsk_create_vm(access=obj_attr_list['access'],
                                       name=obj_attr_list["cloud_vm_name"],
                                       ins_offering_uuid=ins_offering_uuid,
                                       image_uuid=image_uuid,
                                       l3_uuid=net_uuid,
                                       disk_offering_uuid=disk_uuid)
            if _instance.get('inventory'):
                obj_attr_list["cloud_vm_uuid"] = _instance['inventory']['uuid']
                obj_attr_list["cloud_vv_uuid"] = 'none'
                for volume in _instance["inventory"]["allVolumes"]:
                    if volume["type"] == "Data":
                        obj_attr_list["cloud_vv_uuid"] = volume['uuid']
                        break

                obj_attr_list["instance_obj"] = _instance["inventory"]
                obj_attr_list["arrival"] = int(time())

                self.take_action_if_requested("VM", obj_attr_list, "provision_started")

                _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)
                _status = 0

                self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)
                obj_attr_list["host_name"] = "unknown"

                _status = 0

                if str(obj_attr_list["force_failure"]).lower() == "true":
                    _fmsg = "Forced failure (option FORCE_FAILURE set \"true\")"
                    _status = 916

                self.take_action_if_requested("VM", obj_attr_list, "provision_finished")

        except KeyboardInterrupt:
            _status = 42
            _fmsg = "CTRL-C interrupt"
            cbdebug("VM create keyboard interrupt...", True)

        except Exception, e:
            _status = 23
            _fmsg = str(e)
            cberr(traceback.format_exc())
예제 #30
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates, vm_defaults) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            
            _apikey, _secretkey = credentials.split('|')

            self.connect(access, _apikey, _secretkey)
            
            _zoneid = self.get_zone(vmc_name)

            _msg = "Checking if the ssh key pair \"" + key_name + "\" is created"
            _msg += " on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _key_pair_found = False
            for _key_pair in self.cskconn.listSSHKeyPairs() :
                if _key_pair[u'name'] == key_name :
                    _key_pair_found = True

            if not _key_pair_found :
                _msg = "ERROR! Please create the ssh key pair \"" + key_name + "\" in "
                _msg += "CloudPlatform before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = "Checking if the security group \"" + security_group_name
            _msg += "\" is created on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _security_group_found = False
            for security_group in self.cskconn.listSecurityGroups() :
                if security_group[u'name'] == security_group_name :
                    _security_group_found = True

            if not _security_group_found :
                _msg = "ERROR! Please create the security group \"" + security_group_name + "\" in "
                _msg += "CloudPlatform before proceeding."
                _fmsg = _msg
                cberr(_msg, True)
            
            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _registered_image_list = self.cskconn.listTemplates({u'zoneid' : _zoneid, u'templatefilter' : u'executable'})
            _registered_imageid_list = []

            for _registered_image in _registered_image_list :
                _registered_imageid_list.append(_registered_image[u'name'].replace(" ", ""))

            _required_imageid_list = {}


            for _vm_role in vm_templates.keys() :
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
                if _imageid not in _required_imageid_list :
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys() :
                
                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list :
                    if str(_registered_imageid).count(_imageid) :
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else :
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected :
                    True
                else :
                    _msg = "xWARNING Image id for VM roles \""
                    _msg += ','.join(_required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"
            
            if not len(_detected_imageids) :
                _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
                _msg += " in this cloudPlatform. Please register at least one "
                _msg += "of the following images: " + ','.join(_undetected_imageids.keys())
                _fmsg = _msg 
                cberr(_msg, True)
            else :
                _msg = _msg.replace("yx",'')
                _msg = _msg.replace('x',"         ")
                _msg = _msg[:-2]
                if len(_msg) :
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found and len(_detected_imageids)) :
                _msg = "Check the previous errors, fix it (using CloudStack's web"
                _msg += " GUI (horizon) or nova CLI"
                _status = 1178
                raise CldOpsException(_msg, _status) 

            _status = 0

        except CldOpsException, obj :
            _fmsg = str(obj.msg)
            _status = 2
예제 #31
0
    def vmcreate(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            if obj_attr_list["role"] != "predictablevm" :
                obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()
            else :
                obj_attr_list["cloud_vm_uuid"] = "11111111-1111-1111-1111-111111111111"

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"] 
            obj_attr_list["cloud_vm_name"] += '-' + "vm_" + obj_attr_list["name"].split("_")[1] 
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none" :            
                obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list["cloud_vm_name"].replace("_", "-")            

            obj_attr_list["cloud_mac"] = self.generate_random_mac_address()
            self.get_virtual_hardware_config(obj_attr_list)

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            if obj_attr_list["role"] != "willfail" :
                True
            else :
                _status = 7778
                _msg = "Failed to create VM image"
                raise CldOpsException(_msg, _status)

            self.take_action_if_requested("VM", obj_attr_list, "provision_started")

            self.vm_placement(obj_attr_list)

            if "meta_tags" in obj_attr_list :
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else :
                    obj_attr_list["meta_tags"] = "empty"
            else :
                obj_attr_list["meta_tags"] = "empty"
  
            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "utc_offset_on_vm", "3600") 
            
            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "mgt_006_instance_preparation", "1")

            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "status", "Application starting up...") 

            obj_attr_list["arrival"] = int(time())

            _status = 0

            if obj_attr_list["force_failure"].lower() == "true" :
                _fmsg = "Forced failure (option FORCE_FAILURE set \"true\")"                
                _status = 916

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #32
0
    def get_instances(self, obj_attr_list, obj_type = "pod", identifier = "all") :
        '''
        TBD
        '''

        _instances = False
        _fmsg = "Error while getting instances"
        _call = "NA"

        try :

            if obj_type == "pod" :
                _call = "containers()"
                if identifier == "all" :
                    _instances = pykube.objects.Pod.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"])
                                                                   
                else :
                    
                    if "cloud_vm_exact_match_name" in obj_attr_list :
                        identifier = obj_attr_list["cloud_vm_exact_match_name"]
                        _instances = pykube.objects.Pod.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                      field_selector={"metadata.name": identifier})

                    elif "selector" in obj_attr_list :
                        _selector = str2dic(obj_attr_list["selector"])
                        _instances = pykube.objects.Pod.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                          selector= _selector)

                    else :
                        _instances = pykube.objects.Pod.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                      field_selector={"metadata.name": identifier})


            elif obj_type == "replicaset" :
                if identifier == "all" :
                    _instances = pykube.objects.ReplicaSet.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"])
                else :
                    if "cloud_rs_exact_match_name" in obj_attr_list  :
                        identifier = obj_attr_list["cloud_rs_exact_match_name"]
                        _instances = pykube.objects.ReplicaSet.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                      field_selector={"metadata.name": identifier})
                                                
                    elif "selector" in obj_attr_list :
                        _selector = str2dic(obj_attr_list["selector"])
                        _instances = pykube.objects.ReplicaSet.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                             selector= _selector)

                    else :
                        _instances = pykube.objects.ReplicaSet.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                      field_selector={"metadata.name": identifier})
                        
            elif obj_type == "deployment" :
                if identifier == "all" :
                    _instances = pykube.objects.Deployment.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"])
                else :
                    if "selector" in obj_attr_list :
                        _selector = str2dic(obj_attr_list["selector"])
                        _instances = pykube.objects.Deployment.objects(self.kubeconn).filter(namespace = obj_attr_list["namespace"], \
                                                                                      selector= _selector)
                                            
            else :
                _call = "volumes()"                    
                if identifier == "all" :
                    True 
                else :
                    True
                        
            if _instances :
                for _x in _instances :
                    _instances = _x

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _xfmsg = str(obj.msg)
예제 #33
0
    def take_action_if_requested(self, obj_type, obj_attr_list, current_step):
        '''
        TBD
        '''

        if "staging" not in obj_attr_list :
            return

        if not obj_attr_list["staging"].count(current_step) :
            return

        if obj_attr_list["staging"] + "_complete" in obj_attr_list : 
            return

        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            if obj_attr_list["staging"] == "pause_" + current_step :

                if current_step == "provision_originated" :
                    obj_attr_list["last_known_state"] = "waiting for signal"

                _max_tries = int(obj_attr_list["update_attempts"])
                _wait = int(obj_attr_list["update_frequency"])

                # Always subscribe for the VM channel, no matter the object
                _sub_channel = self.osci.subscribe(obj_attr_list["cloud_name"], "VM", "staging", _max_tries * _wait)
    
                if obj_type == "VM" and obj_attr_list["ai"] != "none" and current_step.count("all_vms") :
                    _target_uuid = obj_attr_list["ai"]
                    _target_name = obj_attr_list["ai_name"]
                    _cloud_vm_uuid = obj_attr_list["cloud_vm_uuid"] 
                else :
                    _target_uuid = obj_attr_list["uuid"]
                    _target_name = obj_attr_list["name"]
                    _cloud_vm_uuid = _target_uuid

                self.osci.publish_message(obj_attr_list["cloud_name"], \
                                          obj_type, \
                                          "staging", \
                                          _target_uuid + ";vmready;" + dic2str(obj_attr_list),\
                                           1, \
                                           3600)

                _msg = obj_type + ' ' + _cloud_vm_uuid + " ("
                _msg += _target_name + ") pausing on attach for continue signal ...."
                cbdebug(_msg, True)

                for _message in _sub_channel.listen() :
                    _args = str(_message["data"]).split(";")
                    
                    if len(_args) != 3 :
#                        cbdebug("Message is not for me: " + str(_args))
                        continue

                    _id, _status, _info = _args
    
                    if (_id == _target_uuid or _id == _target_name) and _status == "continue" :
                        obj_attr_list[obj_attr_list["staging"] + "_complete"] = int(time())

                        if _info.count(":") :

                            _add_obj_attr_list = str2dic(_info) 
                            obj_attr_list.update(_add_obj_attr_list)
                            
                        _status = 0
                        break

                _sub_channel.unsubscribe()

                _status = 0

            elif obj_attr_list["staging"] == "execute_" + current_step :

                if current_step == "provision_originated" :
                    obj_attr_list["last_known_state"] = "about to execute script"

                _proc_man = ProcessManagement(username = obj_attr_list["username"], \
                                              cloud_name = obj_attr_list["cloud_name"])

                _json_contents = copy.deepcopy(obj_attr_list)

                if obj_type == "AI" :
                    _json_contents["vms"] = {}

                    if "vms" in obj_attr_list and current_step != "deprovision_finished" :
                        _vm_id_list = obj_attr_list["vms"].split(',')
                        for _vm_id in _vm_id_list :
                            _vm_uuid = _vm_id.split('|')[0]
                            _vm_attr_list = self.osci.get_object(obj_attr_list["cloud_name"], "VM", False, _vm_uuid, False)
                            _json_contents["vms"][_vm_attr_list["uuid"]] = _vm_attr_list 

                obj_attr_list["execute_json_filename"] = "/tmp/" 
                obj_attr_list["execute_json_filename"] += obj_attr_list["execute_json_filename_prefix"]
                obj_attr_list["execute_json_filename"] += "_vapp_" + obj_attr_list["cloud_name"] 
                obj_attr_list["execute_json_filename"] += "_" + obj_attr_list["name"] + "_" 
                obj_attr_list["execute_json_filename"] += obj_attr_list["uuid"] + ".json"

                _json_fh = open(obj_attr_list["execute_json_filename"], 'w')
                _json_fh.write(json.dumps(_json_contents, sort_keys = True, indent = 4))
                _json_fh.close()

                _msg = "JSON contents written to " 
                _msg += obj_attr_list["execute_json_filename"] + '.'
                cbdebug(_msg, True)

                _cmd = obj_attr_list["execute_script_name"] + ' '
                _cmd += obj_attr_list["execute_json_filename"]

                _status, _result_stdout, _result_stderr = _proc_man.run_os_command(_cmd)

                _msg = "Command \"" + _cmd + "\" executed, with return code " + str(_status)
                cbdebug(_msg, True)

                obj_attr_list[obj_attr_list["staging"] + "_stdout"] = _result_stdout
                obj_attr_list[obj_attr_list["staging"] + "_stderr"] = _result_stderr

            obj_attr_list[obj_attr_list["staging"] + "_complete"] = int(time())
                        
        except self.osci.ObjectStoreMgdConnException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #34
0
    def take_action_if_requested(self, obj_type, obj_attr_list, current_step):
        '''
        TBD
        '''

        if "staging" not in obj_attr_list:
            return

        if not obj_attr_list["staging"].count(current_step):
            return

        if obj_attr_list["staging"] + "_complete" in obj_attr_list:
            return

        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            if obj_attr_list["staging"] == "pause_" + current_step:

                _max_tries = int(obj_attr_list["update_attempts"])
                _wait = int(obj_attr_list["update_frequency"])

                # Always subscribe for the VM channel, no matter the object
                _sub_channel = self.osci.subscribe(obj_attr_list["cloud_name"],
                                                   "VM", "staging",
                                                   _max_tries * _wait)

                if obj_type == "VM" and obj_attr_list[
                        "ai"] != "none" and current_step.count("all_vms"):
                    _target_uuid = obj_attr_list["ai"]
                    _target_name = obj_attr_list["ai_name"]
                    _cloud_vm_uuid = obj_attr_list["cloud_vm_uuid"]
                else:
                    _target_uuid = obj_attr_list["uuid"]
                    _target_name = obj_attr_list["name"]
                    _cloud_vm_uuid = _target_uuid

                self.osci.publish_message(obj_attr_list["cloud_name"], \
                                          obj_type, \
                                          "staging", \
                                          _target_uuid + ";vmready;" + dic2str(obj_attr_list),\
                                           1, \
                                           3600)

                _msg = obj_type + ' ' + _cloud_vm_uuid + " ("
                _msg += _target_name + ") pausing on attach for continue signal ...."
                cbdebug(_msg, True)

                for _message in _sub_channel.listen():
                    _args = str(_message["data"]).split(";")

                    if len(_args) != 3:
                        #                        cbdebug("Message is not for me: " + str(_args))
                        continue

                    _id, _status, _info = _args

                    if (_id == _target_uuid
                            or _id == _target_name) and _status == "continue":
                        obj_attr_list[obj_attr_list["staging"] +
                                      "_complete"] = int(time())

                        if _info.count(":"):

                            _add_obj_attr_list = str2dic(_info)
                            obj_attr_list.update(_add_obj_attr_list)

                        _status = 0
                        break

                _sub_channel.unsubscribe()

                _status = 0

            elif obj_attr_list["staging"] == "execute_" + current_step:

                _proc_man = ProcessManagement(username = obj_attr_list["username"], \
                                              cloud_name = obj_attr_list["cloud_name"])

                _json_contents = copy.deepcopy(obj_attr_list)

                if obj_type == "AI":
                    _json_contents["vms"] = {}

                    _vm_id_list = obj_attr_list["vms"].split(',')
                    for _vm_id in _vm_id_list:
                        _vm_uuid = _vm_id.split('|')[0]
                        _vm_attr_list = self.osci.get_object(
                            obj_attr_list["cloud_name"], "VM", False, _vm_uuid,
                            False)
                        _json_contents["vms"][
                            _vm_attr_list["uuid"]] = _vm_attr_list

                obj_attr_list["execute_json_filename"] = "/tmp/"
                obj_attr_list["execute_json_filename"] += obj_attr_list[
                    "execute_json_filename_prefix"]
                obj_attr_list[
                    "execute_json_filename"] += "_vapp_" + obj_attr_list[
                        "cloud_name"]
                obj_attr_list["execute_json_filename"] += "_" + obj_attr_list[
                    "name"] + "_"
                obj_attr_list[
                    "execute_json_filename"] += obj_attr_list["uuid"] + ".json"

                _json_fh = open(obj_attr_list["execute_json_filename"], 'w')
                _json_fh.write(
                    json.dumps(_json_contents, sort_keys=True, indent=4))
                _json_fh.close()

                _msg = "JSON contents written to "
                _msg += obj_attr_list["execute_json_filename"] + '.'
                cbdebug(_msg, True)

                _cmd = obj_attr_list["execute_script_name"] + ' '
                _cmd += obj_attr_list["execute_json_filename"]

                _status, _result_stdout, _result_stderr = _proc_man.run_os_command(
                    _cmd)

                _msg = "Command \"" + _cmd + "\" executed, with return code " + str(
                    _status)
                cbdebug(_msg, True)

            obj_attr_list[obj_attr_list["staging"] + "_complete"] = int(time())

        except self.osci.ObjectStoreMgdConnException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #35
0
    def vmcreate(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            _fault = "No info"

            obj_attr_list["cloud_vm_uuid"] = "NA"
            _instance = False

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"]
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["cloud_name"]
            obj_attr_list["cloud_vm_name"] += '-' + "vm"
            obj_attr_list["cloud_vm_name"] += obj_attr_list["name"].split(
                "_")[1]
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none":
                obj_attr_list[
                    "cloud_vm_name"] += '-' + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list[
                "cloud_vm_name"].replace("_", "-")
            obj_attr_list[
                "last_known_state"] = "about to connect to SoftLayer manager"

            if not self.nodeman or not self.sshman or not self.imageman:
                self.connect(obj_attr_list["access"], obj_attr_list["credentials"], \
                             obj_attr_list["vmc_name"])

            if self.is_vm_running(obj_attr_list):
                _msg = "An instance named \"" + obj_attr_list["cloud_vm_name"]
                _msg += "\" is already running. It needs to be destroyed first."
                _status = 187
                cberr(_msg)
                raise CldOpsException(_msg, _status)

            obj_attr_list[
                "last_known_state"] = "about to get flavor and image list"

            if obj_attr_list["key_name"].lower() == "false":
                _key_name = None
            else:
                _key_name = obj_attr_list["key_name"]

            obj_attr_list["last_known_state"] = "about to send create request"

            _imageid = self.get_images(obj_attr_list)

            _vcpus, _vmemory = obj_attr_list["size"].split('-')

            obj_attr_list["vcpus"] = _vcpus
            obj_attr_list["vmemory"] = _vmemory

            _meta = {}
            if "meta_tags" in obj_attr_list:
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    _meta = str2dic(obj_attr_list["meta_tags"])

            _meta["experiment_id"] = obj_attr_list["experiment_id"]

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = \
            _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            _msg = "Starting an instance on SoftLayer, using the imageid \""
            _msg += obj_attr_list["imageid1"] + "\" (" + str(
                _imageid) + ") and "
            _msg += "size \"" + obj_attr_list["size"] + "\", "
            _msg += " on VMC \"" + obj_attr_list["vmc_name"] + "\""
            cbdebug(_msg, True)

            _key_id = self.sshman.list_keys(
                label=obj_attr_list["key_name"])[0]["id"]

            _kwargs = { "cpus": int(obj_attr_list["vcpus"]), \
                       "memory": int(obj_attr_list["vmemory"]), \
                       "hourly": True, \
                       "domain": "softlayer.com", \
                       "hostname": obj_attr_list["cloud_vm_name"], \
                       "datacenter": obj_attr_list["vmc_name"], \
                       "image_id" : _imageid, \
                       "ssh_keys" : [ int(_key_id) ], \
                       "nic_speed" : int(obj_attr_list["nic_speed"])}

            if len(obj_attr_list["private_vlan"]) > 2:
                _kwargs["private_vlan"] = int(obj_attr_list["private_vlan"])

            if obj_attr_list["private_network_only"].lower() == "true":
                _kwargs["private"] = True

            _instance = self.nodeman.create_instance(**_kwargs)

            if _instance:

                sleep(int(obj_attr_list["update_frequency"]))

                obj_attr_list["cloud_vm_uuid"] = _instance["globalIdentifier"]

                self.take_action_if_requested("VM", obj_attr_list,
                                              "provision_started")

                _time_mark_prc = self.wait_for_instance_ready(
                    obj_attr_list, _time_mark_prs)

                self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

                _status = 0

                if obj_attr_list["force_failure"].lower() == "true":
                    _fmsg = "Forced failure (option FORCE_FAILURE set \"true\")"
                    _status = 916

            else:
                _fmsg = "Failed to obtain instance's (cloud assigned) uuid. The "
                _fmsg += "instance creation failed for some unknown reason."
                cberr(_fmsg)
                _status = 100

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #36
0
    def check_images(self, vmc_name, vm_templates) :
        '''
        TBD
        '''
        _msg = "Checking if the imageids associated to each \"VM role\" are"
        _msg += " registered on VMC " + vmc_name + "...."
        cbdebug(_msg, True)

        _wanted_images = []
        for _vm_role in vm_templates.keys() :
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid.count("ami-") and _imageid not in _wanted_images :
                _wanted_images.append(_imageid)

        _registered_image_list = self.ec2conn.get_all_images(image_ids=_wanted_images)
        _registered_imageid_list = []

        for _registered_image in _registered_image_list :
            _registered_imageid_list.append(_registered_image.id)

        _required_imageid_list = {}

        for _vm_role in vm_templates.keys() :
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
            if _imageid.count("ami-") :
                if _imageid not in _required_imageid_list :
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

        _msg = 'y'

        _detected_imageids = {}
        _undetected_imageids = {}

        for _imageid in _required_imageid_list.keys() :
            
            # Unfortunately we have to check image names one by one,
            # because they might be appended by a generic suffix for
            # image randomization (i.e., deploying the same image multiple
            # times as if it were different images.
            _image_detected = False
            for _registered_imageid in _registered_imageid_list :
                if str(_registered_imageid).count(_imageid) :
                    _image_detected = True
                    _detected_imageids[_imageid] = "detected"
                else :
                    _undetected_imageids[_imageid] = "undetected"

            if _image_detected :
                True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
            else :
                _msg += "x WARNING Image id for VM roles \""
                _msg += ','.join(_required_imageid_list[_imageid]) + "\": \""
                _msg += _imageid + "\" is NOT registered "
                _msg += "(attaching VMs with any of these roles will result in error).\n"
        
        if not len(_detected_imageids) :
            _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
            _msg += " in this EC2 cloud. Please register at least one "
            _msg += "of the following images: " + ','.join(_undetected_imageids.keys())
            _fmsg = _msg 
            cberr(_msg, True)
        else :
            _msg = _msg.replace("yx",'')
            _msg = _msg.replace("x ","          ")
            _msg = _msg[:-2]
            if len(_msg) :
                cbdebug(_msg, True)    

        return _detected_imageids
예제 #37
0
    def test_vmc_connection(
        self, vmc_name, access, credentials, key_name, security_group_name, vm_templates, vm_defaults
    ):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.connect(access, credentials, vmc_name)

            if not key_name:
                _key_pair_found = True
            else:
                _msg = 'Checking if the ssh key pair "' + key_name + '" is created'
                _msg += " on VMC " + vmc_name + "...."
                cbdebug(_msg, True)

                _key_pair_found = False
                for _key_pair in self.sshman.list_keys():
                    if _key_pair["label"] == key_name:
                        _key_pair_found = True

                if not _key_pair_found:
                    _pub_key_fn = vm_defaults["credentials_dir"] + "/"
                    _pub_key_fn += vm_defaults["ssh_key_name"] + ".pub"

                    _msg = 'Creating the ssh key pair "' + key_name + '"'
                    _msg += " on VMC " + vmc_name + ', using the public key "'
                    _msg += _pub_key_fn + '"...'
                    cbdebug(_msg, True)

                    _fh = open(_pub_key_fn, "r")
                    _pub_key = _fh.read()
                    _fh.close()

                    self.sshman.add_key(_pub_key, key_name)
                    _key_pair_found = True

            if security_group_name:
                _security_group_found = True

                """
                At the moment, there isn't a "security group" object/abstraction
                (i.e., fine-grained network access control for CCIs/VSs) in 
                SoftLayer.
                """

            #                _msg = "Checking if the security group \"" + security_group_name
            #                _msg += "\" is created on VMC " + vmc_name + "...."
            #                cbdebug(_msg, True)

            #                _security_group_found = False
            #                for security_group in self.oskconncompute.security_groups.list() :
            #                    if security_group.name == security_group_name :
            #                        _security_group_found = True

            #                if not _security_group_found :
            #                    _msg = "ERROR! Please create the security group \""
            #                    _msg += security_group_name + "\" in "
            #                    _msg += "SoftLayer before proceeding."
            #                    _fmsg = _msg
            #                    cberr(_msg, True)
            #            else :
            #                _security_group_found = True

            _msg = 'Checking if the imageids associated to each "VM role" are'
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            if vm_defaults["images_access"] == "private":
                _registered_image_list = self.imageman.list_private_images()
            else:
                _registered_image_list = self.imageman.list_public_images()

            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image["name"])

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid not in _required_imageid_list:
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = "y"

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys():

                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list:
                    if str(_registered_imageid).count(_imageid):
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else:
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected:
                    True
                #                       _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
                #                       _msg += _imageid + "\" and it is already registered.\n"
                else:
                    _msg += 'xWARNING Image id for VM roles "'
                    _msg += ",".join(_required_imageid_list[_imageid]) + '": "'
                    _msg += _imageid + '" is NOT registered '
                    _msg += "(attaching VMs with any of these roles will result in error).\n"

            if not len(_detected_imageids):
                _msg = 'ERROR! None of the image ids used by any VM "role" were detected'
                _msg += " in this SoftLayer cloud. Please register at least one "
                _msg += "of the following images: " + ",".join(_undetected_imageids.keys())
                cberr(_msg, True)
            else:
                _msg = _msg.replace("yx", "")
                _msg = _msg.replace("x", "         ")
                _msg = _msg[:-2]
                if len(_msg):
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found and len(_detected_imageids)):
                _msg = "Check the previous errors, fix it (using SoftLayer's Portal"
                _msg += "or sl CLI"
                _status = 1178
                raise CldOpsException(_msg, _status)

            _status = 0

        except CldOpsException, obj:
            _fmsg = str(obj.msg)
            _status = 2
예제 #38
0
    def vmcreate(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"] 
            obj_attr_list["cloud_vm_name"] += '-' + "vm_" 
            obj_attr_list["cloud_vm_name"] += obj_attr_list["name"].split("_")[1] 
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["role"]
            
            obj_attr_list["cloud_mac"] = "NA"
            obj_attr_list["vcpus"] = "NA"
            obj_attr_list["vmemory"] = "NA" 
            obj_attr_list["vstorage"] = "NA"
            obj_attr_list["vnics"] = "NA"
            obj_attr_list["size"] = "NA"
            obj_attr_list["class"] = "NA"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            obj_attr_list["host_name"] = "NA"

            if "cloud_ip" in obj_attr_list and obj_attr_list["cloud_ip"] != "undefined" :
                obj_attr_list["prov_cloud_ip"] = obj_attr_list["cloud_ip"]
            else :
                _status = 1181
                _msg = "For NullOp Clouds, the IP address of each VM has to be" 
                _msg += " supplied on the \"vmattach\" (e.g., \"vmattach <role>"
                _msg += " [optional parametes] cloud_ip=X.Y.Z.W)."
                cberr(_msg)
                raise CldOpsException(_msg, _status)

            obj_attr_list["cloud_hostname"] = "vm_" + obj_attr_list["cloud_ip"].replace('.','_')

            if "meta_tags" in obj_attr_list :
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else :
                    obj_attr_list["meta_tags"] = "empty"
            else :
                obj_attr_list["meta_tags"] = "empty"
 
            self.take_action_if_requested("VM", obj_attr_list, "provision_started")
 
            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            obj_attr_list["arrival"] = int(time())

            _status = 0

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #39
0
    def test_vmc_connection(
        self, vmc_name, access, credentials, key_name, security_group_name, vm_templates, vm_defaults
    ):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _apikey, _secretkey = credentials.split("|")

            self.connect(access, _apikey, _secretkey)

            _zoneid = self.get_zone(vmc_name)

            _msg = 'Checking if the ssh key pair "' + key_name + '" is created'
            _msg += " on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _key_pair_found = False
            for _key_pair in self.cskconn.listSSHKeyPairs():
                if _key_pair[u"name"] == key_name:
                    _key_pair_found = True

            if not _key_pair_found:
                _msg = 'ERROR! Please create the ssh key pair "' + key_name + '" in '
                _msg += "CloudPlatform before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = 'Checking if the security group "' + security_group_name
            _msg += '" is created on VMC ' + vmc_name + "...."
            cbdebug(_msg, True)

            _security_group_found = False
            for security_group in self.cskconn.listSecurityGroups():
                if security_group[u"name"] == security_group_name:
                    _security_group_found = True

            if not _security_group_found:
                _msg = 'ERROR! Please create the security group "' + security_group_name + '" in '
                _msg += "CloudPlatform before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = 'Checking if the imageids associated to each "VM role" are'
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _registered_image_list = self.cskconn.listTemplates({u"zoneid": _zoneid, u"templatefilter": u"executable"})
            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image[u"name"].replace(" ", ""))

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid not in _required_imageid_list:
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = "y"

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys():

                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list:
                    if str(_registered_imageid).count(_imageid):
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else:
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected:
                    True
                else:
                    _msg = 'xWARNING Image id for VM roles "'
                    _msg += ",".join(_required_imageid_list[_imageid]) + '": "'
                    _msg += _imageid + '" is NOT registered '
                    _msg += "(attaching VMs with any of these roles will result in error).\n"

            if not len(_detected_imageids):
                _msg = 'ERROR! None of the image ids used by any VM "role" were detected'
                _msg += " in this cloudPlatform. Please register at least one "
                _msg += "of the following images: " + ",".join(_undetected_imageids.keys())
                _fmsg = _msg
                cberr(_msg, True)
            else:
                _msg = _msg.replace("yx", "")
                _msg = _msg.replace("x", "         ")
                _msg = _msg[:-2]
                if len(_msg):
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found and len(_detected_imageids)):
                _msg = "Check the previous errors, fix it (using CloudStack's web"
                _msg += " GUI (horizon) or nova CLI"
                _status = 1178
                raise CldOpsException(_msg, _status)

            _status = 0

        except CldOpsException, obj:
            _fmsg = str(obj.msg)
            _status = 2
예제 #40
0
    def vmcreate(self, obj_attr_list):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            _fault = "No info"

            obj_attr_list["cloud_vm_uuid"] = "NA"
            _instance = False

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"]
            obj_attr_list["cloud_vm_name"] += "-" + obj_attr_list["cloud_name"]
            obj_attr_list["cloud_vm_name"] += "-" + "vm"
            obj_attr_list["cloud_vm_name"] += obj_attr_list["name"].split("_")[1]
            obj_attr_list["cloud_vm_name"] += "-" + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none":
                obj_attr_list["cloud_vm_name"] += "-" + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list["cloud_vm_name"].replace("_", "-")
            obj_attr_list["last_known_state"] = "about to connect to SoftLayer manager"

            self.take_action_if_requested("VM", obj_attr_list, "provision_originated")

            if not self.nodeman or not self.sshman or not self.imageman:
                self.connect(obj_attr_list["access"], obj_attr_list["credentials"], obj_attr_list["vmc_name"])

            if self.is_vm_running(obj_attr_list):
                _msg = 'An instance named "' + obj_attr_list["cloud_vm_name"]
                _msg += '" is already running. It needs to be destroyed first.'
                _status = 187
                cberr(_msg)
                raise CldOpsException(_msg, _status)

            obj_attr_list["last_known_state"] = "about to get flavor and image list"

            if obj_attr_list["key_name"].lower() == "false":
                _key_name = None
            else:
                _key_name = obj_attr_list["key_name"]

            obj_attr_list["last_known_state"] = "about to send create request"

            _imageid = self.get_images(obj_attr_list)

            _vcpus, _vmemory = obj_attr_list["size"].split("-")

            obj_attr_list["vcpus"] = _vcpus
            obj_attr_list["vmemory"] = _vmemory

            _meta = {}
            if "meta_tags" in obj_attr_list:
                if (
                    obj_attr_list["meta_tags"] != "empty"
                    and obj_attr_list["meta_tags"].count(":")
                    and obj_attr_list["meta_tags"].count(",")
                ):
                    _meta = str2dic(obj_attr_list["meta_tags"])

            _meta["experiment_id"] = obj_attr_list["experiment_id"]

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                obj_attr_list["mgt_001_provisioning_request_originated"]
            )

            _msg = 'Starting an instance on SoftLayer, using the imageid "'
            _msg += obj_attr_list["imageid1"] + '" (' + str(_imageid) + ") and "
            _msg += 'size "' + obj_attr_list["size"] + '", '
            _msg += ' on VMC "' + obj_attr_list["vmc_name"] + '"'
            cbdebug(_msg, True)

            _key_id = self.sshman.list_keys(label=obj_attr_list["key_name"])[0]["id"]

            _kwargs = {
                "cpus": int(obj_attr_list["vcpus"]),
                "memory": int(obj_attr_list["vmemory"]),
                "hourly": True,
                "domain": "softlayer.com",
                "hostname": obj_attr_list["cloud_vm_name"],
                "datacenter": obj_attr_list["vmc_name"],
                "image_id": _imageid,
                "ssh_keys": [int(_key_id)],
                "nic_speed": int(obj_attr_list["nic_speed"]),
            }

            if len(obj_attr_list["private_vlan"]) > 2:
                _kwargs["private_vlan"] = int(obj_attr_list["private_vlan"])

            if obj_attr_list["private_network_only"].lower() == "true":
                _kwargs["private"] = True

            _instance = self.nodeman.create_instance(**_kwargs)

            if _instance:

                sleep(int(obj_attr_list["update_frequency"]))

                obj_attr_list["cloud_vm_uuid"] = _instance["globalIdentifier"]

                self.take_action_if_requested("VM", obj_attr_list, "provision_started")

                _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

                self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

                _status = 0

                if obj_attr_list["force_failure"].lower() == "true":
                    _fmsg = 'Forced failure (option FORCE_FAILURE set "true")'
                    _status = 916

            else:
                _fmsg = "Failed to obtain instance's (cloud assigned) uuid. The "
                _fmsg += "instance creation failed for some unknown reason."
                cberr(_fmsg)
                _status = 100

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #41
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates) :
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.test_vmc_common(vmc_name, access, credentials, 2)
            self.connect(access, credentials, vmc_name)
            self.query("describe_service_region", None, False)

            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _registered_image_list = self.query("describe_images", None, True)
            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image["image_id"])

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid not in _required_imageid_list:
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys():

                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list:
                    if str(_registered_imageid).count(_imageid):
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else:
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected:
                    True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
                else:
                    _msg = "xWARNING Image id for VM roles \""
                    _msg += ','.join(
                        _required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"

            if not len(_detected_imageids):
                _msg = "None of the image ids used by any VM \"role\" were detected"
                _msg += " in this SCP cloud. Please register at least one "
                _msg += "of the following images: " + ','.join(
                    _undetected_imageids.keys())
                cberr(_msg, True)
            else:
                _msg = _msg.replace("yx", '')
                _msg = _msg.replace('x', "         ")
                _msg = _msg[:-2]
                if len(_msg):
                    cbdebug(_msg, True)

            _status = 0

        except CldOpsException, obj:
            _status = int(obj.error_code)
            _fmsg = str(obj.error_message)
예제 #42
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates, vm_defaults) :
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.connect(access, credentials, vmc_name)

            if not key_name:
                _key_pair_found = True
            else:
                _msg = "Checking if the ssh key pair \"" + key_name + "\" is created"
                _msg += " on VMC " + vmc_name + "...."
                cbdebug(_msg, True)

                _key_pair_found = False
                for _key_pair in self.sshman.list_keys():
                    if _key_pair["label"] == key_name:
                        _key_pair_found = True

                if not _key_pair_found:
                    _pub_key_fn = vm_defaults["credentials_dir"] + '/'
                    _pub_key_fn += vm_defaults["ssh_key_name"] + ".pub"

                    _msg = "Creating the ssh key pair \"" + key_name + "\""
                    _msg += " on VMC " + vmc_name + ", using the public key \""
                    _msg += _pub_key_fn + "\"..."
                    cbdebug(_msg, True)

                    _fh = open(_pub_key_fn, 'r')
                    _pub_key = _fh.read()
                    _fh.close()

                    self.sshman.add_key(_pub_key, key_name)
                    _key_pair_found = True

            if security_group_name:
                _security_group_found = True
                '''
                At the moment, there isn't a "security group" object/abstraction
                (i.e., fine-grained network access control for CCIs/VSs) in 
                SoftLayer.
                '''

#                _msg = "Checking if the security group \"" + security_group_name
#                _msg += "\" is created on VMC " + vmc_name + "...."
#                cbdebug(_msg, True)

#                _security_group_found = False
#                for security_group in self.oskconncompute.security_groups.list() :
#                    if security_group.name == security_group_name :
#                        _security_group_found = True

#                if not _security_group_found :
#                    _msg = "ERROR! Please create the security group \""
#                    _msg += security_group_name + "\" in "
#                    _msg += "SoftLayer before proceeding."
#                    _fmsg = _msg
#                    cberr(_msg, True)
#            else :
#                _security_group_found = True

            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            if vm_defaults["images_access"] == "private":
                _registered_image_list = self.imageman.list_private_images()
            else:
                _registered_image_list = self.imageman.list_public_images()

            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image["name"])

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid not in _required_imageid_list:
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys():

                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list:
                    if str(_registered_imageid).count(_imageid):
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else:
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected:
                    True
#                       _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                       _msg += _imageid + "\" and it is already registered.\n"
                else:
                    _msg += "xWARNING Image id for VM roles \""
                    _msg += ','.join(
                        _required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"

            if not len(_detected_imageids):
                _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
                _msg += " in this SoftLayer cloud. Please register at least one "
                _msg += "of the following images: " + ','.join(
                    _undetected_imageids.keys())
                cberr(_msg, True)
            else:
                _msg = _msg.replace("yx", '')
                _msg = _msg.replace('x', "         ")
                _msg = _msg[:-2]
                if len(_msg):
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found
                    and len(_detected_imageids)):
                _msg = "Check the previous errors, fix it (using SoftLayer's Portal"
                _msg += "or sl CLI"
                _status = 1178
                raise CldOpsException(_msg, _status)

            _status = 0

        except CldOpsException, obj:
            _fmsg = str(obj.msg)
            _status = 2
예제 #43
0
    def vmcreate(self, obj_attr_list):
        """
        TBD
        """
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"]
            obj_attr_list["cloud_vm_name"] += "-" + "vm_"
            obj_attr_list["cloud_vm_name"] += obj_attr_list["name"].split("_")[1]
            obj_attr_list["cloud_vm_name"] += "-" + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none":
                obj_attr_list["cloud_vm_name"] += "-" + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list["cloud_vm_name"].replace("_", "-")

            obj_attr_list["cloud_mac"] = "NA"
            obj_attr_list["vcpus"] = "NA"
            obj_attr_list["vmemory"] = "NA"
            obj_attr_list["vstorage"] = "NA"
            obj_attr_list["vnics"] = "NA"
            obj_attr_list["size"] = "NA"
            obj_attr_list["class"] = "NA"

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                obj_attr_list["mgt_001_provisioning_request_originated"]
            )

            obj_attr_list["host_name"] = "NA"

            if "cloud_ip" in obj_attr_list and obj_attr_list["cloud_ip"] != "undefined":
                obj_attr_list["prov_cloud_ip"] = obj_attr_list["cloud_ip"]
                obj_attr_list["run_cloud_ip"] = obj_attr_list["cloud_ip"]
            else:
                _status = 1181
                _msg = "For NullOp Clouds, the IP address of each VM has to be"
                _msg += ' supplied on the "vmattach" (e.g., "vmattach <role>'
                _msg += " [optional parametes] cloud_ip=X.Y.Z.W)."
                cberr(_msg)
                raise CldOpsException(_msg, _status)

            obj_attr_list["cloud_hostname"] = "vm_" + obj_attr_list["cloud_ip"].replace(".", "_")

            if "meta_tags" in obj_attr_list:
                if (
                    obj_attr_list["meta_tags"] != "empty"
                    and obj_attr_list["meta_tags"].count(":")
                    and obj_attr_list["meta_tags"].count(",")
                ):
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else:
                    obj_attr_list["meta_tags"] = "empty"
            else:
                obj_attr_list["meta_tags"] = "empty"

            self.take_action_if_requested("VM", obj_attr_list, "provision_started")

            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            obj_attr_list["arrival"] = int(time())

            _status = 0

            if obj_attr_list["force_failure"].lower() == "true":
                _fmsg = 'Forced failure (option FORCE_FAILURE set "true")'
                _status = 916

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #44
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates) :
        '''
        TBD
        '''
        try :
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.test_vmc_common(vmc_name, access, credentials, 2)
            self.connect(access, credentials, vmc_name)
            self.query("describe_service_region", None, False)

            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _registered_image_list = self.query("describe_images", None, True)
            _registered_imageid_list = []

            for _registered_image in _registered_image_list :
                _registered_imageid_list.append(_registered_image["image_id"])

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys() :
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
                if _imageid not in _required_imageid_list :
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys() :
                
                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list :
                    if str(_registered_imageid).count(_imageid) :
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else :
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected :
                    True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
                else :
                    _msg = "xWARNING Image id for VM roles \""
                    _msg += ','.join(_required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"
            
            if not len(_detected_imageids) :
                _msg = "None of the image ids used by any VM \"role\" were detected"
                _msg += " in this SCP cloud. Please register at least one "
                _msg += "of the following images: " + ','.join(_undetected_imageids.keys())
                cberr(_msg, True)
            else :
                _msg = _msg.replace("yx",'')
                _msg = _msg.replace('x',"         ")
                _msg = _msg[:-2]
                if len(_msg) :
                    cbdebug(_msg, True)

            _status = 0

        except CldOpsException, obj :
            _status = int(obj.error_code)
            _fmsg = str(obj.error_message)
예제 #45
0
    def vmcreate(self, obj_attr_list):
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"]
            obj_attr_list["cloud_vm_name"] += '-' + "vm_"
            obj_attr_list["cloud_vm_name"] += obj_attr_list["name"].split(
                "_")[1]
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none":
                obj_attr_list[
                    "cloud_vm_name"] += '-' + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list[
                "cloud_vm_name"].replace("_", "-")

            obj_attr_list["cloud_mac"] = "NA"
            obj_attr_list["vcpus"] = "NA"
            obj_attr_list["vmemory"] = "NA"
            obj_attr_list["vstorage"] = "NA"
            obj_attr_list["vnics"] = "NA"
            obj_attr_list["size"] = "NA"
            obj_attr_list["class"] = "NA"

            _time_mark_prs = int(time())
            obj_attr_list[
                "mgt_002_provisioning_request_sent"] = _time_mark_prs - int(
                    obj_attr_list["mgt_001_provisioning_request_originated"])

            obj_attr_list["host_name"] = "NA"

            if "cloud_ip" in obj_attr_list and obj_attr_list[
                    "cloud_ip"] != "undefined":
                obj_attr_list["prov_cloud_ip"] = obj_attr_list["cloud_ip"]
                obj_attr_list["run_cloud_ip"] = obj_attr_list["cloud_ip"]
            else:
                _status = 1181
                _msg = "For NullOp Clouds, the IP address of each VM has to be"
                _msg += " supplied on the \"vmattach\" (e.g., \"vmattach <role>"
                _msg += " [optional parametes] cloud_ip=X.Y.Z.W)."
                cberr(_msg)
                raise CldOpsException(_msg, _status)

            obj_attr_list[
                "cloud_hostname"] = "vm_" + obj_attr_list["cloud_ip"].replace(
                    '.', '_')

            if "meta_tags" in obj_attr_list:
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(
                        obj_attr_list["meta_tags"])
                else:
                    obj_attr_list["meta_tags"] = "empty"
            else:
                obj_attr_list["meta_tags"] = "empty"

            self.take_action_if_requested("VM", obj_attr_list,
                                          "provision_started")

            _time_mark_prc = self.wait_for_instance_ready(
                obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            obj_attr_list["arrival"] = int(time())

            _status = 0

            if obj_attr_list["force_failure"].lower() == "true":
                _fmsg = "Forced failure (option FORCE_FAILURE set \"true\")"
                _status = 916

        except CldOpsException, obj:
            _status = obj.status
            _fmsg = str(obj.msg)
예제 #46
0
    def check_images(self, vmc_name, vm_templates):
        """
        TBD
        """
        _msg = 'Checking if the imageids associated to each "VM role" are'
        _msg += " registered on VMC " + vmc_name + "...."
        cbdebug(_msg, True)

        _wanted_images = []
        for _vm_role in vm_templates.keys():
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid not in _wanted_images:
                _wanted_images.append(_imageid)

        _registered_image_list = self.gceconn.images().list(project=self.project).execute()["items"]
        _registered_imageid_list = []

        for _registered_image in _registered_image_list:
            _registered_imageid_list.append(_registered_image["name"])

        _required_imageid_list = {}

        for _vm_role in vm_templates.keys():
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid not in _required_imageid_list:
                _required_imageid_list[_imageid] = []
            _required_imageid_list[_imageid].append(_vm_role)

        _msg = "y"

        _detected_imageids = {}
        _undetected_imageids = {}

        for _imageid in _required_imageid_list.keys():

            # Unfortunately we have to check image names one by one,
            # because they might be appended by a generic suffix for
            # image randomization (i.e., deploying the same image multiple
            # times as if it were different images.
            _image_detected = False
            for _registered_imageid in _registered_imageid_list:
                if str(_registered_imageid).count(_imageid):
                    _image_detected = True
                    _detected_imageids[_imageid] = "detected"
                else:
                    _undetected_imageids[_imageid] = "undetected"

            if _image_detected:
                True
            #                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
            #                    _msg += _imageid + "\" and it is already registered.\n"
            else:
                _msg += 'x WARNING Image id for VM roles "'
                _msg += ",".join(_required_imageid_list[_imageid]) + '": "'
                _msg += _imageid + '" is NOT registered '
                _msg += "(attaching VMs with any of these roles will result in error).\n"

        if not len(_detected_imageids):
            _msg = 'ERROR! None of the image ids used by any VM "role" were detected'
            _msg += " in this GCE cloud. Please register at least one "
            _msg += "of the following images: " + ",".join(_undetected_imageids.keys())
            _fmsg = _msg
            cberr(_msg, True)
        else:
            _msg = _msg.replace("yx", "")
            _msg = _msg.replace("x ", "          ")
            _msg = _msg[:-2]
            if len(_msg):
                cbdebug(_msg, True)

        return _detected_imageids
예제 #47
0
    def check_images(self, vmc_name, vm_templates) :
        '''
        TBD
        '''
        _msg = "Checking if the imageids associated to each \"VM role\" are"
        _msg += " registered on VMC " + vmc_name + "...."
        cbdebug(_msg, True)

        _wanted_images = []
        for _vm_role in vm_templates.keys() :
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
            if _imageid.count("ami-") and _imageid not in _wanted_images :
                _wanted_images.append(_imageid)

        _registered_image_list = self.ec2conn.get_all_images(image_ids=_wanted_images)
        _registered_imageid_list = []

        for _registered_image in _registered_image_list :
            _registered_imageid_list.append(_registered_image.id)

        _required_imageid_list = {}

        for _vm_role in vm_templates.keys() :
            _imageid = str2dic(vm_templates[_vm_role])["imageid1"]                
            if _imageid.count("ami-") :
                if _imageid not in _required_imageid_list :
                    _required_imageid_list[_imageid] = []
                _required_imageid_list[_imageid].append(_vm_role)

        _msg = 'y'

        _detected_imageids = {}
        _undetected_imageids = {}

        for _imageid in _required_imageid_list.keys() :
            
            # Unfortunately we have to check image names one by one,
            # because they might be appended by a generic suffix for
            # image randomization (i.e., deploying the same image multiple
            # times as if it were different images.
            _image_detected = False
            for _registered_imageid in _registered_imageid_list :
                if str(_registered_imageid).count(_imageid) :
                    _image_detected = True
                    _detected_imageids[_imageid] = "detected"
                else :
                    _undetected_imageids[_imageid] = "undetected"

            if _image_detected :
                True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
            else :
                _msg += "x WARNING Image id for VM roles \""
                _msg += ','.join(_required_imageid_list[_imageid]) + "\": \""
                _msg += _imageid + "\" is NOT registered "
                _msg += "(attaching VMs with any of these roles will result in error).\n"
        
        if not len(_detected_imageids) :
            _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
            _msg += " in this EC2 cloud. Please register at least one "
            _msg += "of the following images: " + ','.join(_undetected_imageids.keys())
            _fmsg = _msg 
            cberr(_msg, True)
        else :
            _msg = _msg.replace("yx",'')
            _msg = _msg.replace("x ","          ")
            _msg = _msg[:-2]
            if len(_msg) :
                cbdebug(_msg, True)    

        return _detected_imageids
예제 #48
0
    def test_vmc_connection(self, vmc_name, access, credentials, key_name, \
                            security_group_name, vm_templates, vm_defaults) :
        '''
        TBD
        '''
        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"
            self.connect(access, credentials, vmc_name)

            _msg = "Checking if the ssh key pair \"" + key_name + "\" is created"
            _msg += " on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _key_pair_found = False
            for _key_pair in self.ec2conn.get_all_key_pairs():
                if _key_pair.name == key_name:
                    _key_pair_found = True

            if not _key_pair_found:
                _msg = "ERROR! Please create the ssh key pair \"" + key_name + "\" in "
                _msg += "Amazon EC2 before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = "Checking if the security group \"" + security_group_name
            _msg += "\" is created on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _security_group_found = False
            for security_group in self.ec2conn.get_all_security_groups():
                if security_group.name == security_group_name:
                    _security_group_found = True

            if not _security_group_found:
                _msg = "ERROR! Please create the security group \"" + security_group_name + "\" in "
                _msg += "Amazon EC2 before proceeding."
                _fmsg = _msg
                cberr(_msg, True)

            _msg = "Checking if the imageids associated to each \"VM role\" are"
            _msg += " registered on VMC " + vmc_name + "...."
            cbdebug(_msg, True)

            _wanted_images = []
            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid.count("ami-") and _imageid not in _wanted_images:
                    _wanted_images.append(_imageid)

            _registered_image_list = self.ec2conn.get_all_images(
                image_ids=_wanted_images)
            _registered_imageid_list = []

            for _registered_image in _registered_image_list:
                _registered_imageid_list.append(_registered_image.id)

            _required_imageid_list = {}

            for _vm_role in vm_templates.keys():
                _imageid = str2dic(vm_templates[_vm_role])["imageid1"]
                if _imageid.count("ami-"):
                    if _imageid not in _required_imageid_list:
                        _required_imageid_list[_imageid] = []
                    _required_imageid_list[_imageid].append(_vm_role)

            _msg = 'y'

            _detected_imageids = {}
            _undetected_imageids = {}

            for _imageid in _required_imageid_list.keys():

                # Unfortunately we have to check image names one by one,
                # because they might be appended by a generic suffix for
                # image randomization (i.e., deploying the same image multiple
                # times as if it were different images.
                _image_detected = False
                for _registered_imageid in _registered_imageid_list:
                    if str(_registered_imageid).count(_imageid):
                        _image_detected = True
                        _detected_imageids[_imageid] = "detected"
                    else:
                        _undetected_imageids[_imageid] = "undetected"

                if _image_detected:
                    True
#                    _msg += "xImage id for VM roles \"" + ','.join(_required_imageid_list[_imageid]) + "\" is \""
#                    _msg += _imageid + "\" and it is already registered.\n"
                else:
                    _msg = "xWARNING Image id for VM roles \""
                    _msg += ','.join(
                        _required_imageid_list[_imageid]) + "\": \""
                    _msg += _imageid + "\" is NOT registered "
                    _msg += "(attaching VMs with any of these roles will result in error).\n"

            if not len(_detected_imageids):
                _msg = "ERROR! None of the image ids used by any VM \"role\" were detected"
                _msg += " in this EC2 cloud. Please register at least one "
                _msg += "of the following images: " + ','.join(
                    _undetected_imageids.keys())
                _fmsg = _msg
                cberr(_msg, True)
            else:
                _msg = _msg.replace("yx", '')
                _msg = _msg.replace('x', "         ")
                _msg = _msg[:-2]
                if len(_msg):
                    cbdebug(_msg, True)

            if not (_key_pair_found and _security_group_found
                    and len(_detected_imageids)):
                _fmsg += ": Check the previous errors, fix it (using EC2's web"
                _fmsg += " GUI (AWS Console) or ec2-* CLI utilities"
                _status = 1178
                raise CldOpsException(_fmsg, _status)

            _status = 0

        except CldOpsException, obj:
            _fmsg = str(obj.msg)
            _status = 2
예제 #49
0
    def vmcreate(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
                         
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            obj_attr_list["host"] = "NA"
                
            if obj_attr_list["role"] != "predictablevm" :
                obj_attr_list["cloud_vm_uuid"] = self.generate_random_uuid()
            else :
                obj_attr_list["cloud_vm_uuid"] = "11111111-1111-1111-1111-111111111111"

            obj_attr_list["cloud_vm_name"] = "cb-" + obj_attr_list["username"] 
            obj_attr_list["cloud_vm_name"] += '-' + "vm_" + obj_attr_list["name"].split("_")[1] 
            obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["role"]

            if obj_attr_list["ai"] != "none" :            
                obj_attr_list["cloud_vm_name"] += '-' + obj_attr_list["ai_name"]

            obj_attr_list["cloud_vm_name"] = obj_attr_list["cloud_vm_name"].replace("_", "-")            

            obj_attr_list["cloud_mac"] = self.generate_random_mac_address()
            self.get_virtual_hardware_config(obj_attr_list)

            self.take_action_if_requested("VM", obj_attr_list, "provision_originated")

            if "execute_provision_originated_stdout" in obj_attr_list :
                if obj_attr_list["execute_provision_originated_stdout"].count("tenant") :
                    _temp_dict = str2dic(obj_attr_list["execute_provision_originated_stdout"].replace('\n',''))
                    obj_attr_list.update(_temp_dict)

            _time_mark_prs = int(time())
            obj_attr_list["mgt_002_provisioning_request_sent"] = _time_mark_prs - int(obj_attr_list["mgt_001_provisioning_request_originated"])

            if obj_attr_list["role"] != "willfail" :
                True
            else :
                _status = 7778
                _msg = "Deterministic VM failure (\"willfail\")"
                raise CldOpsException(_msg, _status)

            if obj_attr_list["pct_failure"] != " " :
                _pct_failure = int(obj_attr_list["pct_failure"])
                if not weighted_choice([_pct_failure, (100 - _pct_failure)]) :
                    _status = 7779
                    _msg = "Probabilistic VM failure (" + obj_attr_list["pct_failure"] + "%)"
                    raise CldOpsException(_msg, _status)
                else :
                    True
                
            self.take_action_if_requested("VM", obj_attr_list, "provision_started")

            _time_mark_vmp = int(time())
            self.vm_placement(obj_attr_list)
            obj_attr_list["sim_0021_vm_placement_time"] = _time_mark_vmp - int(time())
            
            if "meta_tags" in obj_attr_list :
                if obj_attr_list["meta_tags"] != "empty" and \
                obj_attr_list["meta_tags"].count(':') and \
                obj_attr_list["meta_tags"].count(',') :
                    obj_attr_list["meta_tags"] = str2dic(obj_attr_list["meta_tags"])
                else :
                    obj_attr_list["meta_tags"] = "empty"
            else :
                obj_attr_list["meta_tags"] = "empty"
  
            _time_mark_prc = self.wait_for_instance_ready(obj_attr_list, _time_mark_prs)

            self.wait_for_instance_boot(obj_attr_list, _time_mark_prc)

            self.take_action_if_requested("VM", obj_attr_list, "provision_finished")

            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "utc_offset_on_vm", "3600") 
            
            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "mgt_006_instance_preparation", "1")

            self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                         obj_attr_list["uuid"], "status", "Application starting up...") 

            obj_attr_list["arrival"] = int(time())

            _status = 0

            if obj_attr_list["force_failure"].lower() == "true" :
                _fmsg = "Forced failure (option FORCE_FAILURE set \"true\")"                
                _status = 916

        except CldOpsException, obj :
            _status = obj.status
            _fmsg = str(obj.msg)