Exemple #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)
Exemple #2
0
 def SyncAll(self, site_id, group, defn_list, op, auth, def_manager, transient_state, state_owner, state_transaction):
     error_desc = ''
     for eachdefn in defn_list:
         self.set_transient_state(eachdefn, constants.SYNCING, constants.SCOPE_LEVEL, site_id, group.id, None)
         grp_ent = DBSession.query(Entity).filter(Entity.entity_id == group.id).first()
         for node in PrivilegeOps.get_servers(grp_ent):
             try:
                 self.change_defn_transient_state(auth, node, transient_state, state_owner, state_transaction)
                 node_defn = DBSession.query(ServerDefLink).filter_by(def_id=eachdefn.id, server_id=node.id).first()
                 if node_defn:
                     defType = node_defn.def_type
                     self.sync_node_defn(auth, node, group.id, site_id, eachdefn, defType, op, def_manager)
             except Exception as ex:
                 error_desc += to_str(ex) + '\n'
                 LOGGER.error('SP Sync operation is failed for server (' + node.hostname + ') and definition (' + eachdefn.name + '). Error description: ' + to_str(ex))
                 state_transaction.set_none_state(node.id, state_owner)
             state_transaction.set_none_state(node.id, state_owner)
         self.set_transient_state(eachdefn, None, constants.SCOPE_LEVEL, site_id, group.id, None)
     if error_desc:
         raise Exception(error_desc)
Exemple #3
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