Skip to content

Commit 3adab38

Browse files
author
Fernando Ojeda
committed
Refactor shorts java file network gateway into a single file.
1 parent 9aaf615 commit 3adab38

File tree

1 file changed

+23
-70
lines changed

1 file changed

+23
-70
lines changed

content/python/virtual_guest.py.md

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: "Working with Virtual Guest"
2+
title: "More Virtual Guest Examples"
33
description: "A few examples on interacting with Virtual Guest"
44
date: "2020-07-09"
55
classes:
66
- "SoftLayer_Virtual_Guest"
77
- "SoftLayer_Account"
88
tags:
9-
- "virtualservers"
9+
- "vsi"
10+
- "VirtualGuest"
1011
---
1112

1213
### Create Virtual Server
@@ -18,10 +19,7 @@ This method is a simplified alternative to interacting with the ordering system
1819
import SoftLayer
1920
import json
2021

21-
USERNAME = 'set me'
22-
API_KEY = 'set me'
23-
24-
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
22+
client = SoftLayer.Client()
2523
virtualGuestService = client['SoftLayer_Virtual_Guest']
2624

2725
# The order template for the new virtual guest
@@ -37,16 +35,18 @@ order = {
3735
}
3836
}
3937
],
40-
"localDiskFlag": True,
38+
"hourlyBillingFlag": true,
39+
"localDiskFlag": false,
4140
"datacenter": {
42-
"name": "dal10"
41+
"name": "dal13"
4342
},
44-
"startCpus": 4,
4543
"dedicatedHost": {
4644
"id": 9301
4745
},
48-
"maxMemory": 8192,
49-
"operatingSystemReferenceCode": "UBUNTU_LATEST"
46+
"operatingSystemReferenceCode": "UBUNTU_LATEST",
47+
"supplementalCreateObjectOptions": {
48+
"flavorKeyName": "AC1_8X60X25"
49+
}
5050
}
5151

5252
try:
@@ -74,23 +74,21 @@ def create_vsi():
7474
datacenter = 'wdc07'
7575
domain = 'cde.services'
7676
os_code = 'UBUNTU_LATEST_64'
77-
local_disk = True
77+
local_disk = False
7878
hourly = True
7979
dedicated = False
8080
nic_speed = 1000
81-
disks = [100]
8281
private = False
8382
ssh_keys = [972047]
8483
public_security_groups = [43507]
8584
private_security_groups = [43511]
8685

8786
# server properties
8887
hostname = 'sgvsi'
89-
cpus = 2
90-
memory = 2048
88+
flavor = 'BL1_1X2X100'
9189

