def get(self, name): host = HostsModel.by_name(name) hosts_part = HostsModel.to_json(host) host_host_groups = HostHostGroupsModel.by_host_id(host.id) host_group = HostGroupsModel.by_id(host_host_groups.host_group_id) hosts_part['host_groups'] = HostGroupsModel.to_json( host_group) if host_group else None ssh_key = SshKeysModel.by_id(host.ssh_key_id) hosts_part['ssh_key'] = SshKeysModel.to_json(ssh_key) return hosts_part
def get(self): acls_json = [] acls = AclsModel.return_all() for acl in acls: acl_part = AclsModel.to_json(acl) host_group_acls = HostGroupAclsModel.by_acl_id(acl.id) host_group = HostGroupsModel.by_id(host_group_acls.host_group_id) acl_part['host_groups'] = HostGroupsModel.to_json(host_group) user_group_acls = UserGroupAclModel.by_acl_id(acl.id) user_group = UserGroupsModel.by_id(user_group_acls.user_group_id) acl_part['user_groups'] = UserGroupsModel.to_json(user_group) acls_json.append(acl_part) return acls_json
def get(self, id): # parser = reqparse.RequestParser() # parser.add_argument('id', help='This field cannot be blank', required=True) # data = parser.parse_args() # acl = AclsModel.by_id(data['id']) acl = AclsModel.by_id(id) acl_part = AclsModel.to_json(acl) host_group_acls = HostGroupAclsModel.by_acl_id(acl.id) host_group = HostGroupsModel.by_id(host_group_acls.host_group_id) acl_part['host_groups'] = HostGroupsModel.to_json(host_group) user_group_acls = UserGroupAclModel.by_acl_id(acl.id) user_group = UserGroupsModel.by_id(user_group_acls.user_group_id) acl_part['user_groups'] = UserGroupsModel.to_json(user_group) return acl_part
def get(self): hosts_json = [] hosts = HostsModel.return_all() for host in hosts: hosts_part = HostsModel.to_json(host) host_host_groups = HostHostGroupsModel.by_host_id(host.id) host_group = HostGroupsModel.by_id(host_host_groups.host_group_id) hosts_part['host_groups'] = HostGroupsModel.to_json( host_group) if host_group else None ssh_key = SshKeysModel.by_id(host.ssh_key_id) hosts_part['ssh_key'] = SshKeysModel.to_json(ssh_key) hosts_json.append(hosts_part) return hosts_json
def get(self, name): host_group = HostGroupsModel.by_name(name) host_groups_part = HostGroupsModel.to_json(host_group) host_group_acls = HostGroupAclsModel.by_host_group_id(host_group.id) host_groups_part['acls'] = [] for hgacls in host_group_acls: acl = AclsModel.by_id(hgacls.acl_id) host_groups_part['acls'].append(AclsModel.to_json(acl)) host_host_groups = HostHostGroupsModel.by_host_group_id(host_group.id) host_groups_part['hosts'] = [] for hhg in host_host_groups: host = HostsModel.by_id(hhg.host_id) host_groups_part['hosts'].append( HostsModel.to_json(host) if host else None) return host_groups_part
def get(self): users = UserModel.return_all() groups = UserGroupsModel.return_all() roles = UserRolesModel.return_all() keys = SshKeysModel.return_all() userkeys = UserKeysModel.return_all() hosts = HostsModel.return_all() hostgroups = HostGroupsModel.return_all() acls = AclsModel.return_all() sessions = SessionsModel.return_all() events = EventsModel.return_all() return { 'users': { 'count': len(users['users']) }, 'usergroups': { 'count': len(groups) }, 'userroles': { 'count': len(roles) }, 'keys': { 'count': len(keys) }, 'userkeys': { 'count': len(userkeys) }, 'hosts': { 'count': len(hosts), 'keys': len(list(set([x.ssh_key_id for x in hosts]))) }, 'hostgroups': { 'count': len(hostgroups) }, 'acls': { 'count': len(acls), 'allow': len([x for x in acls if x.action == 'allow']), }, 'sessions': { 'count': len(sessions), 'active': len([s for s in sessions if s.status != 'closed']), 'errors': len([s for s in sessions if s.err_msg != '']) }, 'events': { 'count': len(events), 'last_5': list(reversed([EventsModel.to_json(x) for x in events[-5:]])) } }