Example #1
0
    def vmresize_actual(self, obj_attr_list) :
        '''
        TBD
        '''
        cbdebug("VM " + obj_attr_list["name"] + " resize request sent.", True)

        _vg = ValueGeneration(self.pid)
        tag = obj_attr_list["cloud_uuid"]
        desc = obj_attr_list["resource_description"]
        hypervisor_ip = obj_attr_list["vmc_cloud_ip"]

        if not self.is_vm_running(obj_attr_list) :
            return 0, "VM is not running"

        cbdebug("Getting resource state for Guest " + tag)
        _status, _fmsg, _guest_info = self.plmconn.get_domain_full_info(tag, hypervisor_ip)
        
        try :
            if "cpu_nr" in desc :
                _msg = "Set the number of CPUs for Guest " + tag
                _msg = "(" + obj_attr_list["cloud_ip"] + ")."
                cbdebug(_msg)
        
                _hpg_cnt = HotplugMgdConn(self.pid, obj_attr_list["cloud_ip"], "root", obj_attr_list["identity"])
                _active_cpus = 0
                _cpu_list = _hpg_cnt.get_cpus_state()
                for _cpu_number, _cpu_state in enumerate(_cpu_list) :
                    if _cpu_state == '1' :
                        _active_cpus += 1
                _hpg_cnt.set_active_cpus(desc["cpu_nr"])
                _msg = "CPU number for Guest " + tag
                _msg += " (" + obj_attr_list["cloud_ip"] + ") set to " + str(desc["cpu_nr"]) 
                _msg += " from " + str(_active_cpus) + '.'
                _xmsg = _msg
                cbdebug(_msg, True)
                
                del desc["cpu_nr"]

            if "cpu_sl" in desc :
                cbdebug("Setting CPU Soft Limit for Guest " + tag)
                
                _cpu_sl = _vg.value_suffix(desc["cpu_sl"], False)
                
                self.plmconn.set_domain_cpu(tag, "cpu_shares", str(_cpu_sl), hypervisor_ip)
                _msg = "CPU Soft Limit for Guest \"" + obj_attr_list["cloud_uuid"]
                _msg += "\" successfully set to " + str(_cpu_sl) + " from "
                _msg += str(_guest_info["vcpus_soft_limit"]) + '.'
                cbdebug(_msg, True)
                del desc["cpu_sl"]
                    

            if "cpu_hl" in desc :
                _msg = "Setting CPU Hard Limit for Guest \"" + obj_attr_list["cloud_uuid"]
                _msg += "\"."
                cbdebug(_msg)
                
                _cpu_hl = int(float(desc["cpu_hl"]) * \
                    float(_guest_info["vcpus_period"]))

                self.plmconn.set_domain_cpu(tag, "vcpu_quota", str(_cpu_hl), hypervisor_ip)
                _msg = "CPU Hard Limit for Guest " + tag 
                _msg += " successfully set to " + str(desc["cpu_hl"])
                _msg += " from " + str(_guest_info["vcpus_hard_limit"]) + '.'
                cbdebug(_msg, True)
                del desc["cpu_hl"]

            if "mem_sl" in desc :
                cbdebug("Setting MEMORY Soft Limit for Guest " + tag)

                _mem_sl = _vg.value_suffix(desc["mem_sl"], True)
                cbdebug("Resource Control Not implemented", True)
                del desc["mem_sl"]

            if "mem_hl" in desc :
                cbinfo("Setting MEMORY Hard Limit for Guest " + tag)
                _mem_hl = _vg.value_suffix(desc["mem_hl"], True)

                self.plmconn.set_domain_memory(tag, "current_memory", str(_mem_hl * 1024), hypervisor_ip)
                _msg = "MEMORY Hard Limit (virtio balloon) for Guest " + tag 
                _msg += " successfully set to " + str(_mem_hl)
                _msg += " KB from " + str(_guest_info["current_memory"]) + "KB ."
                cbdebug(_msg, True)
                del desc["mem_hl"]
        except ValueGeneration.ValueGenerationException, obj :
            raise CldOpsException("resize failure: " + obj.msg, obj.status)
