Ejemplo n.º 1
0
    def get_nws(self,auth,image_id=None,dom_id=None,node_id=None, op_level=None):
        vm_config=None
        if dom_id is not None:
#                dom=NodeService().get_dom(auth,dom_id,node_id)
            dom=DBHelper().find_by_name(VM,dom_id)
            vm_config=dom.get_config()

        elif image_id is not None:
            image=ImageService().get_image(auth,image_id)
            (vm_config,img_conf)=image.get_configs()

        if not vm_config:
            return
        managed_node=None
        if node_id is not None:
            managed_node=NodeService().get_managed_node(auth,node_id)
            if managed_node is not None:
                self.managed_node=managed_node
        vifs = vm_config.getNetworks()
        result=[]

        for vif in vifs:
            result.append(self.get_nw_entry(vif, op_level))
        
        return result
Ejemplo n.º 2
0
    def migration_vm_checks(self, vm_name, dest_node, live):
       """
       Implements a series of compatiblity checks required for successful
       migration.
       """
       (err_list, warn_list) = VNode.migration_vm_checks(self, vm_name,
                                                         dest_node, live)
       
       if self.is_up():
            vm = self.get_dom(vm_name)
       else:
            vm = DBHelper().find_by_name(VM,vm_name)
       if vm == None :
          err_list.append(("VM", "VM %s not found."% vm_name))
          return (err_list, warn_list)


       # mem assumed to be in MB (same unit)
       vm_memory = 0
       if vm.is_running():
          vm_memory = vm["memory"]

       if dest_node.is_up():
           node_free_mem =  self.guess_free_mem(dest_node)
           if int(vm_memory) >  node_free_mem:
              err_list.append(("Memory","Insufficient memory on destination node. " \
                              "VM memory %s, free memory on destination node %s " % 
                              (vm["memory"], node_free_mem)))

       # TBD : compare CPUs. This needs to encode compatibility list.
       #       check AMD/INTEL
       #       X86/X32

       # 32 bit vs 64 bit kernel

       # critical files available or not.
       vm_conf = vm.get_config()
       if vm_conf is not None and dest_node.is_up():
          bootloader = vm_conf["bootloader"]
          if bootloader and bootloader.strip() is not "":
             if not dest_node.node_proxy.file_exists(bootloader.strip()):
                err_list.append(("Bootloader","Bootloader %s for %s vm not found on destination node." % (bootloader.strip(), vm.name)))
          kernel = vm_conf["kernel"]
          if kernel and kernel.strip() is not "":
             if not dest_node.node_proxy.file_exists(kernel.strip()):
                err_list.append(("Kernel","Kernel %s for %s vm not found on destination node." % (kernel.strip(), vm.name)))
          ramdisk = vm_conf["ramdisk"]
          if ramdisk and ramdisk.strip() is not "":
             if not dest_node.node_proxy.file_exists(ramdisk.strip()):
                err_list.append(("Ramdisk", "Ramdisk %s for %s vm not found on destination node." % (ramdisk.strip(), vm.name)))
     
       # hvm availablity
       if vm_conf and vm_conf.is_hvm() \
          and dest_node.get_platform_info().get("xen_caps","").find("hvm")==-1:
          err_list.append(("HVM","VM %s requires hvm capabilities which are not found on destination node." % (vm.name)))


       # TBD : PAE kernel check

       return (err_list, warn_list)
