Skip to content

Commit

Permalink
Merge pull request #161 from Wlix13/ExtNetworks-rework
Browse files Browse the repository at this point in the history
C2DEVEL-8028, C2DEVEL-9386, C2DEVEL-12245: Rework ExternalNetwork
  • Loading branch information
Sharpeye90 authored Nov 2, 2024
2 parents 97e2393 + a75ceaf commit 8baa273
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
49 changes: 41 additions & 8 deletions boto/ec2/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5098,11 +5098,25 @@ def get_all_classic_link_instances(self, instance_ids=None, filters=None,

# External networks

def attach_extnetwork(self, network_name, subnet_id=None, switch_id=None, switch_name=None):
def attach_extnetwork(
self,
extnet_id=None,
extnet_name=None,
availability_zone=None,
subnet_id=None,
switch_id=None,
switch_name=None,
):
"""Attach an external network.
:type network_name: string
:param network_name: The name of the external network.
:type extnet_id: string
:param extnet_id: The ID of the external network.
:type extnet_name: string
:param network_name: The name of the external network, used with availability_zone.
:type availability_zone: string
:param availability_zone: The availability zone, used when attaching by name.
:type subnet_id: string
:param subnet_id: The ID of the subnet.
Expand All @@ -5113,7 +5127,13 @@ def attach_extnetwork(self, network_name, subnet_id=None, switch_id=None, switch
:type switch_name: string
:param switch_name: The name of the virtual switch.
"""
params = {'ExtNetName': network_name}
if extnet_id:
params = {'ExtNetId': extnet_id}
elif extnet_name:
params = {'ExtNetName': extnet_name, 'AvailabilityZone': availability_zone}
else:
params = {}

if subnet_id:
params['SubnetId'] = subnet_id
if switch_id:
Expand Down Expand Up @@ -5154,13 +5174,26 @@ def get_all_extnetworks(self, ext_net_names=None, filters=None, dry_run=False):

return self.get_list('DescribeExtNetworks', params, [('item', ExtNetwork)], verb='POST')

def detach_extnetwork(self, network_name):
def detach_extnetwork(self, extnet_id=None, extnet_name=None, availability_zone=None):
"""Detach an external network.
:type network_name: string
:param network_name: The name of the external network.
:type extnet_id: string
:param extnet_id: The ID of the external network.
:type extnet_name: string
:param network_name: The name of the external network, used with availability_zone.
:type availability_zone: string
:param availability_zone: The availability zone, used when attaching by name.
"""
params = {'ExtNetName' : network_name}

if extnet_id:
params = {'ExtNetId': extnet_id}
elif extnet_name:
params = {'ExtNetName': extnet_name, 'AvailabilityZone': availability_zone}
else:
params = {}

return self.get_status('DetachExtNetwork', params, verb='POST')

# Import/Export
Expand Down
4 changes: 3 additions & 1 deletion boto/ec2/extnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def __init__(self, connection = None):
self.availability_zone = None

def endElement(self, name, value, connection):
if name == "extNetName":
if name == "extNetId":
self.extnet_id = value
elif name == "extNetName":
self.extnet_name = value
elif name == "state":
self.state = value
Expand Down

0 comments on commit 8baa273

Please sign in to comment.