Example #2
0
    def vmresize_actual(self, obj_attr_list):
        '''
        TBD
        '''
        cbdebug("VM " + obj_attr_list["name"] + " resize request sent.", True)

        _vg = ValueGeneration(self.pid)
        tag = obj_attr_list["cloud_vm_uuid"]
        desc = obj_attr_list["resource_description"]
        hypervisor_ip = obj_attr_list["host_cloud_ip"]

        if not self.is_vm_running(obj_attr_list):
            return 0, "VM is not running"

        cbdebug("Getting resource state for Guest " + tag)
        _status, _fmsg, _guest_info = self.ftcconn.get_domain_full_info(
            tag, hypervisor_ip)

        try:
            if "cpu_nr" in desc:
                _msg = "Set the number of CPUs for Guest " + tag
                _msg = "(" + obj_attr_list["cloud_ip"] + ")."
                cbdebug(_msg)

                _hpg_cnt = HotplugMgdConn(self.pid, obj_attr_list["cloud_ip"],
                                          "root", obj_attr_list["identity"])
                _active_cpus = 0
                _cpu_list = _hpg_cnt.get_cpus_state()
                for _cpu_number, _cpu_state in enumerate(_cpu_list):
                    if _cpu_state == '1':
                        _active_cpus += 1
                _hpg_cnt.set_active_cpus(desc["cpu_nr"])
                _msg = "CPU number for Guest " + tag
                _msg += " (" + obj_attr_list["cloud_ip"] + ") set to " + str(
                    desc["cpu_nr"])
                _msg += " from " + str(_active_cpus) + '.'
                _xmsg = _msg
                cbdebug(_msg, True)

                del desc["cpu_nr"]

            if "cpu_sl" in desc:
                cbdebug("Setting CPU Soft Limit for Guest " + tag)

                _cpu_sl = _vg.value_suffix(desc["cpu_sl"], False)

                self.ftcconn.set_domain_cpu(tag, "cpu_shares", str(_cpu_sl),
                                            hypervisor_ip)
                _msg = "CPU Soft Limit for Guest \"" + obj_attr_list[
                    "cloud_vm_uuid"]
                _msg += "\" successfully set to " + str(_cpu_sl) + " from "
                _msg += str(_guest_info["vcpus_soft_limit"]) + '.'
                cbdebug(_msg, True)
                del desc["cpu_sl"]

            if "cpu_hl" in desc:
                _msg = "Setting CPU Hard Limit for Guest \"" + obj_attr_list[
                    "cloud_vm_uuid"]
                _msg += "\"."
                cbdebug(_msg)

                _cpu_hl = int(float(desc["cpu_hl"]) * \
                    float(_guest_info["vcpus_period"]))

                self.ftcconn.set_domain_cpu(tag, "vcpu_quota", str(_cpu_hl),
                                            hypervisor_ip)
                _msg = "CPU Hard Limit for Guest " + tag
                _msg += " successfully set to " + str(desc["cpu_hl"])
                _msg += " from " + str(_guest_info["vcpus_hard_limit"]) + '.'
                cbdebug(_msg, True)
                del desc["cpu_hl"]

            if "mem_sl" in desc:
                cbdebug("Setting MEMORY Soft Limit for Guest " + tag)

                _mem_sl = _vg.value_suffix(desc["mem_sl"], True)
                cbdebug("Resource Control Not implemented", True)
                del desc["mem_sl"]

            if "mem_hl" in desc:
                cbinfo("Setting MEMORY Hard Limit for Guest " + tag)
                _mem_hl = _vg.value_suffix(desc["mem_hl"], True)

                self.ftcconn.set_domain_memory(tag, "current_memory",
                                               str(_mem_hl * 1024),
                                               hypervisor_ip)
                _msg = "MEMORY Hard Limit (virtio balloon) for Guest " + tag
                _msg += " successfully set to " + str(_mem_hl)
                _msg += " KB from " + str(
                    _guest_info["current_memory"]) + "KB ."
                cbdebug(_msg, True)
                del desc["mem_hl"]
        except ValueGeneration.ValueGenerationException, obj:
            raise CldOpsException("resize failure: " + obj.msg, obj.status)
Example #3
0
    def aidefine(self, obj_attr_list) :
        '''
        TBD
        '''
        try :
            _fmsg = "An error has occurred, but no error message was captured"

            _vg = ValueGeneration("NA")
            
            for _vm in obj_attr_list["vms"].split(',') :
                _vm_uuid, _vm_role, _vm_name = _vm.split('|')

                # default distribution is 10-500.  If the user set distribution, use it.
                _distribution = 'uniformIXIXI10I500'
                if 'deployment_time_value' in obj_attr_list:
                    _distribution = obj_attr_list['deployment_time_value']

                self.osci.pending_object_set(obj_attr_list["cloud_name"], "VM", \
                                             _vm_uuid, "mgt_007_application_start", \
                                             int(_vg.get_value(_distribution, 0)))

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

                if _vm.count("faildb2") :
                    _fmsg = "Forced failure during AI definition"

            self.take_action_if_requested("AI", obj_attr_list, "all_vms_booted")

            if obj_attr_list["create_performance_emitter"].lower() == "true" :
                
                _msg = "Starting a new \"performance emitter\" for " + obj_attr_list["name"]
                cbdebug(_msg, True)

                _cmd = obj_attr_list["base_dir"] + "/cbact"
                _cmd += " --procid=" + self.pid
                _cmd += " --osp=" + obj_attr_list["osp"]
                _cmd += " --msp=" + obj_attr_list["msp"]
                _cmd += " --operation=performance-emit"
                _cmd += " --cn=" + obj_attr_list["cloud_name"]
                _cmd += " --uuid=" + obj_attr_list["uuid"]
                _cmd += " --daemon"
                cbdebug(_cmd)

                _proc_h = Popen(_cmd, shell=True, stdout=PIPE, stderr=PIPE)

                if _proc_h.pid :
                    _msg = "Performance emitter command \"" + _cmd + "\" "
                    _msg += " successfully started a new daemon."
                    _msg += "The process id is " + str(_proc_h.pid) + "."
                    cbdebug(_msg)

                    _obj_id = obj_attr_list["uuid"] + '-' + "performance-emit"
                    
                    _process_identifier = "AI-" + _obj_id

                    self.osci.add_to_list(obj_attr_list["cloud_name"], \
                                          "GLOBAL", \
                                          "running_processes", \
                                          _process_identifier)

                    create_restart_script("restart_cb_perf-emitter", \
                                          _cmd, \
                                          obj_attr_list["username"], \
                                          "performance-emit", \
                                          obj_attr_list["name"], \
                                          obj_attr_list["uuid"])


            if _fmsg == "Forced failure during AI definition" :
                _status = 181
            else :
                _status = 0

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