Skip to content

Instantly share code, notes, and snippets.

@underscorephil
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underscorephil/dc3f9c4390ae9ad723c3 to your computer and use it in GitHub Desktop.
Save underscorephil/dc3f9c4390ae9ad723c3 to your computer and use it in GitHub Desktop.
# So we can talk to the SoftLayer API:
import SoftLayer.API
# For nice debug output:
from pprint import pprint as pp
def create_user(username):
password = 'SL<3sKL!'
user_template = {
'username': username,
'firstName': '_phil',
'lastName': 'jackson',
'email': 'pjackson@softlayer.com',
'companyName': 'SoftLayer',
'address1': '315 Capitol Street',
'city': 'Houston',
'country': 'US',
'postalCode': 'TX 77002',
'userStatusId': 1001,
'timezoneId': 107
}
created_user = client['User_Customer'].createObject(
user_template,
password,
password)
return created_user
def get_permissions(_id):
permissions = client['User_Customer'].getPermissions(id=_id)
return permissions
def set_permissions(_id, permissions):
return client['User_Customer'].addBulkPortalPermission(
permissions, id=_id)
def list_users():
from prettytable import PrettyTable
table = PrettyTable(['Username', 'Password', 'ID'])
users = client['Account'].getUsers()
for user in users:
if 'kl-lab' not in user['username']:
continue
else:
table.add_row([user['username'], 'SL<3sKL! ', user['id']])
print table
exit()
def fix_permissions(user):
permissions = get_permissions(template_user_id)
t = user['id']
set_permissions(user['id'], permissions)
client['User_Customer'].removeAllVirtualAccessForThisUser(id=t)
client['User_Customer'].removeAllHardwareAccessForThisUser(id=t)
client['User_Customer'].addApiAuthenticationKey(id=t)
if __name__ == "__main__":
import argparse
argsparse = argparse.ArgumentParser(description='Number of users')
argsparse.add_argument('--num-users', dest='num_users', type=int,
help='Number of users to provision.')
argsparse.add_argument('--list', action='store_true',
help='List lab users', default=False)
argsparse.add_argument('--offset', dest="offset", type=int,
default=1, help='Username offset')
args = argsparse.parse_args()
template_user_id = 0000 # Takes copies permissions from this user
api_username = ''
api_key = ''
client = SoftLayer.Client(
username=api_username,
api_key=api_key,
)
if args.list is True:
list_users()
start_user_num = args.offset
for i in range(args.num_users):
target_username = 'kl-lab-%s' % (start_user_num)
new_user = create_user(target_username)
fix_permissions(new_user)
start_user_num = start_user_num + 1
print "Created user: %s" % (target_username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment