示例#1
0
    def set_updated_entities(self, entity_ids):
        node_ids = []
        up_sessions = {}
        (usrs, grps) = ([], [])
        if not entity_ids:
            LOGGER.error('Error: entity_ids are not found.')
            return None
        del_ent_usrs = []
        for entity_id in entity_ids.split(','):
            usr_grps = []
            ent = Entity.get_entity(entity_id)
            if ent and ent.type.name==constants.DOMAIN:
                if ent.csep_context_id:
                    vm = DBSession.query(VM.cloud_vm_id).filter(VM.id == entity_id).first()
                    if vm and vm[0]:
                        cloud_vm_id = vm[0]
                        node_ids.append(cloud_vm_id)
                        node_ids = self.merge_lists(node_ids, Entity.get_hierarchy(cloud_vm_id))
                        usr_grps.extend(Entity.get_users_groups(cloud_vm_id))

            hierarchy = Entity.get_hierarchy(entity_id)
            if not hierarchy:
                hierarchy = [entity_id]
                del_ent_usrs = self.updated_entities.keys()

            node_ids = self.merge_lists(node_ids, hierarchy)
            usr_grps.extend(Entity.get_users_groups(entity_id))
            (priv_usrs, priv_groups) = ([], [])

            for priv_usr,priv_group in usr_grps:
                priv_usrs.append(priv_usr)
                priv_groups.append(priv_group)

            usrs = self.merge_lists(usrs, priv_usrs)
            grps = self.merge_lists(grps, priv_groups)

        usr_names=[u.user_name for u in usrs]

        grp_names=[g.group_name for g in priv_groups]
        if del_ent_usrs:
            usr_names=del_ent_usrs
        try:
            self.lock.acquire()
            
            for key in self.updated_entities.keys():
                if key not in usr_names and key not in grp_names:
                    continue
                else:
                    up_sessions=self.updated_entities.get(key, {})
                    for session,nodes in up_sessions.iteritems():
                        if len(nodes) > 35:
                            nodes=[]
                        updated_nodes=self.merge_lists(nodes, node_ids)
                        self.updated_entities[key][session]=updated_nodes
        finally:
            self.lock.release()
示例#2
0
    def add_entity(self, name, entity_id, entityType, parent):
        try:
            type = DBHelper().find_by_name(EntityType, entityType)
            e = Entity()
            e.name = name
            e.type = type
            e.entity_id = entity_id
            e.parent = parent
            DBHelper().add(e)

        except Exception as e:
            raise e

        return e
示例#3
0
 def set_updated_tasks(self, task_id, user_name, entity_id=None):
     user_names = []
     if entity_id:
         usr_grps = Entity.get_users_groups(entity_id)
         if not usr_grps:
             user_names = self.updated_tasks.keys()
         else:
             priv_usrs = []
             for priv_usr,priv_group in usr_grps:
                 priv_usrs.append(priv_usr)
             user_names=[u.user_name for u in priv_usrs]
             if user_name not in user_names:
                 user_names.append(user_name)
     else:
         user_names.append(user_name)
     self.lock.acquire()
     try:
         for user_name in user_names:
             up_sessions = self.updated_tasks.get(user_name, {})
             for session,tasks in up_sessions.iteritems():
                 if len(tasks) > 35:
                     tasks = []
                 updated_tasks = self.merge_lists(tasks, [task_id])
                 self.updated_tasks[user_name][session] = updated_tasks
     finally:
         self.lock.release()
示例#4
0
    def get_entity_id(self, name, type):
        try:
            type_id = self.get_mapped_type(type)
            ent = Entity.find_by_name(name, type_id)
            if ent is not None:
                return {"success": True, "entity_id": ent.entity_id}
            return {"success": False, "msg": "The Entity is not found"}

        except Exception as ex:
            print_traceback()
            return {"success": False, "msg": to_str(ex).replace("'", "")}
示例#5
0
 def create_vmw_datacenter(self, auth, name, actual_name, moid, vcenter_id, parent_ent=None):
     msg = ''
     entityType = to_unicode(constants.DATA_CENTER)
     dc = None
     update_name = False
     dc_ent = auth.get_entity_by_entity_attributes(self.get_entity_attributes_dict(vcenter_id, moid), entityType)
     if not dc_ent:
         dup_ent = auth.get_entity_by_name(name, entityType=entityType)
         if dup_ent:
             msg += '\nERROR: Could not import Datacenter:%s. It is already exist,please choose different name' % name
             return (msg, None, None)
     if dc_ent:
         update_name = self.can_update_managed_object_name(auth, name, actual_name, dc_ent.name)
         msg += '\nDatacenter: %s already exist' % name
         dc = DBSession.query(VMWDatacenter).filter(VMWDatacenter.id == dc_ent.entity_id).first()
         if dc:
             if update_name:
                 dc.name = name
     if not dc:
         msg += '\nCreating Datacenter: %s' % name
         dc = VMWDatacenter(name)
     DBSession.add(dc)
     if not dc_ent:
         dc_ent = Entity()
         dc_ent.name = dc.name
         dc_ent.entity_id = dc.id
         dc_ent.type_id = 1
         ent_cntx_dict = self.get_entity_context_dict(external_manager_id=vcenter_id, external_id=moid)
         dc_ent.context_id = auth.add_context(ent_cntx_dict)
         DBSession.add(dc_ent)
         admin_role = auth.get_admin_role()
         auth.make_rep_entry(admin_role, dc_ent)
         ent_attr_dict = self.get_entity_attributes_dict(external_manager_id=vcenter_id, external_id=moid)
         self.add_entity_attributes(dc_ent, ent_attr_dict)
     else:
         if not update_name:
             name = None
         auth.update_entity(dc_ent, name=name)
     return (msg, dc, dc_ent)
示例#6
0
文件: Groups.py 项目: smarkm/ovm
 def checkVmLimit(self, node_id, group):
     if node_id:
         concurrent_provision_count = Entity.get_attribute_value(node_id, 'concurrent_provision_count', None)
         if not concurrent_provision_count:
             concurrent_provision_count = self._group.getGroupVarValue('CONCURRENT_PROVISION_COUNT')
             if not concurrent_provision_count:
                 concurrent_provision_count = tg.config.get(constants.CONCURRENT_PROVISION_COUNT)
         avails = DBSession.query(AvailState).filter(AvailState.entity_id == node_id).first()
         used_count = int(avails.used_count)
         ccpc = 3
         try:
             ccpc = int(concurrent_provision_count)
         except Exception as e:
             print 'Exception:',
             print e
         if ccpc <= used_count:
             return False
         return True