9290
result = vsi_mgr.create_instance(hostname=hostname, domain=domain,
93-
cpus=cpus, memory=memory, datacenter=datacenter,
91+
flavor=flavor, datacenter=datacenter,
9492
os_code=os_code, local_disk=local_disk,
9593
hourly=hourly, dedicated=dedicated,
9694
disks=disks, nic_speed=nic_speed, private=private,
@@ -112,9 +110,6 @@ import SoftLayer
112110
# For nice debug output:
113111
from pprint import pprint as pp
114112

115-
API_USERNAME = 'set me'
116-
API_KEY = 'set me'
117-
118113
# Set the server id that you wish to get details.
119114
# Call the getVirtualGuests method from SoftLayer_Account
120115
serverId = 35747489
@@ -125,10 +120,7 @@ mask = "mask[id, fullyQualifiedDomainName, operatingSystem[passwords], networkCo
125120
"category[name, id]]]]"
126121

127122
# Make a connection to the Virtual_Guest service.
128-
client = SoftLayer.create_client_from_env(
129-
username=API_USERNAME,
130-
api_key=API_KEY
131-
)
123+
client = SoftLayer.Client()
132124

133125
try:
134126
# Make the call to retrieve the server details.
@@ -191,11 +183,7 @@ vsiIp = "169.45.98.148"
191183
startDate = "2000-01-01"
192184
endDate = "2016-12-22"
193185

194-
USERNAME = 'set me'
195-
API_KEY = 'set me'
196-
197-
client = SoftLayer.Client(username=USERNAME,
198-
api_key=API_KEY)
186+
client = SoftLayer.Client()
199187
vsiService = client['SoftLayer_Virtual_Guest']
200188

201189
try:
@@ -224,11 +212,7 @@ vsiIp = "169.45.98.148"
224212
startDate = "2000-01-01"
225213
endDate = "2016-12-22"
226214

227-
USERNAME = 'set me'
228-
API_KEY = 'set me'
229-
230-
client = SoftLayer.Client(username=USERNAME,
231-
api_key=API_KEY)
215+
client = SoftLayer.Client()
232216
vsiService = client['SoftLayer_Virtual_Guest']
233217

234218
try:
@@ -252,17 +236,11 @@ Create a transaction to perform an OS reload.
252236
import SoftLayer
253237
from pprint import pprint as pp
254238

255-
API_USERNAME = 'set me'
256-
API_KEY = 'set me'
257-
258239
# Set the server id that you wish to reload.
259240
serverId = 35747489
260241

261242
# Create a SoftLayer Client.
262-
client = SoftLayer.create_client_from_env(
263-
username=API_USERNAME,
264-
api_key=API_KEY
265-
)
243+
client = SoftLayer.Client()
266244

267245
# Reload the Virtual Guest
268246
try:
@@ -282,16 +260,13 @@ except SoftLayer.SoftLayerAPIError as e:
282260
```python
283261
import SoftLayer
284262

285-
API_USERNAME = 'set me'
286-
API_KEY = 'set me'
287-
288263
# the virtual guest ID where you wish to add the tags
289264
virtualGuestID = 35747489
290265

291266
# the tags you wish to add
292267
tags = "tag1,tag2,tag3"
293268

294-
client = SoftLayer.create_client_from_env(username=API_USERNAME, api_key=API_KEY)
269+
client = SoftLayer.Client()
295270
virtualGuestService = client['SoftLayer_Virtual_Guest']
296271

297272
try:
@@ -315,15 +290,11 @@ The script retrieve all the VSIs which contain an arbitrary list of tags.
315290
import SoftLayer.API
316291
from pprint import pprint as pp
317292

318-
# Your SoftLayer API username.
319-
USERNAME = 'set me'
320-
API_KEY = 'set me'
321-
322293
# List of tags to look for
323294
tags = ["mytag1", "tag2"]
324295

325296
# Declare the API client
326-
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
297+
client = SoftLayer.Client()
327298
accountService = client['SoftLayer_Account']
328299

329300
# Declaring an object filter to get only the virtual servers which contain the tags that we are looking for
@@ -349,15 +320,8 @@ SoftLayer_Virtual_Guest API service and we set an object mask to get the informa
349320
```python
350321
import SoftLayer
351322

352-
"""
353-
Client configuration
354-
Your SoftLayer API username and key.
355-
"""
356-
USERNAME = 'set me'
357-
API_KEY = 'set me'
358-
359323
# Declaring the API client
360-
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
324+
client = SoftLayer.Client()
361325
accountService = client['SoftLayer_Account']
362326

363327
# Adding the object mask to the call to get the information about the user data.
@@ -382,19 +346,12 @@ It reboots a SoftLayer Virtual Guest
382346
import SoftLayer
383347
from pprint import pprint as pp
384348

385-
# Your SoftLayer API username and key.
386-
API_USERNAME = 'set me'
387-
API_KEY = 'set me'
388-
389349
# If you don't know your server id you can call getVirtualGuests() in the
390350
# SoftLayer_Account API service to get a list of Virtual Guests
391351
serverId = 35747489
392352

393353
# Create a connection to API service.
394-
client = SoftLayer.create_client_from_env(
395-
username=API_USERNAME,
396-
api_key=API_KEY
397-
)
354+
client = SoftLayer.Client()
398355

399356
# Reboot the Virtual Guest
400357
try:
@@ -416,15 +373,11 @@ method.
416373
```python
417374
import SoftLayer
418375

419-
# Your SoftLayer API username and key.
420-
API_USERNAME = 'set me'
421-
API_KEY = 'set me'
422-
423376
#Declare variables
424377
virtualGuestId = 35747489
425378

426379
# Declare the API client
427-
client = SoftLayer.create_client_from_env(username=API_USERNAME, api_key=API_KEY)
380+
client = SoftLayer.Client()
428381
virtualServer = client['SoftLayer_Virtual_Guest']
429382

430383
try:

0 commit comments

Comments
 (0)