Exemplo n.º 1
0
def _commit(host, port, sessionid, args, _args):
   if args.user!=None:
      display.error("too many parameters")
      return False
   code,result=commit_users(host, port, sessionid)
   display.formated(result, args.format)
   return True
Exemplo n.º 2
0
def _password(host, port, sessionid, args, _args):
   j={}
   possible=["oldpassword", "newpassword"]
   for i in args.keyvalue:
      s=i.split(':')
      if len(s) != 2:
         display.error("property syntax error: "+str(i))
         return False

      v=s[0].strip().lower()
      if not v in possible:
         display.error("unknown property: "+str(v))
         return False
      j[s[0].strip().lower()]=v

   if "oldpassword" in j:
      oldpassword=j["oldpassword"]
   else:
      oldpassword=getpass.getpass("old password:"******"newpassword" in j:
      newpassword=j["newpassword"]
   else:
      newpassword=getpass.getpass("new password:")

   code,result= update_password(host, port, sessionid, oldpassword, newpassword)
   display.formated(result, args.format)
   return True
Exemplo n.º 3
0
def _delete(host, port, sessionid, args, _args):
   if len(args.keyvalue)>0:
      display.error("too many parameters")
      return False
   code,result=delete_user(host, port, sessionid, args.user)
   display.formated(result, args.format)
   return True
Exemplo n.º 4
0
def _commit(host, port, sessionid, args, _args):
    if args.name == None:
        code, result = commit_interfaces(host, port, sessionid)
    else:
        display.error("too many parameters")
        return False
    display.formated(result, args.format)
    return True
Exemplo n.º 5
0
def _get(host, port, sessionid, args, _args):
    _pid = args.pid
    if _pid == None:
        code, result = get_metrics(host, port, sessionid)
    else:
        code, result = get_metric(host, port, sessionid, _pid)
    display.formated(result, args.format)
    return True
Exemplo n.º 6
0
def _pairable(host, port, sessionid, args, _args):
    _result = None
    if args.name == None:
        code, result = get_pairable_interfaces(host, port, sessionid)
    else:
        code, result = get_pairable_interface(host, port, sessionid, args.name)
    display.formated(result, args.format)
    return True
Exemplo n.º 7
0
def _get(host, port, sessionid, args, _args):
   result=None
   if args.user==None:
      code,result=get_users(host, port, sessionid)
   else:
      code,result=get_user(host, port, sessionid, args.user)
   display.formated(result, args.format)
   return True
Exemplo n.º 8
0
def _add(host, port, sessionid, args, _args):
    interface = args.name
    if interface == None:
        display.error("no interface")
        return False
    j = {}

    if len(args.option) > 1 and args.option[0].strip().lower() == "device":
        code, result = _add_interface_device(host, port, sessionid, interface,
                                             args, _args)
        if code == -1:
            return False
    else:
        possibles = ["id_type", "state", "dev", "description", "parameters"]
        for i in args.option:
            s = str(i).split(':', 1)
            if len(s) != 2:
                display.error("property syntax error: " + str(i))
                return False
            v = s[0].strip().lower()
            if not v in possibles:
                display.error("unknown property: " + str(v))
                return False
            j[s[0].strip().lower()] = s[1].strip()

        if len(j) > 0:
            if not "id_type" in j:
                display.error("id_type is mandatory")
                return False
            _available_types = get_available_interfaces_types(
                host, port, sessionid)
            if j["id_type"] in _available_types:
                j["id_type"] = _available_types[j["id_type"]]
            else:
                display.error("Not valid id_type values")
                printValids("Valid id_type values", _available_types)
                return False

            if not "state" in j:
                display.error("state is mandatory")
                return False
            if j["state"] in interface_states:
                j["state"] = interface_states[j["state"]]
            else:
                display.error("Not valid id_type values")
                printValids("Valid id_type values", interface_states)
                return False

            if not "dev" in j:
                display.error("dev is mandatory")
                return False

            code, result = add_interface(host, port, sessionid, interface, j)
        else:
            display.error("no property")
            return False
    display.formated(result, args.format)
    return True
Exemplo n.º 9
0
def _get(host, port, sessionid, args, _args):
    result = None
    if len(_args) > 0:
        display.error("too many parameters")
        return False
    if args.key == None:
        code, result = get_configurations(host, port, sessionid)
    else:
        code, result = get_configuration(host, port, sessionid, args.key)
    display.formated(result, args.format)
    return True
Exemplo n.º 10
0
def _actions(action, host, port, sessionid, args, _args):
    if args.pid == None:
        display.error("pid is mandatory")
        return False
    if len(_args) > 0:
        display.error("too many parameters")
        return False

    code, result = do_action(host, port, sessionid, args.pid, action)
    display.formated(result, args.format)
    return True
Exemplo n.º 11
0
def _start(host, port, sessionid, args, _args):
    if args.name != None:
        code, result = set_pairing_interface(host, port, sessionid, args.name,
                                             1)
        display.formated(result, args.format)
        if (code == 200):
            return True
        else:
            return False
    else:
        display.error("parameter error")
        return False
Exemplo n.º 12
0
def _get(host, port, sessionid, args, _args):
    result = None
    if args.name == None:
        code, result = get_interfaces(host, port, sessionid)
    elif len(args.option) == 0:
        code, result = get_interface(host, port, sessionid, args.name)
    else:
        interface = args.name
        code, result = _get_interface_device(host, port, sessionid, interface,
                                             args, _args)
        if code == -1:
            return False
    display.formated(result, args.format)
    return True
Exemplo n.º 13
0
def _get(host, port, sessionid, args, _args):
    result = None

    if len(_args) != 0:
        display.error("too many parameters")
        return False

    if args.pid == None:
        code, result = get_services(host, port, sessionid)
    else:
        code, result = get_service(host, port, sessionid, args.pid)

    display.formated(result, args.format)
    return True
Exemplo n.º 14
0
def _delete(host, port, sessionid, args, _args):
    interface = args.name
    if len(args.option) == 0:
        code, result = delete_interface(host, port, sessionid, interface)
        display.formated(result, args.format)
        return True
    if len(args.option) == 2 and args.option[0].strip().lower() == "device":
        device = args.option[1].strip().lower()
        code, result = delete_interface_device(host, port, sessionid,
                                               interface, device)
        display.formated(result, args.format)
        return True
    else:
        display.error("bad parameters")
        return False
Exemplo n.º 15
0
def _rollback(host, port, sessionid, args, _args):
    if args.name == None:
        code, result = rollback_interfaces(host, port, sessionid)
    elif len(args.option) == 0:
        date_str = args.name
        try:
            #         _datetime = parse(date_str)
            _datetime = date_str
        except:
            display.error("bad date format: " + date_str)
            return False
        timestamp = _datetime.strftime('%s')
        code, result = rollback_interfaces(host, port, sessionid, timestamp)
    else:
        display.error("too many parameters")
        return False
    display.formated(result, args.format)
    return True
Exemplo n.º 16
0
def _create(host, port, sessionid, args, _args):
   username=args.user
   j={}
   possible=["password", "fullname", "profile"]
   for i in args.keyvalue:
      s=str(i).split(':')
      if len(s) != 2:
         display.error("property syntax error: "+str(i))
         return False
      v=s[0].strip().lower()
      if not v in possible:
         display.error("unknown property: "+str(v))
         return False

      j[s[0].strip().lower()]=s[1].strip()

   if len(j)>0:
      if not "password" in j:
         display.error("password is mandatory")
         return False

      if not "profile" in j:
         profile=0
      else:
         profile=int(j["profile"])

      if not "fullname" in j:
         fullname=""
      else:
         fullname=j["fullname"]

      user={"username":username, "password":j["password"], "fullname":fullname, "profile":profile}
      code,result= create_user(host, port, sessionid, user)
      display.formated(result, args.format)
      return True
   else:
      display.error("no parameters")
      return False

   display.error("unknown error")
   return False
Exemplo n.º 17
0
def _set(host, port, sessionid, args, _args):
    result = None
    if args.key == None:
        return False
    keyvalue = [args.key] + args.keyvalue
    if len(keyvalue) == 0:
        return False
    else:
        j = {}
        for i in keyvalue:
            s = i.split(':')
            if len(s) != 2:
                return False
            j[s[0].strip()] = s[1].strip()

        if len(j) > 0:
            code, result = set_configuration_parameters(
                host, port, sessionid, j)
            display.formated(result, args.format)
            return True
    return False
Exemplo n.º 18
0
def _update(host, port, sessionid, args, _args):
   username=args.user
   j={}
   possible=["password", "fullname", "profile"]

   for i in args.keyvalue:
      s=str(i).split(':')
      if len(s) != 2:
         display.error("property syntax error - "+str(i))
         return False

      v=s[0].strip().lower()
      if not v in possible:
         display.error("unknown property - "+str(v))
         return False

      j[s[0].strip().lower()]=s[1].strip()

   if len(j)>0:
      user={}
      if "fullname" in j:
         user["fullname"]=j["fullname"]
      if "password" in j:
         user["password"]=j["password"]
      if "profile" in j:
         user["profile"]=int(j["profile"])

      code,result= update_user(host, port, sessionid, username, user)
      display.formated(result, args.format)
      return True
   else:
      display.error("no parameters")
      return False

   display.error("sorry, unknown error")
   return False
Exemplo n.º 19
0
def _status(host, port, sessionid, args, _args):
    code, result = get_pairing_interfaces_status(host, port, sessionid)
    if args.name == None:
        display.formated(result, args.format)
        return True
    else:
        if args.name.upper() in result:
            display.formated(result[args.name.upper()], args.format)
            return True
        display.formated(None, args.format)
        return False