Beispiel #1
0
 def add_defn(self, defn, site, group, node, auth, defType, op, action_op, def_manager, grid_manager, op_level, sp_ids=None, scan_result=None, csep_id=None):
     scope = op_level
     if scope == constants.SCOPE_S:
         entityId = node.id
     elif scope == constants.SCOPE_SP:
         entityId = group.id
     elif scope == constants.SCOPE_DC:
         entityId = site.id
     elif scope == constants.SCOPE_CP:
         entityId = csep_id
     ent = auth.get_entity(entityId)
     if not auth.has_privilege(action_op, ent):
         raise Exception(constants.NO_PRIVILEGE)
     if scope == constants.SCOPE_SP:
         if not PrivilegeOps.check_child_privileges(auth, action_op, ent):
             raise Exception(constants.NO_CHILD_PRIVILEGE % ('Servers', 'Server Pool'))
     DBSession.add(defn)
     nw_id = defn.id
     if site:
         def_manager.SaveScanResult(defn.id, grid_manager, scan_result, site.id)
     def_manager.RemoveScanResult(scan_result)
     errs = []
     details = {}
     status = to_unicode(constants.OUT_OF_SYNC)
     if scope == constants.SCOPE_DC:
         oos_count = 0
         status = to_unicode(constants.IN_SYNC)
         self.add_site_defn(site.id, defn.id, defType, status, oos_count)
         def_manager.manage_defn_to_groups(site, group, sp_ids, defn, defType, op, def_manager, auth, errs, grid_manager)
     elif scope == constants.SCOPE_SP:
         def_manager.manage_defn_to_groups(site, group, sp_ids, defn, defType, op, def_manager, auth, errs, grid_manager)
     elif scope == constants.SCOPE_S:
         self.add_node_defn(node.id, defn.id, defType, status, details)
         update_status = True
         #def_manager.add_private_ip_pool(defn)
         self.sync_node_defn(auth, node, group.id, site.id, defn, defType, op, def_manager, update_status, errs)
         
     elif scope == constants.SCOPE_CP:
         oos_count = 0
         status = to_unicode(constants.IN_SYNC)
         self.add_csep_defn(csep_id, defn.id, defType, status, oos_count)
         def_manager.manage_defn_to_groups(site, group, sp_ids, defn, defType, op, def_manager, auth, errs, grid_manager, csep_id)
         details['defn_id'] = defn.id
         if node:
             details['node_id'] = node.id
     def_manager.on_defn_creation(auth,**details)
     def_manager.Recompute(defn)
     if errs:
         if len(errs) > 0:
             LOGGER.error('Error:' + to_str(errs))
     return (errs, nw_id)
Beispiel #2
0
    def remove_defn(self, defn, site, group, node, auth, defType, op, action_op, def_manager, grid_manager, add_mode=False, group_list=None, op_level=None, csep_id=None):
        warning_msg = None
        scope = op_level
        entityId = None
        server_list = []
        if scope == constants.SCOPE_S:
            entityId = node.id
        elif scope == constants.SCOPE_SP:
            entityId = group.id
        elif scope == constants.SCOPE_DC:
            entityId = site.id
        elif scope == constants.SCOPE_CP:
            entityId = csep_id
        ent = auth.get_entity(entityId)
        if not auth.has_privilege(action_op, ent):
            raise Exception(constants.NO_PRIVILEGE)
        if scope == constants.SCOPE_SP:
            if not PrivilegeOps.check_child_privileges(auth, action_op, ent):
                raise Exception(constants.NO_CHILD_PRIVILEGE % ('Servers', 'Server Pool'))
        if defn:
            returnVal = def_manager.is_storage_allocated(defn.id)
            if returnVal==True:
                allocated = False
                if op_level==constants.SCOPE_SP and defn.scope==constants.SCOPE_DC:
                    vm_disks = grid_manager.get_vm_disks_from_pool(auth, group.id)
                    storage_disks = grid_manager.get_storage_disks_from_storage(defn.id)
                    if storage_disks:
                        for each_storage_disk in storage_disks:
                            if allocated == True:
                                break
                            for each_vm_disk in vm_disks:
                                vm_storage_link = DBSession.query(VMStorageLinks).filter_by(vm_disk_id=each_vm_disk.id, storage_disk_id=each_storage_disk.id).first()
                                if vm_storage_link:
                                    allocated = True
                                    warning_msg = 'All the links associated with the storage (' + to_str(defn.name) + ') would be removed'
                                    break
                else:
                    warning_msg = 'The storage (' + to_str(defn.name) + ') and all the links associated with it would be removed'
            if op_level == constants.SCOPE_SP and defn.scope == constants.SCOPE_DC:
                defn.is_deleted = False
            else:
                defn.is_deleted = True
            node_defn = DBSession.query(ServerDefLink).filter_by(def_id=defn.id).first()
            if node_defn:
                node = DBSession.query(ManagedNode).filter_by(id=node_defn.server_id).first()
            site_id = None
            group_id = None
            if node:
                if group:
                    group_id = group.id
                else:
                    entity = auth.get_entity(node.id)
                    if entity:
                        group_id = entity.parents[0].entity_id
                if group_id:
                    group = DBSession.query(ServerGroup).filter_by(id=group_id).first()
                if group:
                    if site:
                        site_id = site.id
                    else:
                        entity = auth.get_entity(group.id)
                        if entity:
                            site_id = entity.parents[0].entity_id
                    if site_id:
                        site = DBSession.query(Site).filter_by(id=site_id).first()

                if add_mode==False:
                    if defn.scope==constants.SCOPE_S:
                        self.sync_node_defn(auth, node, group_id, site_id, defn, defType, op, def_manager)
                        server_list.append(node)
                    elif op_level==constants.SCOPE_SP:
                        result = self.sync_defn(defn, site, group, auth, defType, op, def_manager)
                        if result:
                            server_list.extend(result)
                    elif op_level==constants.SCOPE_DC and defn.scope==constants.SCOPE_DC:
                        site_entity = auth.get_entity(site.id)
                        group_entities = auth.get_entities(to_unicode(constants.SERVER_POOL), site_entity)
                        for eachgroup in group_entities:
                            group = DBSession.query(ServerGroup).filter_by(id=eachgroup.entity_id).first()
                            result = self.sync_defn(defn, site, group, auth, defType, op, def_manager)
                            if result:
                                server_list.extend(result)
                    elif op_level==constants.SCOPE_CP and defn.scope==constants.SCOPE_CP:
                        dc_def_links = DBSession.query(SPDefLink).filter_by(def_id=defn.id)
                        for each_link in dc_def_links:
                            group = DBSession.query(ServerGroup).filter_by(id=each_link.group_id).first()
                            update_status = True
                            errs = None
                            result = self.sync_defn(defn, site, group, auth, defType, op, def_manager, update_status, errs, csep_id)
                            if result:
                                server_list.extend(result)
        if op_level == constants.SCOPE_SP and defn.scope == constants.SCOPE_DC:
            defn.is_deleted = False
            self.disassociate_defn(site, group, auth, defn, defType, add_mode, grid_manager)
        else:
            self.delete_defn(defn, auth, defType, def_manager, grid_manager)
        def_manager.Recompute(defn)
        return warning_msg