Ejemplo n.º 3
0
    def get_miscellaneous_configs(self, auth, image_id, dom_id, node_id,
                                  group_id, action):
        result = []
        display_list = []

        if action == "change_vm_settings":
            #dom = self.node_service.get_dom(auth,dom_id,node_id)
            dom = DBHelper().find_by_name(VM, dom_id)
            if dom is not None:
                vm_config = dom.get_config()
        else:
            image = self.image_store.get_image(auth, image_id)
            if image is None:
                raise Exception("Can not find the specified Image.")

            if dom_id is None:
                vm_config, img_config = image.get_configs()
                #vm_config=get_config(image.vm_config)
            else:
                #dom = self.node_service.get_dom(auth,dom_id,node_id)
                dom = DBHelper().find_by_name(VM, dom_id)
                vm_config = dom.get_config()

            if action == 'provision_image' or action == 'provision_vm':
                group = self.manager.getGroup(auth, group_id)
                if group is not None:
                    grp_settings = group.getGroupVars()
                    merge_pool_settings(vm_config, img_config, grp_settings,
                                        True)

        for key in vm_config:
            #            print key,"---++--",vm_config[key]
            if key not in self.node_service.get_exclude_list() and \
               key not in vm_config.get_computed_options() :
                display_list.append(key)

        display_list.sort()

        for key in display_list:
            value = vm_config[key]
            value = process_value(value)
            result.append(dict(attribute=key, value=to_str(value)))
        return dict(success='true', rows=result)
Ejemplo n.º 4
0
    def get_miscellaneous_configs(self,auth,image_id,dom_id,node_id,group_id,action):        
        result=[]
        display_list=[]

        if action=="change_vm_settings":
                #dom = self.node_service.get_dom(auth,dom_id,node_id)
                dom=DBHelper().find_by_name(VM,dom_id)
                if dom is not None:
                    vm_config=dom.get_config()
        else:
            image=self.image_store.get_image(auth,image_id)
            if image is None:
                raise Exception("Can not find the specified Image.")

            if dom_id is None:
                vm_config,img_config = image.get_configs()
                #vm_config=get_config(image.vm_config)
            else:
                #dom = self.node_service.get_dom(auth,dom_id,node_id)
                dom=DBHelper().find_by_name(VM,dom_id)
                vm_config=dom.get_config()

            if action=='provision_image' or action=='provision_vm':
                group=self.manager.getGroup(auth,group_id)
                if group is not None:
                    grp_settings = group.getGroupVars()
                    merge_pool_settings(vm_config,img_config,grp_settings, True)
                
        for key in vm_config:
#            print key,"---++--",vm_config[key]
            if key not in self.node_service.get_exclude_list() and \
               key not in vm_config.get_computed_options() :
                display_list.append(key)

        display_list.sort()
        
        for key in display_list:
            value=vm_config[key]
            value=process_value(value)
            result.append(dict(attribute=key,value=to_str(value)))
        return dict(success='true',rows=result)
Ejemplo n.º 5
0
    def disk_data(self,auth,dom_id,node_id,mode):
        result=[]
        vm_config=None
        if mode !="NEW":
           # dom = self.node_service.get_dom(auth,dom_id,node_id)
            dom=DBHelper().find_by_name(VM,dom_id)
            if dom is None:
                raise Exception("Can not find the specified .")
            vm_config=dom.get_config()
            disks=VMDiskManager(vm_config).getDisks(dom.id)
        else:
                #new_disk = self.get_new_disk_entry(None)
                #TODO: think about this, can we change this
                new_disk = VMDiskManager(vm_config).get_new_disk_entry()
                disks=[new_disk]
        is_remote=False
        for disk in disks:
            storage_disk_id = ""
            storage_id = ""
            storage_name=None
            if vm_config:
                #is_remote = vm_config.get_storage_stats().get_remote(disk.filename)
                is_remote = VMDiskManager(vm_config).get_remote(disk.disk_name)
                #storage_disk_id = vm_config.get_storage_stats().get_storage_disk_id(disk.filename)
                storage_disk_id = VMDiskManager(vm_config).get_storage_disk_id(disk.disk_name)
                storage_id = VMDiskManager(vm_config).get_storage_id(disk.disk_name)
                if storage_disk_id:
                    vm_storage_link = DBSession.query(VMStorageLinks).filter_by(vm_disk_id=disk.id, storage_disk_id=storage_disk_id).first()
                    if vm_storage_link:
                        if storage_id:
                            defn = self.storage_manager.get_defn(storage_id)
                            storage_name = defn.name

            """
            result.append(dict(type=disk.type,filename=disk.filename,device=disk.device,
                                mode=disk.mode,shared=is_remote,option=disk.option,disk_create="",
                                size=disk.size,disk_type=disk.disk_type,image_src=disk.image_src,
                                image_src_type=disk.image_src_type,image_src_format=disk.image_src_format,fs_type="",storage_disk_id=storage_disk_id))
            """
            if mode!="NEW":
                disk_gb=disk.disk_size*1024
                disk_size=round(disk_gb)
            else:
                disk_size=disk.disk_size
            result.append(dict(type=disk.disk_type,filename=disk.disk_name,device=disk.dev_type,
                                mode=disk.read_write,shared=is_remote,option="",disk_create="",
                                size=disk_size,disk_type=disk.disk_type,image_src="",
                                image_src_type="",image_src_format="",fs_type=disk.file_system,
                                storage_disk_id=storage_disk_id, storage_id=storage_id,
                                storage_name=storage_name,sequence=disk.sequence))
        return result
