Example #1
0
 def delete(self, request, *args, **kwargs):
     group_id = request.GET.get("group_id")
     if not group_id:
         return jresp(set_response("500", "group not found"))
     hostgroup = HostGroup.objects.get(id=group_id)
     host = hostgroup.host_set.all()
     if host.count() != 0:
         return jresp(
             set_response("500", "group is not empty,cant be remove"))
     hostgroup.delete()
     return jresp(set_response("200", "group remove success", group_id))
Example #2
0
 def delete(self, request, *args, **kwargs):
     host_id = request.GET.get("host_id")
     if not host_id:
         return jresp(
             set_response("400",
                          "host_group_id and host_id must be define"))
     try:
         host = Host.objects.get(id=host_id)
     except Exception as e:
         return jresp(set_response("400", "host not found"))
     host.delete()
     return jresp(set_response("200", "delete successd"))
Example #3
0
 def post(self, request, *args, **kwargs):
     ok, body = get_body(request)
     if not ok:
         return jresp(body)
     cmd = body.get("cmd")
     host_list = body.get("host_list")
     if not cmd:
         return jresp(set_response("500", "cmd not found", "cmd not found"))
     if len(host_list) == 0:
         return jresp(
             set_response("500", "host_list is empty",
                          "host_list is empty"))
     print(host_list)
     user = "******"
     passwd = '123456'
     c = Shell(user, passwd, host_list)
     result = c.exe(cmd)
     print(result)
     return jresp(set_response("200", "shell exec successd", result))
Example #4
0
 def post(self, request, *args, **kwargs):
     ok, body = get_body(request)
     if not ok:
         return jresp(body)
     group_name = body.get("group_name")
     user_name = body.get("user_name")
     passwd = body.get("passwd")
     if not group_name or not user_name or not passwd:
         return jresp(set_response("500", "主机名、用户、密码不能为空"))
     try:
         HostGroup.objects.get(group_name=group_name)
         return jresp(set_response("500", "host group is exist"))
     except Exception as e:
         pass
     host_group = HostGroup.objects.create(group_name=group_name,
                                           user_name=user_name,
                                           passwd=passwd)
     return jresp(
         set_response("200", "host group create successd",
                      host_group.group_name))
Example #5
0
 def post(self, request, *args, **kwargs):
     ok, body = get_body(request)
     if not ok:
         return jresp(body)
     host_group_id = body.get("host_group_id")
     host_list = body.get("host_list")
     try:
         host_group = HostGroup.objects.get(id=host_group_id)
     except Exception as e:
         return jresp(set_response("500", "host group not found"))
     hosts = Host.objects.filter(group=host_group_id)
     for host in host_list:
         try:
             hosts.get(host_ip=host.get("host_ip"))
             continue
         except Exception as e:
             Host.objects.create(host_ip=host.get("host_ip"),
                                 host_port=host.get("host_port"),
                                 group=host_group)
     return jresp(set_response("200", "host create successd", host_list))
Example #6
0
 def get(self, request, *args, **kwargs):
     host_group_id = request.GET.get("host_group_id")
     if not host_group_id:
         hosts = Host.objects.get_values()
     else:
         hosts = Host.objects.get_values(group=int(host_group_id))
     for host in hosts:
         group_name = HostGroup.objects.get(
             id=host.get("group_id")).group_name
         host["group_name"] = group_name
     return jresp(set_response("200", "host query successd", hosts))
Example #7
0
 def get(self, request, *args, **kwargs):
     host_group_list = HostGroup.objects.get_values()
     return jresp(
         set_response("200", "host query successd", host_group_list))
Example #8
0
 def options(self, request, *args, **kwargs):
     return jresp(set_response("200", "delete successd"))