1- Packet
2- ======
1+ # Packet
32
43A Python client for the Packet API.
54
65![ travis build status badge] ( https://travis-ci.org/packethost/packet-python.svg?branch=master " Build Status ")
76
8- Installation
9- ------------
7+ ## Table of Contents
8+
9+ * [ Installation] ( #installation )
10+ * [ Documentation] ( #documentation )
11+ * [ Authentication] ( #authentication )
12+ * [ Examples] ( #examples )
13+ * [ List Projects] ( #list-projects )
14+ * [ List Plans] ( #list-plans )
15+ * [ Creating a Device] ( #creating-a-device )
16+ * [ Checking the Status and Rebooting a Device] ( #checking-the-status-and-rebooting-a-device )
17+ * [ Listing all Devices Limiting to 50 per Page] ( #listing-all-devices-limiting-to-50-per-page )
18+ * [ Updating a Device] ( #updating-a-device )
19+ * [ Deleting a Device] ( #deleting-a-device )
20+ * [ Creating a Device Batch] ( #creating-a-device-batch )
21+ * [ Creating a Volume] ( #creating-a-volume )
22+ * [ Attaching and Detaching a Volume] ( #attaching-and-detaching-a-volume )
23+ * [ Creating and Restoring a Volume Snapshot] ( #creating-and-restoring-a-volume-snapshot )
24+ * [ Listing Project IP Addresses] ( #listing-project-ip-addresses )
25+ * [ Creating a Project for an Organization] ( #creating-a-project-for-an-organization )
26+ * [ Creating a VLAN] ( #creating-a-vlan )
27+ * [ Contributing] ( #contributing )
28+ * [ Copyright] ( #copyright )
29+ * [ Changes] ( #changes )
30+
31+ ## Installation
32+
1033The packet python api library can be installed using pip:
1134
1235 pip install packet-python
@@ -15,14 +38,23 @@ Package information available here:
1538
1639https://pypi.python.org/pypi/packet-python
1740
18- Documentation
19- -------------
41+ ## Documentation
42+
2043Full Packet API documenation is available here:
2144[ https://www.packet.net/developers/api/ ] ( https://www.packet.net/developers/api/ )
2245
23- Examples
24- --------
25- ### List projects
46+ ## Authentication
47+
48+ Provide your credentials when instantiating client:
49+
50+ ``` python
51+ import packet
52+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
53+ ```
54+
55+ ## Examples
56+
57+ ### List Projects
2658
2759``` python
2860import packet
@@ -33,7 +65,7 @@ for project in projects:
3365 print (project)
3466```
3567
36- ### List plans
68+ ### List Plans
3769
3870``` python
3971import packet
@@ -55,11 +87,11 @@ manager = packet.Manager(auth_token="yourapiauthtoken")
5587device = manager.create_device(project_id = ' project-id' ,
5688 hostname = ' node-name-of-your-choice' ,
5789 plan = ' baremetal_1' , facility = ' ewr1' ,
58- operating_system = ' ubuntu_14_04 ' )
90+ operating_system = ' ubuntu_18_04 ' )
5991print (device)
6092```
6193
62- ### Checking the status and rebooting a Device
94+ ### Checking the Status and Rebooting a Device
6395
6496``` python
6597import packet
@@ -70,7 +102,7 @@ print(device.state)
70102device.reboot()
71103```
72104
73- ### Listing all devices, limiting to 50 per page
105+ ### Listing all Devices Limiting to 50 per Page
74106
75107_ Packet API defaults to a limit of 10 per page_
76108
@@ -84,8 +116,138 @@ devices = manager.list_devices(project_id='project_id', params = params)
84116print (devices)
85117```
86118
87- Contributing
88- ------------
119+ ### Updating a Device
120+
121+ ``` python
122+ import packet
123+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
124+
125+ device = manager.get_device(' device-id' )
126+ device.hostname = " test02"
127+ device.description = " new description"
128+
129+ device.update()
130+ ```
131+
132+ ### Deleting a Device
133+
134+ ``` python
135+ import packet
136+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
137+
138+ device = manager.get_device(' device-id' )
139+ device.delete()
140+ ```
141+
142+ ### Creating a Device Batch
143+
144+ ``` python
145+ import packet
146+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
147+
148+ batch01 = packet.DeviceBatch({
149+ " hostname" : " batch01" ,
150+ " quantity" : 2 ,
151+ " facility" : " ams1" ,
152+ " operating_system" : " centos_7" ,
153+ " plan" : " baremetal_0" ,
154+ })
155+
156+ device_batch = manager.create_batch(project_id = " project_id" , params = [batch01])
157+ print (device_batch)
158+ ```
159+
160+ ### Creating a Volume
161+
162+ ``` python
163+ import packet
164+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
165+
166+ volume = manager.create_volume(project_id = " project-id" ,
167+ description = " volume description" ,
168+ plan = " storage_1" ,
169+ size = " 100" ,
170+ facility = " ewr1" ,
171+ snapshot_count = 7 ,
172+ snapshot_frequency = " 1day" )
173+ print (volume)
174+ ```
175+
176+ ### Attaching and Detaching a Volume
177+
178+ ``` python
179+ import packet
180+ import time
181+
182+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
183+ volume = manager.get_volume(" volume_id" )
184+
185+ volume.attach(" device_id" )
186+
187+ while True :
188+ if manager.get_device(" device_id" ).state == " active" :
189+ break
190+ time.sleep(2 )
191+
192+ volume.detach()
193+ ```
194+
195+ ## Creating and Restoring a Volume Snapshot
196+
197+ ``` python
198+ import packet
199+ import time
200+
201+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
202+
203+ volume = manager.get_volume(" volume_id" )
204+ volume.create_snapshot()
205+
206+ while True :
207+ if manager.get_volume(volume.id).state == " active" :
208+ break
209+ time.sleep(2 )
210+
211+ snapshots = manager.get_snapshots(volume.id)
212+ volume.restore(snapshots[0 ].timestamp)
213+ ```
214+
215+ ### Listing Project IP Addresses
216+
217+ ``` python
218+ import packet
219+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
220+
221+ ips = manager.list_project_ips(" project_id" )
222+ for ip in ips:
223+ print (ip.address)
224+ ```
225+
226+ ### Creating a Project for an Organization
227+
228+ ``` python
229+ import packet
230+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
231+
232+ project = manager.create_organization_project(
233+ org_id = " organization_id" ,
234+ name = " Integration Tests" ,
235+ customdata = {" tag" : " QA" }
236+ )
237+ print (project)
238+ ```
239+
240+ ### Creating a VLAN
241+
242+ ``` python
243+ import packet
244+ manager = packet.Manager(auth_token = " yourapiauthtoken" )
245+
246+ vlan = manager.create_vlan(project_id = " project_id" , facility = " ewr1" )
247+ print (vlan)
248+ ```
249+
250+ ## Contributing
89251
90252* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
91253* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -94,18 +256,15 @@ Contributing
94256* Commit and push until you are happy with your contribution.
95257* You can test your changes with the ` test/tests.sh ` script, which is what travis uses to check builds.
96258
97- Credits
98- -------
259+ ## Credits
99260
100261CargoCulted with much gratitude from:
101262https://github.com/koalalorenzo/python-digitalocean
102263
103- Copyright
104- ---------
264+ ## Copyright
105265
106266Copyright (c) 2017 Packet Host. See [ License] ( LICENSE.txt ) for further details.
107267
108- Changes
109- -------
268+ ## Changes
110269
111270See the [ Changelog] ( CHANGELOG.md ) for further details.
0 commit comments