Exemple #1
0
    def _wait_for_vlan_state(self, vlan, state_to_wait_for):
        network_domain = self._get_network_domain()

        wait_poll_interval = self.module.params['wait_poll_interval']
        wait_time = self.module.params['wait_time']

        # Bizarre bug in libcloud when checking status after delete; socket.error is too generic to catch in this context so for now we don't even try.

        try:
            return self.driver.connection.wait_for_state(
                state_to_wait_for, self.driver.ex_get_vlan, wait_poll_interval,
                wait_time, vlan)

        except DimensionDataAPIException as api_exception:
            if api_exception.code != 'RESOURCE_NOT_FOUND':
                raise

            return DimensionDataVlan(id=vlan.id,
                                     status='NOT_FOUND',
                                     name='',
                                     description='',
                                     private_ipv4_range_address='',
                                     private_ipv4_range_size=0,
                                     ipv4_gateway='',
                                     ipv6_range_address='',
                                     ipv6_range_size=0,
                                     ipv6_gateway='',
                                     location=self.location,
                                     network_domain=network_domain)
def delete_vlan(client, vlanid):
    try:
        client.node.ex_delete_vlan(
            DimensionDataVlan(vlanid, None, None, None, None, None, None, None,
                              None, None, None, None))
        click.secho("Vlan {0} deleted.".format(vlanid), fg='green', bold=True)
    except DimensionDataAPIException as e:
        handle_dd_api_exception(e)
Exemple #3
0
    def _to_vlan(self, element):
        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))

        location_id = element.get('location')
        location = self.ex_get_location_by_id(location_id)

        return DimensionDataVlan(
            id=element.get('id'),
            name=findtext(element, 'name', TYPES_URN),
            description=findtext(element, 'description',
                                 TYPES_URN),
            location=location,
            status=status)
Exemple #4
0
    def _to_vlan(self, element, locations):
        status = self._to_status(element.find(fixxpath('state', TYPES_URN)))

        location_id = element.get('datacenterId')
        location = list(filter(lambda x: x.id == location_id, locations))[0]
        ip_range = element.find(fixxpath('privateIpv4Range', TYPES_URN))
        return DimensionDataVlan(
            id=element.get('id'),
            name=findtext(element, 'name', TYPES_URN),
            description=findtext(element, 'description', TYPES_URN),
            private_ipv4_range_address=ip_range.get('address'),
            private_ipv4_range_size=ip_range.get('prefixSize'),
            location=location,
            status=status)
Exemple #5
0
    def ex_create_vlan(self,
                       network_domain,
                       name,
                       private_ipv4_base_address,
                       description=None,
                       private_ipv4_prefix_size='24'):
        """
        Deploy a new VLAN to a network domain
        """
        create_node = ET.Element('deployVlan', {'xmlns': TYPES_URN})
        ET.SubElement(create_node, "networkDomainId").text = network_domain.id
        ET.SubElement(create_node, "name").text = name
        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "privateIpv4BaseAddress").text = \
            private_ipv4_base_address
        ET.SubElement(create_node, "privateIpv4PrefixSize").text = \
            private_ipv4_prefix_size

        response = self.connection.request_with_orgId_api_2(
            'network/deployVlan', method='POST',
            data=ET.tostring(create_node)).object

        vlan_id = None

        for info in findall(response, 'info', TYPES_URN):
            if info.get('name') == 'vlanId':
                vlan_id = info.get('value')

        return DimensionDataVlan(
            id=vlan_id,
            name=name,
            description=description,
            location=network_domain.location,
            status=NodeState.RUNNING,
            private_ipv4_range_address=private_ipv4_base_address,
            private_ipv4_range_size=private_ipv4_prefix_size)