|
| 1 | +import os |
| 2 | + |
| 3 | +from profitbricks.client import ProfitBricksService, Group, User |
| 4 | + |
| 5 | +# Instantiate ProfitBricks connection |
| 6 | +client = ProfitBricksService( |
| 7 | + username=os.getenv('PROFITBRICKS_USERNAME'), |
| 8 | + password=os.getenv('PROFITBRICKS_PASSWORD')) |
| 9 | + |
| 10 | +"""Create a group |
| 11 | +""" |
| 12 | +request = Group( |
| 13 | + name='demo-group', |
| 14 | + create_datacenter=True, |
| 15 | + create_snapshot=False, |
| 16 | + reserve_ip=True, |
| 17 | + access_activity_log=False) |
| 18 | + |
| 19 | +group = client.create_group(request) |
| 20 | + |
| 21 | +"""List groups |
| 22 | +""" |
| 23 | +groups = client.list_groups() |
| 24 | + |
| 25 | +"""Create a user |
| 26 | +""" |
| 27 | +user_request = User( |
| 28 | + firstname='John', |
| 29 | + lastname='Doe', |
| 30 | + email='demo-user@example.com', |
| 31 | + password='SecretPassword123', |
| 32 | + administrator=True, |
| 33 | + force_sec_auth=False) |
| 34 | + |
| 35 | +user = client.create_user(user_request) |
| 36 | + |
| 37 | +"""List users |
| 38 | +""" |
| 39 | +users = client.list_users() |
| 40 | + |
| 41 | +"""Add user to group |
| 42 | +""" |
| 43 | +# gu = client.add_group_user(group_id=group['id'], user_id=user['id']) |
| 44 | +# print json.dumps(gu, indent=4) |
| 45 | + |
| 46 | +"""List group users |
| 47 | +""" |
| 48 | +gus = client.list_group_users(group_id=group['id']) |
| 49 | + |
| 50 | +"""Delete group |
| 51 | +""" |
| 52 | +response = client.delete_group(group['id']) |
| 53 | + |
| 54 | +"""Delete user |
| 55 | +""" |
| 56 | +response = client.delete_user(user['id']) |
| 57 | + |
| 58 | +"""List all resources |
| 59 | +""" |
| 60 | +# listing all resources under an admin user may take a while |
| 61 | +resources = client.list_resources() |
| 62 | + |
| 63 | +"""List ipblock resources |
| 64 | +""" |
| 65 | +ipblock_resources = client.list_resources(resource_type='ipblock') |
0 commit comments