Ejemplo n.º 6
0
    def get_disks(self,auth,image_id,mode,dom_id,node_id,group_id,action):
        result=[]
        try:
            if action=="change_vm_settings":
                return self.disk_data(auth,dom_id,node_id,mode)
            else:
                image=self.image_store.get_image(auth,image_id)
                if image is None:
                    raise Exception("Can not find the specified Image.")

                grp_settings={}
                group=self.manager.getGroup(auth,group_id)
                if group is not None:
                    grp_settings = group.getGroupVars()

                disks=[]
                vm_config,image_config = image.get_configs()
                if mode !="NEW":
                    if dom_id is not None :
#                        dom = self.node_service.get_dom(auth,dom_id,node_id)
                        dom=DBHelper().find_by_name(VM,dom_id)
                        vm_config=dom.get_config()
                    if action!='edit_image_settings':
                        merge_pool_settings(vm_config,image_config,grp_settings, True)
                        vm_config.instantiate_config(image_config)
                    disks = vm_config.getDisks(image_config)
                else:
                    new_disk = self.get_new_disk_entry(image_config)
                    if action!='edit_image_settings':
                        if grp_settings.get('VM_DISKS_DIR',None) is not None:
                            new_disk.filename=new_disk.filename.replace('$VM_DISKS_DIR',grp_settings.get('VM_DISKS_DIR'))
                        elif image_config.get('VM_DISKS_DIR') is not None:
                            new_disk.filename=new_disk.filename.replace('$VM_DISKS_DIR',image_config.get('VM_DISKS_DIR'))
                    disks=[new_disk]

        #        print "DDDDDDEVICe  =",disks
        #        vm_config,image_config = image.get_configs()

                is_remote=False

                for disk in disks:
                    if vm_config:
                        is_remote = vm_config.get_storage_stats().get_remote(disk.filename)
                        storage_disk_id = vm_config.get_storage_stats().get_storage_disk_id(disk.filename)
                        result.append(dict(type=disk.type,filename=disk.filename,device=disk.device,
                                        mode=disk.mode,shared=is_remote,option=disk.option,disk_create=disk.disk_create,
                                        size=disk.size,disk_type=disk.disk_type,image_src=disk.image_src,
                                        image_src_type=disk.image_src_type,image_src_format=disk.image_src_format,fs_type=disk.fs_type,storage_disk_id=storage_disk_id))
        except Exception, ex:
            print_traceback()
            raise ex
Ejemplo n.º 7
0
    def migration_vm_checks(self, vm_name, dest_node, live):
        """
       Implements a series of compatiblity checks required for successful
       migration.
       """
        (err_list,
         warn_list) = VNode.migration_vm_checks(self, vm_name, dest_node, live)

        if self.is_up():
            vm = self.get_dom(vm_name)
        else:
            vm = DBHelper().find_by_name(VM, vm_name)
        if vm == None:
            err_list.append(("VM", "VM %s not found." % vm_name))
            return (err_list, warn_list)

        # mem assumed to be in MB (same unit)
        vm_memory = 0
        if vm.is_running():
            vm_memory = vm["memory"]

        if dest_node.is_up():
            node_free_mem = self.guess_free_mem(dest_node)
            if int(vm_memory) > node_free_mem:
                err_list.append(("Memory","Insufficient memory on destination node. " \
                                "VM memory %s, free memory on destination node %s " %
                                (vm["memory"], node_free_mem)))

        # TBD : compare CPUs. This needs to encode compatibility list.
        #       check AMD/INTEL
        #       X86/X32

        # 32 bit vs 64 bit kernel

        # critical files available or not.
        vm_conf = vm.get_config()
        if vm_conf is not None and dest_node.is_up():
            bootloader = vm_conf["bootloader"]
            if bootloader and bootloader.strip() is not "":
                if not dest_node.node_proxy.file_exists(bootloader.strip()):
                    err_list.append((
                        "Bootloader",
                        "Bootloader %s for %s vm not found on destination node."
                        % (bootloader.strip(), vm.name)))
            kernel = vm_conf["kernel"]
            if kernel and kernel.strip() is not "":
                if not dest_node.node_proxy.file_exists(kernel.strip()):
                    err_list.append(
                        ("Kernel",
                         "Kernel %s for %s vm not found on destination node." %
                         (kernel.strip(), vm.name)))
            ramdisk = vm_conf["ramdisk"]
            if ramdisk and ramdisk.strip() is not "":
                if not dest_node.node_proxy.file_exists(ramdisk.strip()):
                    err_list.append((
                        "Ramdisk",
                        "Ramdisk %s for %s vm not found on destination node." %
                        (ramdisk.strip(), vm.name)))

        # hvm availablity
        if vm_conf and vm_conf.is_hvm() \
           and dest_node.get_platform_info().get("xen_caps","").find("hvm")==-1:
            err_list.append((
                "HVM",
                "VM %s requires hvm capabilities which are not found on destination node."
                % (vm.name)))

        # TBD : PAE kernel check

        return (err_list, warn_list)
Ejemplo n.º 8
0
 def disk_data(self, auth, dom_id, node_id, mode):
     result = []
     vm_config = None
     if mode != "NEW":
         # dom = self.node_service.get_dom(auth,dom_id,node_id)
         dom = DBHelper().find_by_name(VM, dom_id)
         if dom is None:
             raise Exception("Can not find the specified .")
         vm_config = dom.get_config()
         disks = VMDiskManager(vm_config).getDisks(dom.id)
     else:
         #new_disk = self.get_new_disk_entry(None)
         #TODO: think about this, can we change this
         new_disk = VMDiskManager(vm_config).get_new_disk_entry()
         disks = [new_disk]
     is_remote = False
     for disk in disks:
         storage_disk_id = ""
         storage_id = ""
         storage_name = None
         if vm_config:
             #is_remote = vm_config.get_storage_stats().get_remote(disk.filename)
             is_remote = VMDiskManager(vm_config).get_remote(disk.disk_name)
             #storage_disk_id = vm_config.get_storage_stats().get_storage_disk_id(disk.filename)
             storage_disk_id = VMDiskManager(vm_config).get_storage_disk_id(
                 disk.disk_name)
             storage_id = VMDiskManager(vm_config).get_storage_id(
                 disk.disk_name)
             if storage_disk_id:
                 vm_storage_link = DBSession.query(
                     VMStorageLinks).filter_by(
                         vm_disk_id=disk.id,
                         storage_disk_id=storage_disk_id).first()
                 if vm_storage_link:
                     if storage_id:
                         defn = self.storage_manager.get_defn(storage_id)
                         storage_name = defn.name
         """
         result.append(dict(type=disk.type,filename=disk.filename,device=disk.device,
                             mode=disk.mode,shared=is_remote,option=disk.option,disk_create="",
                             size=disk.size,disk_type=disk.disk_type,image_src=disk.image_src,
                             image_src_type=disk.image_src_type,image_src_format=disk.image_src_format,fs_type="",storage_disk_id=storage_disk_id))
         """
         if mode != "NEW":
             disk_gb = disk.disk_size * 1024
             disk_size = round(disk_gb)
         else:
             disk_size = disk.disk_size
         result.append(
             dict(type=disk.disk_type,
                  filename=disk.disk_name,
                  device=disk.dev_type,
                  mode=disk.read_write,
                  shared=is_remote,
                  option="",
                  disk_create="",
                  size=disk_size,
                  disk_type=disk.disk_type,
                  image_src="",
                  image_src_type="",
                  image_src_format="",
                  fs_type=disk.file_system,
                  storage_disk_id=storage_disk_id,
                  storage_id=storage_id,
                  storage_name=storage_name,
                  sequence=disk.sequence))
     return result
