Skip to content

Commit 7bf7716

Browse files
committed
add users from file sample
1 parent edba0f4 commit 7bf7716

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from cloudshell.api.cloudshell_api import CloudShellAPISession
2+
from dataclasses import dataclass
3+
4+
# cloudshell group to place users in
5+
TARGET_GROUP = "QA users"
6+
7+
# Initial password - pick something more secure than this :)
8+
DEFAULT_PASSWORD = "Quali123!"
9+
10+
# wheter users will be system admins or not
11+
IS_ADMINS = False
12+
13+
14+
@dataclass
15+
class User:
16+
email: str
17+
user_name: str
18+
19+
20+
api = CloudShellAPISession(host="localhost", username="admin", password="admin", domain="Global")
21+
22+
with open("user_emails.txt") as f:
23+
user_lines = [x.rstrip() for x in f.readlines()]
24+
user_emails = [x for x in user_lines if x]
25+
26+
users = []
27+
for email in user_emails:
28+
split = email.split("@")
29+
user = User(email=email, user_name=split[0])
30+
users.append(user)
31+
32+
for user in users:
33+
print(f"adding user: {user.user_name}...")
34+
35+
try:
36+
api.AddNewUser(username=user.user_name, email=user.email, password=DEFAULT_PASSWORD, isActive=True, isAdmin=IS_ADMINS)
37+
except Exception as e:
38+
print(f"issue creating user {user.user_name}. Skipping. Error: {str(e)}")
39+
else:
40+
print("user created")
41+
print("==========")
42+
43+
print("adding users to group...")
44+
user_names = [x.user_name for x in users]
45+
api.AddUsersToGroup(usernames=user_names, groupName=TARGET_GROUP)
46+
47+
print("Script Done!")
48+
49+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
QA_User.1@test.com
2+
QA_User.2@test.com
3+
QA_User.3@test.com
4+
QA_User.4@test.com
5+
QA_User.5@test.com
6+
7+

0 commit comments

Comments
 (0)