add assign function in device.py for user/strategy/ab
This commit is contained in:
parent
53dbc2fa6f
commit
7d961d895b
@ -91,11 +91,24 @@ def delete(url, token, guid, id):
|
|||||||
return check(response)
|
return check(response)
|
||||||
|
|
||||||
|
|
||||||
|
def assign(url, token, guid, id, type, value):
|
||||||
|
print("assign", id, type, value)
|
||||||
|
if type != "ab" and type != "strategy_name" and type != "user_name":
|
||||||
|
print("Invalid type, it must be 'ab', 'strategy_name' or 'user_name'")
|
||||||
|
return
|
||||||
|
data = {"type": type, "value": value}
|
||||||
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
response = requests.post(
|
||||||
|
f"{url}/api/devices/{guid}/assign", headers=headers, json=data
|
||||||
|
)
|
||||||
|
return check(response)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Device manager")
|
parser = argparse.ArgumentParser(description="Device manager")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"command",
|
"command",
|
||||||
choices=["view", "disable", "enable", "delete"],
|
choices=["view", "disable", "enable", "delete", "assign"],
|
||||||
help="Command to execute",
|
help="Command to execute",
|
||||||
)
|
)
|
||||||
parser.add_argument("--url", required=True, help="URL of the API")
|
parser.add_argument("--url", required=True, help="URL of the API")
|
||||||
@ -106,6 +119,10 @@ def main():
|
|||||||
parser.add_argument("--device_name", help="Device name")
|
parser.add_argument("--device_name", help="Device name")
|
||||||
parser.add_argument("--user_name", help="User name")
|
parser.add_argument("--user_name", help="User name")
|
||||||
parser.add_argument("--group_name", help="Group name")
|
parser.add_argument("--group_name", help="Group name")
|
||||||
|
parser.add_argument(
|
||||||
|
"--assign_to",
|
||||||
|
help="<type>=<value>, e.g. user_name=mike, strategy_name=test, ab=ab1, ab=ab1,tag1",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--offline_days", type=int, help="Offline duration in days, e.g., 7"
|
"--offline_days", type=int, help="Offline duration in days, e.g., 7"
|
||||||
)
|
)
|
||||||
@ -137,6 +154,16 @@ def main():
|
|||||||
for device in devices:
|
for device in devices:
|
||||||
response = delete(args.url, args.token, device["guid"], device["id"])
|
response = delete(args.url, args.token, device["guid"], device["id"])
|
||||||
print(response)
|
print(response)
|
||||||
|
elif args.command == "assign":
|
||||||
|
if "=" not in args.assign_to:
|
||||||
|
print("Invalid assign_to format, it must be <type>=<value>")
|
||||||
|
return
|
||||||
|
type, value = args.assign_to.split("=", 1)
|
||||||
|
for device in devices:
|
||||||
|
response = assign(
|
||||||
|
args.url, args.token, device["guid"], device["id"], type, value
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user