Skip to content

Commit c5b2543

Browse files
release notes and some security group things
1 parent 6cd4db8 commit c5b2543

24 files changed

Lines changed: 2949 additions & 1084 deletions

File tree

classes/softlayer_network_securitygroup/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,18 @@ <h3>python</h3>
101101
<ul>
102102

103103
<li>
104-
<a href="https://softlayer.github.io/python/createsecuritygroup/">Create a Security group</a>
105-
<div class="meta">Example for creating a Security Group.</div>
104+
<a href="https://softlayer.github.io/python/securitygroup_rule_ops/">Add, list, and remove security group rules</a>
105+
<div class="meta">Examples for adding, listing, and removing rules from security groups</div>
106+
</li>
107+
108+
<li>
109+
<a href="https://softlayer.github.io/python/securitygroup_ops/">Create, list, get, and delete security groups</a>
110+
<div class="meta">Examples for creating, listing, getting, and deleting security groups</div>
111+
</li>
112+
113+
<li>
114+
<a href="https://softlayer.github.io/python/securitygroup_vsis/">VSIs and security groups</a>
115+
<div class="meta">Examples for associating and disassociating VSIs with security groups</div>
106116
</li>
107117

108118
</ul>

classes/softlayer_network_securitygroup/index.xml

Lines changed: 300 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,306 @@
66
<language>en-US</language>
77
<author>Enthusiastic Hugo User</author>
88
<rights>Copyright (c) 2014, Enthusiastic Hugo User; all rights reserved.</rights>
9-
<updated>Mon, 02 Oct 2017 00:00:00 UTC</updated>
9+
<updated>Wed, 18 Oct 2017 00:00:00 UTC</updated>
10+
11+
<item>
12+
<title>Add, list, and remove security group rules</title>
13+
<link>https://softlayer.github.io/python/securitygroup_rule_ops/</link>
14+
<pubDate>Wed, 18 Oct 2017 00:00:00 UTC</pubDate>
15+
<author>Enthusiastic Hugo User</author>
16+
<guid>https://softlayer.github.io/python/securitygroup_rule_ops/</guid>
17+
<description>
18+
19+
&lt;h2 id=&#34;adding-a-rule-to-a-security-group&#34;&gt;Adding a rule to a security group&lt;/h2&gt;
20+
21+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
22+
# For nice debug output
23+
from pprint import pprint as pp
24+
25+
# Create a client for use with the NetworkManager
26+
client = SoftLayer.Client()
27+
net_mgr = SoftLayer.NetworkManager(client)
28+
29+
sg_id = 123045
30+
direction = &#39;ingress&#39;
31+
ethertype = &#39;IPv4&#39;
32+
remote_ip = &#39;169.148.34.0/24&#39;
33+
protocol = &#39;tcp&#39;
34+
port_min = 22
35+
port_max = 22
36+
try:
37+
result = net_mgr.add_securitygroup_rule(sg_id,
38+
direction=direction,
39+
ethertype=ethertype,
40+
remote_ip=remote_ip,
41+
protocol=protocol,
42+
port_min=port_min,
43+
port_max=port_max)
44+
pp(result)
45+
except SoftLayer.SoftLayerAPIError as e:
46+
pp(&#39;Failed... Unable to add a rule to the security group: faultCode=%s, faultString=%s&#39;
47+
% (e.faultCode, e.faultString))
48+
&lt;/code&gt;&lt;/pre&gt;
49+
50+
&lt;h2 id=&#34;listing-rules-in-a-security-group&#34;&gt;Listing rules in a security group&lt;/h2&gt;
51+
52+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
53+
# For nice debug output
54+
from pprint import pprint as pp
55+
56+
# Create a client for use with the NetworkManager
57+
client = SoftLayer.Client()
58+
net_mgr = SoftLayer.NetworkManager(client)
59+
60+
sg_id = 123045
61+
try:
62+
result = net_mgr.list_securitygroup_rules(sg_id)
63+
pp(result)
64+
except SoftLayer.SoftLayerAPIError as e:
65+
pp(&#39;Failed... Unable to list rules in the security group: faultCode=%s, faultString=%s&#39;
66+
% (e.faultCode, e.faultString))
67+
&lt;/code&gt;&lt;/pre&gt;
68+
69+
&lt;h2 id=&#34;removing-a-rule-from-a-security-group&#34;&gt;Removing a rule from a security group&lt;/h2&gt;
70+
71+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
72+
# For nice debug output
73+
from pprint import pprint as pp
74+
75+
# Create a client for use with the NetworkManager
76+
client = SoftLayer.Client()
77+
net_mgr = SoftLayer.NetworkManager(client)
78+
79+
sg_id = 123045
80+
rule_id = 475879
81+
try:
82+
result = net_mgr.remove_securitygroup_rule(sg_id, rule_id)
83+
pp(result)
84+
except SoftLayer.SoftLayerAPIError as e:
85+
pp(&#39;Failed... Unable to remove rule from the security group: faultCode=%s, faultString=%s&#39;
86+
% (e.faultCode, e.faultString))
87+
&lt;/code&gt;&lt;/pre&gt;
88+
89+
&lt;h2 id=&#34;remove-all-rules-from-a-security-group&#34;&gt;Remove all rules from a security group&lt;/h2&gt;
90+
91+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
92+
# For nice debug output
93+
from pprint import pprint as pp
94+
95+
# Create a client for use with the NetworkManager
96+
client = SoftLayer.Client()
97+
net_mgr = SoftLayer.NetworkManager(client)
98+
99+
sg_id = 123045
100+
try:
101+
rules = net_mgr.list_securitygroup_rules(sg_id)
102+
rules = [rule[&#39;id&#39;] for rule in rules]
103+
result = net_mgr.remove_securitygroup_rules(sg_id, rules)
104+
pp(result)
105+
except SoftLayer.SoftLayerAPIError as e:
106+
pp(&#39;Failed... Unable to remove rules from the security group: faultCode=%s, faultString=%s&#39;
107+
% (e.faultCode, e.faultString))
108+
&lt;/code&gt;&lt;/pre&gt;
109+
</description>
110+
</item>
111+
112+
<item>
113+
<title>Create, list, get, and delete security groups</title>
114+
<link>https://softlayer.github.io/python/securitygroup_ops/</link>
115+
<pubDate>Wed, 18 Oct 2017 00:00:00 UTC</pubDate>
116+
<author>Enthusiastic Hugo User</author>
117+
<guid>https://softlayer.github.io/python/securitygroup_ops/</guid>
118+
<description>
119+
120+
&lt;h2 id=&#34;creating-a-security-group&#34;&gt;Creating a security group&lt;/h2&gt;
121+
122+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
123+
# For nice debug output
124+
from pprint import pprint as pp
125+
126+
# Create a client for use with the NetworkManager
127+
client = SoftLayer.Client()
128+
net_mgr = SoftLayer.NetworkManager(client)
129+
130+
name = &#39;pythonCreatedGroupExample&#39;
131+
description = &#39;Security Group created via python&#39;
132+
try:
133+
result = net_mgr.create_securitygroup(name=name, description=description)
134+
pp(result)
135+
except SoftLayer.SoftLayerAPIError as e:
136+
pp(&#39;Failed... Unable to create a new security group: faultCode=%s, faultString=%s&#39;
137+
% (e.faultCode, e.faultString))
138+
&lt;/code&gt;&lt;/pre&gt;
139+
140+
&lt;h2 id=&#34;deleting-a-security-group&#34;&gt;Deleting a security group&lt;/h2&gt;
141+
142+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
143+
# For nice debug output
144+
from pprint import pprint as pp
145+
146+
# Create a client for use with the NetworkManager
147+
client = SoftLayer.Client()
148+
net_mgr = SoftLayer.NetworkManager(client)
149+
150+
sg_id = 12045
151+
try:
152+
result = net_mgr.delete_securitygroup(sg_id)
153+
pp(result)
154+
except SoftLayer.SoftLayerAPIError as e:
155+
pp(&#39;Failed... Unable to delete security group: faultCode=%s, faultString=%s&#39;
156+
% (e.faultCode, e.faultString))
157+
&lt;/code&gt;&lt;/pre&gt;
158+
159+
&lt;h2 id=&#34;getting-a-security-group&#34;&gt;Getting a security group&lt;/h2&gt;
160+
161+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
162+
# For nice debug output
163+
from pprint import pprint as pp
164+
165+
# Create a client for use with the NetworkManager
166+
client = SoftLayer.Client()
167+
net_mgr = SoftLayer.NetworkManager(client)
168+
169+
sg_id = 12045
170+
try:
171+
result = net_mgr.get_securitygroup(sg_id)
172+
pp(result)
173+
except SoftLayer.SoftLayerAPIError as e:
174+
pp(&#39;Failed... Unable to get security group: faultCode=%s, faultString=%s&#39;
175+
% (e.faultCode, e.faultString))
176+
&lt;/code&gt;&lt;/pre&gt;
177+
178+
&lt;h2 id=&#34;list-all-security-groups-in-account&#34;&gt;List all security groups in account&lt;/h2&gt;
179+
180+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
181+
# For nice debug output
182+
from pprint import pprint as pp
183+
184+
# Create a client for use with the NetworkManager
185+
client = SoftLayer.Client()
186+
net_mgr = SoftLayer.NetworkManager(client)
187+
188+
result = net_mgr.list_securitygroups()
189+
pp(result)
190+
&lt;/code&gt;&lt;/pre&gt;
191+
</description>
192+
</item>
193+
194+
<item>
195+
<title>VSIs and security groups</title>
196+
<link>https://softlayer.github.io/python/securitygroup_vsis/</link>
197+
<pubDate>Wed, 18 Oct 2017 00:00:00 UTC</pubDate>
198+
<author>Enthusiastic Hugo User</author>
199+
<guid>https://softlayer.github.io/python/securitygroup_vsis/</guid>
200+
<description>
201+
202+
&lt;h2 id=&#34;creating-a-vsi-with-security-groups&#34;&gt;Creating a VSI with security groups&lt;/h2&gt;
203+
204+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
205+
# For nice debug output
206+
from pprint import pprint as pp
207+
208+
# Create a client for use with the VSManager
209+
client = SoftLayer.Client()
210+
vs_mgr = SoftLayer.VSManager(client)
211+
212+
http_sg_id = 384757
213+
ssh_sg_id = 576973
214+
215+
# Allow only HTTP on the public interface of the VSI
216+
public_groups = [http_sg_id]
217+
218+
# Allow HTTP and SSH on the private interface of the VSI
219+
private_groups = [http_sg_id, ssh_sg_id]
220+
221+
# If we didn&#39;t want to set any security groups on an interface
222+
# (which allows all traffic), we don&#39;t set the associated
223+
# creation kwarg
224+
225+
create_kwargs = {
226+
&#39;hostname&#39;: &#39;sg-vsi&#39;,
227+
&#39;domain&#39;: &#39;mycompany.com&#39;,
228+
&#39;os_code&#39;: &#39;UBUNTU_LATEST_64&#39;,
229+
&#39;datacenter&#39;: &#39;dal13&#39;,
230+
&#39;cpus&#39;: 1,
231+
&#39;memory&#39;: 1024,
232+
&#39;hourly&#39;: True,
233+
&#39;disks&#39;: (&#39;100&#39;,),
234+
&#39;public_security_groups&#39;: public_groups,
235+
&#39;private_security_groups&#39;: private_groups,
236+
}
237+
238+
try:
239+
vsi = vs_mgr.create_instance(**create_kwargs)
240+
pp(vsi)
241+
except SoftLayer.SoftLayerAPIError as e:
242+
pp(&#39;Failed... Unable to create VSI with security group: faultCode=%s, faultString=%s&#39;
243+
% (e.faultCode, e.faultString))
244+
&lt;/code&gt;&lt;/pre&gt;
245+
246+
&lt;h2 id=&#34;attach-an-existing-vsi-to-security-groups&#34;&gt;Attach an existing VSI to security groups&lt;/h2&gt;
247+
248+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
249+
# For nice debug output
250+
from pprint import pprint as pp
251+
252+
# Create a client for use with the NetworkManager and VSManager
253+
client = SoftLayer.Client()
254+
net_mgr = SoftLayer.NetworkManager(client)
255+
vs_mgr = SoftLayer.VSManager(client)
256+
257+
http_sg_id = 384757
258+
vsi_id = 4018735
259+
private_interface = False
260+
port_number = 0 if private_interface else 1
261+
network_component_mask = &#39;networkComponents[id, port]&#39;
262+
263+
try:
264+
vsi_components = vs_mgr.get_instance(vsi_id, mask=network_component_mask)
265+
component_to_attach = [comp for comp in vsi_components[&#39;networkComponents&#39;]
266+
if comp[&#39;port&#39;] == port_number][0]
267+
result = net_mgr.attach_securitygroup_component(http_sg_id,
268+
component_to_attach[&#39;id&#39;])
269+
pp(result)
270+
271+
# If this is the first time the server is being associated with security groups,
272+
# a reboot is required for the security group to take effect on the VSI
273+
client[&#39;Virtual_Guest&#39;].rebootSoft(id=vsi_id)
274+
except SoftLayer.SoftLayerAPIError as e:
275+
pp(&#39;Failed... Unable to associate VSI with security group: faultCode=%s, faultString=%s&#39;
276+
% (e.faultCode, e.faultString))
277+
&lt;/code&gt;&lt;/pre&gt;
278+
279+
&lt;h2 id=&#34;detach-a-vsi-from-a-security-group&#34;&gt;Detach a VSI from a security group&lt;/h2&gt;
280+
281+
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
282+
# For nice debug output
283+
from pprint import pprint as pp
284+
285+
# Create a client for use with the NetworkManager and VSManager
286+
client = SoftLayer.Client()
287+
net_mgr = SoftLayer.NetworkManager(client)
288+
vs_mgr = SoftLayer.VSManager(client)
289+
290+
http_sg_id = 384757
291+
vsi_id = 4018735
292+
private_interface = False
293+
port_number = 0 if private_interface else 1
294+
network_component_mask = &#39;networkComponents[id, port]&#39;
295+
296+
try:
297+
vsi_components = vs_mgr.get_instance(vsi_id, mask=network_component_mask)
298+
component_to_detach = [comp for comp in vsi_components[&#39;networkComponents&#39;]
299+
if comp[&#39;port&#39;] == port_number][0]
300+
net_mgr.detach_securitygroup_component(http_sg_id,
301+
component_to_detach[&#39;id&#39;])
302+
303+
except SoftLayer.SoftLayerAPIError as e:
304+
pp(&#39;Failed... Unable to disassociate VSI with security group: faultCode=%s, faultString=%s&#39;
305+
% (e.faultCode, e.faultString))
306+
&lt;/code&gt;&lt;/pre&gt;
307+
</description>
308+
</item>
10309

11310
<item>
12311
<title>Add, get, edit and remove Security Group rules</title>
@@ -352,37 +651,6 @@ secGroupId = 70501
352651

353652
getAll = client[&#39;SoftLayer_Network_SecurityGroup&#39;].object_with_id(secGroupId).getAllObjects
354653
pp getAll
355-
&lt;/code&gt;&lt;/pre&gt;
356-
</description>
357-
</item>
358-
359-
<item>
360-
<title>Create a Security group</title>
361-
<link>https://softlayer.github.io/python/createsecuritygroup/</link>
362-
<pubDate>Tue, 20 Jun 2017 00:00:00 UTC</pubDate>
363-
<author>Enthusiastic Hugo User</author>
364-
<guid>https://softlayer.github.io/python/createsecuritygroup/</guid>
365-
<description>
366-
367-
&lt;h2 id=&#34;creating-a-security-group&#34;&gt;Creating a Security Group&lt;/h2&gt;
368-
369-
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import SoftLayer
370-
# For nice debug output:
371-
from pprint import pprint as pp
372-
# Create an object template to create the item.
373-
objectTemplate = {
374-
&#39;accountId&#39;: YOUR_ACCOUNT_ID,
375-
&#39;name&#39;: &#39;pythonCreatedGroupExample&#39;,
376-
&#39;description&#39;: &#39;Sec Group created via python&#39;
377-
}
378-
client = SoftLayer.Client()
379-
try:
380-
result = client[&#39;SoftLayer_Network_SecurityGroup&#39;].createObjects([objectTemplate])
381-
pp(result)
382-
except SoftLayer.SoftLayerAPIError as e:
383-
pp(&#39;Failed ... Unable to create a new SecGroup faultCode=%s, faultString=%s&#39;
384-
% (e.faultCode, e.faultString))
385-
386654
&lt;/code&gt;&lt;/pre&gt;
387655
</description>
388656
</item>

classes/softlayer_virtual_guest/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ <h3>php</h3>
145145
<h3>python</h3>
146146
<ul>
147147

148+
<li>
149+
<a href="https://softlayer.github.io/python/createvsiwithsecgroup/">Create a new virtual server and attach Security Groups</a>
150+
<div class="meta">Creates a new virtual server (VSI) aand attach the public and private interfaces to respective Security Groups.</div>
151+
</li>
152+
148153
<li>
149154
<a href="https://softlayer.github.io/python/migratededicatedinstance/">Migrate a VSI between dedicated hosts</a>
150155
<div class="meta">Migrate a Dedicated Host instance to another Dedicated Host. You can migrate your dedicated host instances from one host to another within the same POD.</div>

0 commit comments

Comments
 (0)