Skip to content

Commit

Permalink
Adding tests and documentation to firewall rules/anti affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
jadunham1 authored and tonybaloney committed Mar 26, 2016
1 parent a88cd53 commit 02ce76d
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 12 deletions.
5 changes: 3 additions & 2 deletions libcloud/common/dimensiondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ def paginated_request_with_orgId_api_2(self, action, params=None, data='',

while paged_resp.get('pageCount') >= paged_resp.get('pageSize'):
params['pageNumber'] = int(paged_resp.get('pageNumber')) + 1
paged_resp = self._list_nodes_single_page(action, params, data,
headers, method).object
paged_resp = self.request_with_orgId_api_2(action, params,
data, headers,
method).object
yield paged_resp

def get_resource_path_api_1(self):
Expand Down
60 changes: 52 additions & 8 deletions libcloud/compute/drivers/dimensiondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ def ex_update_node(self, node, name=None, description=None,
return response_code in ['IN_PROGRESS', 'SUCCESS']

def ex_create_anti_affinity_rule(self, node_list):
"""
Create an anti affinity rule given a list of nodes
Anti affinity rules ensure that servers will not reside
on the same VMware ESX host
:param node_list: The list of nodes to create a rule for
:type node_list: ``list`` of :class:`Node` or
``list`` of ``str``
:rtype: ``bool``
"""
if not isinstance(node_list, (list, tuple)):
raise TypeError("Node list must be a list or a tuple.")
anti_affinity_xml_request = ET.Element('NewAntiAffinityRule',
Expand All @@ -703,6 +714,15 @@ def ex_create_anti_affinity_rule(self, node_list):
return response_code in ['IN_PROGRESS', 'SUCCESS']

def ex_delete_anti_affinity_rule(self, anti_affinity_rule):
"""
Remove anti affinity rule
:param anti_affinity_rule: The anti affinity rule to delete
:type anti_affinity_rule: :class:`DimensionDataAntiAffinityRule` or
``str``
:rtype: ``bool``
"""
rule_id = self._anti_affinity_rule_to_anti_affinity_rule_id(
anti_affinity_rule)
result = self.connection.request_with_orgId_api_1(
Expand All @@ -712,10 +732,34 @@ def ex_delete_anti_affinity_rule(self, anti_affinity_rule):
return response_code in ['IN_PROGRESS', 'SUCCESS']

def ex_list_anti_affinity_rules(self, network=None, network_domain=None,
node=None, ex_filter_id=None,
ex_filter_state=None,
return_generator=False):
node=None, filter_id=None,
filter_state=None):
"""
List anti affinity rules for a network, network domain, or node
:param network: The network to list anti affinity rules for
One of network, network_domain, or node is required
:type network: :class:`DimensionDataNetwork` or ``str``
:param network_domain: The network domain to list anti affinity rules
One of network, network_domain,
or node is required
:type network_domain: :class:`DimensionDataNetworkDomain` or ``str``
:param node: The node to list anti affinity rules for
One of network, netwok_domain, or node is required
:type node: :class:`Node` or ``str``
:param filter_id: This will allow you to filter the rules
by this node id
:type filter_id: ``str``
:type filter_state: This will allow you to filter rules by
node state (i.e. NORMAL)
:type filter_state: ``str``
:rtype: ``list`` of :class:`DimensionDataAntiAffinityRule`
"""
not_none_arguments = [key
for key in (network, network_domain, node)
if key is not None]
Expand All @@ -732,11 +776,11 @@ def ex_list_anti_affinity_rules(self, network=None, network_domain=None,
self._network_to_network_id(network)
if node is not None:
params['serverId'] = \
self._node_to_node_id(network_domain)
if ex_filter_id is not None:
params['id'] = ex_filter_id
if ex_filter_state is not None:
params['state'] = ex_filter_state
self._node_to_node_id(node)
if filter_id is not None:
params['id'] = filter_id
if filter_state is not None:
params['state'] = filter_state

paged_result = self.connection.paginated_request_with_orgId_api_2(
'server/antiAffinityRule',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,60 @@
<ipVersion>IPV6</ipVersion>
<protocol>TCP</protocol>
<source>
<ip address="2607:f480:111:1336:6503:544c:74a6:3a28"/>
<ip address="2607:f480:111:1336:6503:544c:74a6:3a28"/>
</source>
<destination>
<ip address="ANY"/>
</destination>
<enabled>true</enabled>
<state>NORMAL</state>
</firewallRule>
<firewallRule id="ce250bd3-0e45-4c13-a6d2-74e0657ef699" datacenterId="NA9" ruleType="CLIENT_RULE">
<networkDomainId>423c4386-87b4-43c4-9604-88ae237bfc7f</networkDomainId>
<name>RULE_WITH_SOURCE_AND_DEST_IP_ONLY</name>
<action>ACCEPT_DECISIVELY</action>
<ipVersion>IPV4</ipVersion>
<protocol>TCP</protocol>
<source>
<ip address="10.10.10.15"/>
</source>
<destination>
<ip address="10.10.10.14"/>
</destination>
<enabled>true</enabled>
<state>NORMAL</state>
</firewallRule>
<firewallRule id="ce250bd3-0e45-4c13-a6d2-74e0657ef699" datacenterId="NA9" ruleType="CLIENT_RULE">
<networkDomainId>423c4386-87b4-43c4-9604-88ae237bfc7f</networkDomainId>
<name>RULE_WITH_DEST_IP_NO_PORT</name>
<action>ACCEPT_DECISIVELY</action>
<ipVersion>IPV4</ipVersion>
<protocol>TCP</protocol>
<source>
<ip address="10.10.10.15"/>
</source>
<destination>
<ip address="10.10.10.14"/>
<port begin="40000" end="40005"/>
</destination>
<enabled>true</enabled>
<state>NORMAL</state>
</firewallRule>
<firewallRule id="ce250bd3-0e45-4c13-a6d2-74e0657ef700" datacenterId="NA9" ruleType="CLIENT_RULE">
<networkDomainId>423c4386-87b4-43c4-9604-88ae237bfc7f</networkDomainId>
<name>RULE_WITH_SOURCE_AND_DEST</name>
<action>ACCEPT_DECISIVELY</action>
<ipVersion>IPV4</ipVersion>
<protocol>TCP</protocol>
<source>
<ip address="10.10.10.0" prefixSize="24"/>
<port begin="40000" end="40005"/>
</source>
<destination>
<ip address="10.10.10.0" prefixSize="24"/>
<port begin="40000"/>
</destination>
<enabled>true</enabled>
<state>NORMAL</state>
</firewallRule>
</firewallRules>
</firewallRules>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<antiAffinityRules xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="2" totalCount="2" pageSize="250">
<antiAffinityRule id="07e3621a-a920-4a9a-943c-d8021f27f418" state="NORMAL" created="2016-03-24T00:03:27.000Z" datacenterId="NA9">
<serverSummary id="22f3544a-c874-4930-a31c-e9e513e51114">
<name>ansible-test-image-rhel6</name>
<description>my new node</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="aafffb27-f16b-4757-9b63-ef7d8acd9c7f" privateIpv4="172.16.1.8" ipv6="2607:f480:111:1423:1b57:e47a:c212:257d" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/> </networkInfo>
</networkingDetails>
</serverSummary>
<serverSummary id="5718d174-31d4-4d49-b1c6-fcb0d782f233">
<name>ansible-custom-image-test-UAT</name>
<description>my new node</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="b359cea3-4452-46fe-b30b-b3ce839cde9b" privateIpv4="172.16.1.9" ipv6="2607:f480:111:1423:7fa7:9a9b:ecb9:882e" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
</antiAffinityRule>
<antiAffinityRule id="5e10b1ab-68f2-4a8b-a49c-d88d623db665" state="NORMAL" created="2016-03-24T00:07:39.000Z" datacenterId="NA9">
<serverSummary id="9f8b5428-bac3-4cf9-adda-62f57fb38671">
<name>rhel-ansible-full-test</name>
<description>RHEL Ansible Test</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="e081e784-5768-472c-b7f3-353e1646edc8" privateIpv4="172.16.1.15" ipv6="2607:f480:111:1423:70c9:9216:f7bf:dcf6" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
<serverSummary id="feee5cd2-d83b-4b80-913d-0bf26c838a33">
<name>rhel-ansible-full-test</name>
<description>RHEL Ansible Test</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="3278f833-9535-405c-91b8-0a0470f58aae" privateIpv4="172.16.1.17" ipv6="2607:f480:111:1423:3081:71a8:4c52:a8a" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
</antiAffinityRule>
</antiAffinityRules>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<antiAffinityRules xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="2" totalCount="2" pageSize="2">
<antiAffinityRule id="07e3621a-a920-4a9a-943c-d8021f27f418" state="NORMAL" created="2016-03-24T00:03:27.000Z" datacenterId="NA9">
<serverSummary id="22f3544a-c874-4930-a31c-e9e513e51114">
<name>ansible-test-image-rhel6</name>
<description>my new node</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="aafffb27-f16b-4757-9b63-ef7d8acd9c7f" privateIpv4="172.16.1.8" ipv6="2607:f480:111:1423:1b57:e47a:c212:257d" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/> </networkInfo>
</networkingDetails>
</serverSummary>
<serverSummary id="5718d174-31d4-4d49-b1c6-fcb0d782f233">
<name>ansible-custom-image-test-UAT</name>
<description>my new node</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="b359cea3-4452-46fe-b30b-b3ce839cde9b" privateIpv4="172.16.1.9" ipv6="2607:f480:111:1423:7fa7:9a9b:ecb9:882e" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
</antiAffinityRule>
<antiAffinityRule id="5e10b1ab-68f2-4a8b-a49c-d88d623db665" state="NORMAL" created="2016-03-24T00:07:39.000Z" datacenterId="NA9">
<serverSummary id="9f8b5428-bac3-4cf9-adda-62f57fb38671">
<name>rhel-ansible-full-test</name>
<description>RHEL Ansible Test</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="e081e784-5768-472c-b7f3-353e1646edc8" privateIpv4="172.16.1.15" ipv6="2607:f480:111:1423:70c9:9216:f7bf:dcf6" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
<serverSummary id="feee5cd2-d83b-4b80-913d-0bf26c838a33">
<name>rhel-ansible-full-test</name>
<description>RHEL Ansible Test</description>
<networkingDetails>
<networkInfo networkDomainId="423c4386-87b4-43c4-9604-88ae237bfc7f" networkDomainName="Deloitte Test">
<primaryNic id="3278f833-9535-405c-91b8-0a0470f58aae" privateIpv4="172.16.1.17" ipv6="2607:f480:111:1423:3081:71a8:4c52:a8a" vlanId="bd6fbee5-17db-49f8-b1f5-3b213cea3061" vlanName="deloitte-test"/>
</networkInfo>
</networkingDetails>
</serverSummary>
</antiAffinityRule>
</antiAffinityRules>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns5:Status xmlns:ns16="http://oec.api.opsource.net/schemas/storage" xmlns="http://oec.api.opsource.net/schemas/server" xmlns:ns14="http://oec.api.opsource.net/schemas/serverbootstrap" xmlns:ns15="http://oec.api.opsource.net/schemas/multigeo" xmlns:ns9="http://oec.api.opsource.net/schemas/admin" xmlns:ns5="http://oec.api.opsource.net/schemas/general" xmlns:ns12="http://oec.api.opsource.net/schemas/whitelabel" xmlns:ns13="http://oec.api.opsource.net/schemas/reset" xmlns:ns6="http://oec.api.opsource.net/schemas/vip" xmlns:ns7="http://oec.api.opsource.net/schemas/datacenter" xmlns:ns10="http://oec.api.opsource.net/schemas/backup" xmlns:ns8="http://oec.api.opsource.net/schemas/manualimport" xmlns:ns11="http://oec.api.opsource.net/schemas/support" xmlns:ns2="http://oec.api.opsource.net/schemas/network" xmlns:ns4="http://oec.api.opsource.net/schemas/directory" xmlns:ns3="http://oec.api.opsource.net/schemas/organization">
<ns5:operation>Create Anti Affinity Rule</ns5:operation>
<ns5:result>SUCCESS</ns5:result>
<ns5:resultDetail>Request to create Server Anti-Affinity Rule between 'rhel-ansible-full-test' and 'rhel-ansible-full-test' on 'Deloitte Test' has been accepted and is being processed.</ns5:resultDetail>
<ns5:resultCode>REASON_0</ns5:resultCode>
<ns5:additionalInformation name="antiaffinityrule.id">
<ns5:value>5e10b1ab-68f2-4a8b-a49c-d88d623db665</ns5:value>
</ns5:additionalInformation>
</ns5:Status>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns5:Status xmlns:ns16="http://oec.api.opsource.net/schemas/storage" xmlns="http://oec.api.opsource.net/schemas/server" xmlns:ns14="http://oec.api.opsource.net/schemas/serverbootstrap" xmlns:ns15="http://oec.api.opsource.net/schemas/multigeo" xmlns:ns9="http://oec.api.opsource.net/schemas/admin" xmlns:ns5="http://oec.api.opsource.net/schemas/general" xmlns:ns12="http://oec.api.opsource.net/schemas/whitelabel" xmlns:ns13="http://oec.api.opsource.net/schemas/reset" xmlns:ns6="http://oec.api.opsource.net/schemas/vip" xmlns:ns7="http://oec.api.opsource.net/schemas/datacenter" xmlns:ns10="http://oec.api.opsource.net/schemas/backup" xmlns:ns8="http://oec.api.opsource.net/schemas/manualimport" xmlns:ns11="http://oec.api.opsource.net/schemas/support" xmlns:ns2="http://oec.api.opsource.net/schemas/network" xmlns:ns4="http://oec.api.opsource.net/schemas/directory" xmlns:ns3="http://oec.api.opsource.net/schemas/organization">
<ns5:operation>Create Anti Affinity Rule</ns5:operation>
<ns5:result>ERROR</ns5:result>
<ns5:resultDetail>Server 'ansible-test-image-rhel6' (id 22f3544a-c874-4930-a31c-e9e513e51114) is already used in another Anti-Affinity Rule (id 07e3621a-a920-4a9a-943c-d8021f27f418).</ns5:resultDetail>
<ns5:resultCode>REASON_692</ns5:resultCode>
</ns5:Status>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns5:Status xmlns:ns16="http://oec.api.opsource.net/schemas/storage" xmlns="http://oec.api.opsource.net/schemas/server" xmlns:ns14="http://oec.api.opsource.net/schemas/serverbootstrap" xmlns:ns15="http://oec.api.opsource.net/schemas/multigeo" xmlns:ns9="http://oec.api.opsource.net/schemas/admin" xmlns:ns5="http://oec.api.opsource.net/schemas/general" xmlns:ns12="http://oec.api.opsource.net/schemas/whitelabel" xmlns:ns13="http://oec.api.opsource.net/schemas/reset" xmlns:ns6="http://oec.api.opsource.net/schemas/vip" xmlns:ns7="http://oec.api.opsource.net/schemas/datacenter" xmlns:ns10="http://oec.api.opsource.net/schemas/backup" xmlns:ns8="http://oec.api.opsource.net/schemas/manualimport" xmlns:ns11="http://oec.api.opsource.net/schemas/support" xmlns:ns2="http://oec.api.opsource.net/schemas/network" xmlns:ns4="http://oec.api.opsource.net/schemas/directory" xmlns:ns3="http://oec.api.opsource.net/schemas/organization">
<ns5:operation>Delete Anti Affinity Rule</ns5:operation>
<ns5:result>SUCCESS</ns5:result>
<ns5:resultDetail>Request to delete Server Anti-Affinity Rule between 'ansible-test-image-rhel6' and 'ansible-custom-image-test-UAT' on 'Deloitte Test' has been accepted and is being processed.</ns5:resultDetail>
<ns5:resultCode>REASON_0</ns5:resultCode>
</ns5:Status>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns5:Status xmlns:ns16="http://oec.api.opsource.net/schemas/storage" xmlns="http://oec.api.opsource.net/schemas/server" xmlns:ns14="http://oec.api.opsource.net/schemas/serverbootstrap" xmlns:ns15="http://oec.api.opsource.net/schemas/multigeo" xmlns:ns9="http://oec.api.opsource.net/schemas/admin" xmlns:ns5="http://oec.api.opsource.net/schemas/general" xmlns:ns12="http://oec.api.opsource.net/schemas/whitelabel" xmlns:ns13="http://oec.api.opsource.net/schemas/reset" xmlns:ns6="http://oec.api.opsource.net/schemas/vip" xmlns:ns7="http://oec.api.opsource.net/schemas/datacenter" xmlns:ns10="http://oec.api.opsource.net/schemas/backup" xmlns:ns8="http://oec.api.opsource.net/schemas/manualimport" xmlns:ns11="http://oec.api.opsource.net/schemas/support" xmlns:ns2="http://oec.api.opsource.net/schemas/network" xmlns:ns4="http://oec.api.opsource.net/schemas/directory" xmlns:ns3="http://oec.api.opsource.net/schemas/organization">
<ns5:operation>Delete Anti Affinity Rule</ns5:operation>
<ns5:result>ERROR</ns5:result>
<ns5:resultDetail>Could not find Anti Affinity Rule with Id 07e3621a-a920-4a9a-943c-d8021f27f418</ns5:resultDetail>
<ns5:resultCode>REASON_693</ns5:resultCode>
</ns5:Status>
Loading

0 comments on commit 02ce76d

Please sign in to comment.