Ejemplo n.º 9
0
    def get_disks(self, auth, image_id, mode, dom_id, node_id, group_id,
                  action):
        result = []
        try:
            if action == "change_vm_settings":
                return self.disk_data(auth, dom_id, node_id, mode)
            else:
                image = self.image_store.get_image(auth, image_id)
                if image is None:
                    raise Exception("Can not find the specified Image.")

                grp_settings = {}
                group = self.manager.getGroup(auth, group_id)
                if group is not None:
                    grp_settings = group.getGroupVars()

                disks = []
                vm_config, image_config = image.get_configs()
                if mode != "NEW":
                    if dom_id is not None:
                        #                        dom = self.node_service.get_dom(auth,dom_id,node_id)
                        dom = DBHelper().find_by_name(VM, dom_id)
                        vm_config = dom.get_config()
                    if action != 'edit_image_settings':
                        merge_pool_settings(vm_config, image_config,
                                            grp_settings, True)
                        vm_config.instantiate_config(image_config)
                    disks = vm_config.getDisks(image_config)
                else:
                    new_disk = self.get_new_disk_entry(image_config)
                    if action != 'edit_image_settings':
                        if grp_settings.get('VM_DISKS_DIR', None) is not None:
                            new_disk.filename = new_disk.filename.replace(
                                '$VM_DISKS_DIR',
                                grp_settings.get('VM_DISKS_DIR'))
                        elif image_config.get('VM_DISKS_DIR') is not None:
                            new_disk.filename = new_disk.filename.replace(
                                '$VM_DISKS_DIR',
                                image_config.get('VM_DISKS_DIR'))
                    disks = [new_disk]

        #        print "DDDDDDEVICe  =",disks
        #        vm_config,image_config = image.get_configs()

                is_remote = False

                for disk in disks:
                    if vm_config:
                        is_remote = vm_config.get_storage_stats().get_remote(
                            disk.filename)
                        storage_disk_id = vm_config.get_storage_stats(
                        ).get_storage_disk_id(disk.filename)
                        result.append(
                            dict(type=disk.type,
                                 filename=disk.filename,
                                 device=disk.device,
                                 mode=disk.mode,
                                 shared=is_remote,
                                 option=disk.option,
                                 disk_create=disk.disk_create,
                                 size=disk.size,
                                 disk_type=disk.disk_type,
                                 image_src=disk.image_src,
                                 image_src_type=disk.image_src_type,
                                 image_src_format=disk.image_src_format,
                                 fs_type=disk.fs_type,
                                 storage_disk_id=storage_disk_id))
        except Exception, ex:
            print_traceback()
            raise ex