Is there a way to check if SSL vpn is enabled for a softlayer ID using Python API? I have to retrieve all users with VPN access.
Asked
Active
Viewed 317 times
1 Answers
1
“Currently there are two types of VPN connection to the private network, these are sslVpnAllowedFlag and pptpVpnAllowedFlag properties which you may retrieve by using object Mask along with the script, these properties will let you check if their access is allowed or not.
Here an example to get the users who have access to VPN
""""
Get Users
This script retrieves a list of all account´s users.
See below for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getUsers
https://sldn.softlayer.com/article/Python#Using_Object_Masks
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. sldn@softlayer.com
"""""
import SoftLayer
from pprint import pprint as pp
# Valid Softlayer username
USERNAME = 'set-me'
# Valid Softlayer apiKey token, Generate one for you or your users, or view yours at https://control.softlayer.com/account/users
API_KEY = 'set-me'
client = SoftLayer.create_client_from_env(username=USERNAME,
api_key=API_KEY)
userCustomerService = client['SoftLayer_User_Customer']
objectMask='accountId, id, sslVpnAllowedFlag, username, firstName, lastName'
#add pptpVpnAllowedFlag to retrieve boolean value for the
# other VPN connection type.
objectFilter={"users":{"sslVpnAllowedFlag":{"operation":"1"}}}
#change values between 1=True and 0=False as required, this will retrieve only the users with a True value for a SSL VPN private network connection.
try:
""""
getUsers() retrieves a list of all account's users.
"""""
result = accountService.getUsers(mask=objectMask, filter=objectFilter)
pp(result)
except SoftLayer.SoftLayerAPIError as e:
""""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""""
print("Unable to retrieve all account´s users information, please refer to following error: . %s %s " %
(e.faultCode, e.faultString))
Here an example to get an user and his VPN access:
> """" Get Object
>
> This script retrieves the SoftLayer_User_Customer object whose ID
> number corresponds to the ID number of a user customer.
>
> See below for more details.
>
> Important manual pages:
> http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer
> http://sldn.softlayer.com/reference/datatypes/SoftLayer_User_Customer
> http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/getObject
> https://sldn.softlayer.com/article/Python#Using_Object_Masks
>
> License: http://sldn.softlayer.com/article/License Author: SoftLayer
> Technologies, Inc. sldn@softlayer.com """""
>
> import SoftLayer from pprint import pprint as pp
>
> # Valid Softlayer username USERNAME = 'set-me'
> # Valid Softlayer apiKey token, Generate one for you or your users, or view yours at https://control.softlayer.com/account/users API_KEY =
> 'set-me'
>
> userCustomerId = 6724753 # Change this value for specific user id.
>
> client = SoftLayer.create_client_from_env(username=USERNAME,
> api_key=API_KEY)
>
>
> userCustomerService = client['SoftLayer_User_Customer']
>
> objectMask='sslVpnAllowedFlag' #add pptpVpnAllowedFlag to retrieve
> boolean value for the
> # other VPN connection type.
>
> try:
> """"
> getObject() retrieves the information of a specific user by its user customer ID number.
> This will retrieve the SoftLayer_User_Customer object.
> """""
> result = userCustomerService.getObject(id=userCustomerId, mask=objectMask)
>
> pp(result)
>
> except SoftLayer.SoftLayerAPIError as e:
> """"
> If there was an error returned from the SoftLayer API then bomb out with the
> error message.
> """""
> print("Unable to retrieve softlayer user information, please refer to following error: . %s %s " %
> (e.faultCode, e.faultString))

Nelson Raul Cabero Mendoza
- 4,386
- 1
- 14
- 19