|
7 | 7 | """ |
8 | 8 | import collections |
9 | 9 | import json |
| 10 | +import logging |
| 11 | + |
| 12 | +from SoftLayer.decoration import retry |
10 | 13 |
|
11 | 14 | from SoftLayer import exceptions |
12 | 15 | from SoftLayer import utils |
13 | 16 |
|
14 | 17 | from SoftLayer.managers import event_log |
15 | 18 |
|
| 19 | +LOGGER = logging.getLogger(__name__) |
| 20 | + |
16 | 21 | # pylint: disable=too-many-public-methods |
17 | 22 |
|
18 | 23 | DEFAULT_SUBNET_MASK = ','.join(['hardware', |
@@ -688,7 +693,53 @@ def get_nas_credentials(self, identifier, **kwargs): |
688 | 693 | result = self.network_storage.getObject(id=identifier, **kwargs) |
689 | 694 | return result |
690 | 695 |
|
| 696 | + def edit(self, instance_id, name=None, note=None, tags=None): |
| 697 | + """Edit a vlan. |
| 698 | +
|
| 699 | + :param integer instance_id: the instance ID to edit. |
| 700 | + :param string name: valid name. |
| 701 | + :param string note: note about this particular vlan. |
| 702 | + :param string tags: tags to set on the vlan as a comma separated list. |
| 703 | + Use the empty string to remove all tags. |
| 704 | + :returns: bool -- True or an Exception |
| 705 | + """ |
| 706 | + |
| 707 | + obj = {} |
| 708 | + |
| 709 | + if tags is not None: |
| 710 | + self.set_tags(tags, vlan_id=instance_id) |
| 711 | + |
| 712 | + if name: |
| 713 | + obj['name'] = name |
| 714 | + |
| 715 | + if note: |
| 716 | + obj['note'] = note |
| 717 | + |
| 718 | + if not obj: |
| 719 | + return True |
| 720 | + |
| 721 | + return self.vlan.editObject(obj, id=instance_id) |
| 722 | + |
| 723 | + @retry(logger=LOGGER) |
| 724 | + def set_tags(self, tags, vlan_id): |
| 725 | + """Sets tags on a vlan with a retry decorator |
| 726 | +
|
| 727 | + Just calls vlan.setTags, but if it fails from an APIError will retry. |
| 728 | + """ |
| 729 | + self.vlan.setTags(tags, id=vlan_id) |
| 730 | + |
| 731 | + def get_ip_by_address(self, ip_address): |
| 732 | + """get the ip address object |
| 733 | +
|
| 734 | + :param string ip_address: the ip address to edit. |
| 735 | + """ |
| 736 | + return self.client.call('SoftLayer_Network_Subnet_IpAddress', 'getByIpAddress', ip_address) |
| 737 | + |
691 | 738 | def set_subnet_ipddress_note(self, identifier, note): |
692 | | - """Set the ip address note of the subnet""" |
| 739 | + """Set the ip address note of the subnet |
| 740 | +
|
| 741 | + :param integer identifier: the ip address ID to edit. |
| 742 | + :param json note: the note to edit. |
| 743 | + """ |
693 | 744 | result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier) |
694 | 745 | return result |
0 commit comments