def _ex_create_network(self, cidr, name):
        """
        Create a network
        """
        data = {
            "location": self.provider.default_location.id,
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        cidr
                    ]
                }
            }
        }

        subscription = self.provider.connection.subscription_id
        resource_group = self.resource_group

        action = f"/subscriptions/{subscription}/resourceGroups/" \
            f"{resource_group}/providers/" \
            "Microsoft.Network/virtualNetworks/{name}"

        r = self.provider.connection.request(
            action,
            params=self.api_version,
            method="PUT",
            data=data
        )

        return AzureNetwork(
            id=r.object["id"],
            name=r.object["name"],
            location=r.object["location"],
            extra=r.object["properties"]
        )
Esempio n. 2
0
    def _ex_create_network(self, cidr, name):
        """
        Create a network
        """
        data = {
            "location": self.default_location.id,
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        cidr
                    ]
                }
            }
        }

        action = "/subscriptions/%s/resourceGroups/%s/providers/" \
                 "Microsoft.Network/virtualNetworks/%s" \
                 % (self.connection.subscription_id, self.resource_group, name)

        r = self.connection.request(
            action,
            params={"api-version": "2018-08-01"},
            method="PUT",
            data=data
        )

        return AzureNetwork(
            id=r.object["id"],
            name=r.object["name"],
            location=r.object["location"],
            extra=r.object["properties"]
        )
Esempio n. 3
0
    def ex_create_network(self, resource_group, network, extra=None, location=None):
        """ Create a new network. Subnets can be created using the "properties" in extra field

        :param resource_group: name of the resource group
        :param network: name of the network
        :param extra: extra properties
        :param location: location of the network
        :return:
        """
        if location is None:
            if self.default_location:
                location = self.default_location
            else:
                raise ValueError("location is required.")
        target = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s" % (
            self.subscription_id, resource_group, network)
        params = {"api-version": "2016-03-30"}
        data = {
            "tags": {},
            "location": location.id,
        }

        if extra:
            data["properties"] = extra

        r = self.connection.request(action=target,
                                    params=params,
                                    data=data,
                                    method="PUT")

        while r.object is None:
            time.sleep(1)

        return AzureNetwork(r.object["id"], r.object["name"], r.object["location"], r.object["properties"])
Esempio n. 4
0
    def ex_create_network(self,
                          resource_group,
                          location_id,
                          cidr_block,
                          dns_server=None,
                          name=None):

        data = {
            "location": location_id,
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [cidr_block]
                }
            }
        }

        action = "/subscriptions/%s/resourceGroups/%s/providers/" \
                 "Microsoft.Network/virtualNetworks/%s" \
                 % (self.connection.subscription_id, resource_group, name)

        r = self.connection.request(action,
                                    params={"api-version": "2017-03-01"},
                                    method="PUT",
                                    data=data)
        return AzureNetwork(r.object["id"], r.object["name"],
                            r.object["location"], r.object["properties"])
Esempio n. 5
0
    def list_subnets(self):
        result = []

        cloud_driver = self.get_cloud_driver()

        n = AzureNetwork(self.id, None, None, None)

        subnets = cloud_driver.ex_list_subnets(network=n)

        for subnet in subnets:
            result.append(
                AzureSubnet(subnet.id, subnet.name,
                            subnet.extra["addressPrefix"], self))

        return result
Esempio n. 6
0
    def ex_update_network(self, resource_group, location_id, cidr_block, name,
                          dns_server):

        action = "/subscriptions/%s/resourceGroups/%s/providers/" \
                 "Microsoft.Network/virtualNetworks/%s" \
                 % (self.connection.subscription_id, resource_group, name)

        r = self.connection.request(action,
                                    params={"api-version": "2017-08-01"},
                                    method="GET")

        data = r.object

        data["properties"]["dhcpOptions"] = {"dnsServers": [dns_server]}

        r = self.connection.request(action,
                                    params={"api-version": "2017-08-01"},
                                    method="PUT",
                                    data=data)

        return AzureNetwork(r.object["id"], r.object["name"],
                            r.object["location"], r.object["properties"])
Esempio n. 7
0
 def _list_subnets__fetch_subnets(self, network):
     l_network = AzureNetwork(network.network_id,
                              network.name, '', network.extra)
     return self.cloud.ctl.compute.connection.ex_list_subnets(l_network)