forked from F5Networks/f5-common-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_example.py
More file actions
72 lines (53 loc) · 2.06 KB
/
code_example.py
File metadata and controls
72 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from f5.bigip import ManagementRoot
# Connect to the BigIP and configure the basic objects
mgmt = ManagementRoot('10.190.7.161', 'admin', 'admin')
ltm = mgmt.tm.ltm
pools = mgmt.tm.ltm.pools
pool = mgmt.tm.ltm.pools.pool
# Create a pool
pool1 = mgmt.tm.ltm.pools.pool.create(name='pool1', partition='Common')
# Define a pool object and load an existing pool
pool_obj = mgmt.tm.ltm.pools.pool
pool_1 = pool_obj.load(partition='Common', name='pool1')
# We can also skip creating the object and load the pool directly
pool_2 = mgmt.tm.ltm.pools.pool.load(partition='Common', name='pool1')
# Make sure 1 and 2 have the same names and generation
assert pool_1.name == pool_2.name
assert pool_1.generation == pool_2.generation
print pool_1.name
print pool_2.name
print pool_1.generation
print pool_2.generation
# Update the pool description
pool_1.description = "This is my first pool"
pool_1.update()
# Check the updated description
print pool_1.description
# Since we haven't refreshed pool_2 it shouldn't match pool_1 any more
print pool_2.description
# Refresh pool_2 and check that is now equal
pool_2.refresh()
print pool_2.description
print pool_1.generation
print pool_2.generation
# Create members on pool_1
members = pool_1.members_s
member = pool_1.members_s.members
m1 = pool_1.members_s.members.create(partition='Common', name='m1:80')
m2 = pool_1.members_s.members.create(partition='Common', name='m2:80')
# load the pool members
m1 = pool_1.members_s.members.load(partition='Common', name='m1:80')
m2 = pool_1.members_s.members.load(partition='Common', name='m2:80')
# Get all of the pool members for pool_1 and print their names
for member in members:
print member.name
# Delete our pool member m1
m1.delete()
# Make sure it is gone
if pool_1.members_s.members.exists(partition='Common', name='m1:80'):
raise Exception("Object should have been deleted")
# We are done with this pool so remove it from BIG-IP®
pool_1.delete()
# Make sure it is gone
if mgmt_rt.tm.ltm.pools.pool.exists(partition='Common', name='mypool'):
raise Exception("Object should have been deleted")