def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.nsg_name = defn.nsg_name
        self.resource_group = defn.resource_group

        if check:
            nsg = self.get_settled_resource()
            if not nsg:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(nsg)
                self.handle_changed_property('location', normalize_location(nsg.location),
                                             can_fix = False)
                self.handle_changed_property('tags', nsg.tags)
                self.handle_changed_security_rules(nsg.security_rules)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a network security group that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 2
0
 def _parse_endpoint(self, xml):
     enabled = "Enabled" if self.get_option_value(xml, 'enable',
                                                  bool) else "Disabled"
     weight = self.get_option_value(
         xml,
         'weight',
         int,
         optional=(self.traffic_routing_method != 'Weighted'))
     priority = self.get_option_value(
         xml,
         'priority',
         int,
         optional=(self.traffic_routing_method != 'Priority'))
     location = normalize_location(
         self.get_option_value(
             xml,
             'location',
             str,
             optional=(self.traffic_routing_method != 'Performance')))
     return {
         'target': self.get_option_value(xml, 'target', str, empty=False),
         'endpointStatus': enabled,
         'weight': weight,
         'priority': priority,
         'endpointLocation': location,
     }
Esempio n. 3
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')
        self.no_property_change(defn, 'connection_type')
        self.no_property_change(defn, 'virtual_network_gateway1')
        self.no_property_change(defn, 'virtual_network_gateway2')
        self.no_property_change(defn, 'local_network_gateway2')

        self.copy_mgmt_credentials(defn)
        self.connection_name = defn.connection_name
        self.resource_group = defn.resource_group

        if check:
            connection = self.get_settled_resource()
            if not connection:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(connection)
                self.handle_changed_property('location',
                                             normalize_location(connection.location),
                                             can_fix = False)
                self.handle_changed_property('tags', connection.tags)
                self.handle_changed_property('connection_type',
                                             connection.connection_type, can_fix = False)
                self.handle_changed_property('routing_weight',
                                             connection.routing_weight)
                # check key only if the user wants to manage it
                if defn.shared_key:
                    self.handle_changed_property('shared_key',
                                                connection.shared_key)
                self.handle_changed_property('virtual_network_gateway1',
                                             connection.virtual_network_gateway1 and
                                             connection.virtual_network_gateway1.id,
                                             can_fix = False)
                self.handle_changed_property('virtual_network_gateway2',
                                             connection.virtual_network_gateway2 and
                                             connection.virtual_network_gateway2.id,
                                             can_fix = False)
                self.handle_changed_property('local_network_gateway2',
                                             connection.local_network_gateway2 and
                                             connection.local_network_gateway2.id,
                                             can_fix = False)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a virtual network gateway connection that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 4
0
    def handle_changed_endpoints(self, endpoints):
        def update_endpoints(k, v):
            x = self.endpoints
            if v == None:
                x.pop(k, None)
            else:
                x[k] = v
            self.endpoints = x

        for _ep in endpoints:
            _ep_name = next((_n for _n, _x in self.endpoints.iteritems()
                             if _n == _ep.get('name', None)), None)
            if _ep_name is None:
                self.warn("found unexpected endpoint {0}".format(
                    _ep.get('name', None)))
                update_endpoints(_ep.get('name', None), {"dummy": True})
        for _name, _s_ep in self.endpoints.iteritems():
            if _s_ep.get("dummy", False): continue
            ep_res_name = "endpoint {0}".format(_name)
            ep = next(
                (_r for _r in endpoints if _r.get('name', None) == _name),
                None)
            if ep is None:
                self.warn(
                    "{0} has been deleted behind our back".format(ep_res_name))
                update_endpoints(_name, None)
                continue
            properties = ep.get('properties', {})
            self.handle_changed_dict(_s_ep,
                                     'target',
                                     properties.get('target', None),
                                     resource_name=ep_res_name)
            self.handle_changed_dict(_s_ep,
                                     'endpointStatus',
                                     properties.get('endpointStatus', None),
                                     resource_name=ep_res_name)
            if self.traffic_routing_method == 'Weighted':
                self.handle_changed_dict(_s_ep,
                                         'weight',
                                         properties.get('weight', None),
                                         resource_name=ep_res_name)
            if self.traffic_routing_method == 'Priority':
                self.handle_changed_dict(_s_ep,
                                         'priority',
                                         properties.get('priority', None),
                                         resource_name=ep_res_name)
            if self.traffic_routing_method == 'Performance':
                self.handle_changed_dict(
                    _s_ep,
                    'endpointLocation',
                    normalize_location(properties.get('endpointLocation',
                                                      None)),
                    resource_name=ep_res_name)
            update_endpoints(_name, _s_ep)
Esempio n. 5
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_property_change(defn, 'resource_group')
        self.no_location_change(defn)

        self.copy_mgmt_credentials(defn)
        self.circuit_name = defn.circuit_name
        self.resource_group = defn.resource_group

        if check:
            circuit = self.get_settled_resource()
            if not circuit:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(circuit)
                self.handle_changed_property('tags', circuit.get('tags', {}))
                self.handle_changed_property('location',
                                             normalize_location(
                                                 circuit.get('location',
                                                             None)),
                                             can_fix=False)
                sku = circuit.get('sku', {})
                self.handle_changed_property('tier', sku.get('tier', None))
                self.handle_changed_property('family', sku.get('family', None))
                properties = circuit.get('properties', {})
                provider = properties.get('serviceProviderProperties', {})
                self.handle_changed_property(
                    'service_provider_name',
                    provider.get('serviceProviderName', None))
                self.handle_changed_property(
                    'peering_location', provider.get('peeringLocation', None))
                self.handle_changed_property(
                    'bandwidth', provider.get('bandwidthInMbps', None))
                self.handle_changed_peerings(properties.get('peerings', []))
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating an express route circuit that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
 def _parse_endpoint(self, xml):
     enabled = "Enabled" if self.get_option_value(xml, 'enable', bool) else "Disabled"
     weight = self.get_option_value(xml, 'weight', int,
                                    optional = (self.traffic_routing_method != 'Weighted'))
     priority = self.get_option_value(xml, 'priority', int,
                                      optional = (self.traffic_routing_method != 'Priority'))
     location = normalize_location(
                    self.get_option_value(xml, 'location', str,
                        optional = (self.traffic_routing_method != 'Performance')))
     return {
         'target': self.get_option_value(xml, 'target', str, empty = False),
         'endpointStatus': enabled,
         'weight': weight,
         'priority': priority,
         'endpointLocation': location,
     }
    def handle_changed_endpoints(self, endpoints):
        def update_endpoints(k, v):
            x = self.endpoints
            if v == None:
                x.pop(k, None)
            else:
                x[k] = v
            self.endpoints = x

        for _ep in endpoints:
            _ep_name = next((_n for _n, _x in self.endpoints.iteritems()
                                if _n == _ep.get('name', None)),
                            None)
            if _ep_name is None:
                self.warn("found unexpected endpoint {0}".format(_ep.get('name', None)))
                update_endpoints(_ep.get('name', None), {"dummy": True})
        for _name, _s_ep in self.endpoints.iteritems():
            if _s_ep.get("dummy", False): continue
            ep_res_name = "endpoint {0}".format(_name)
            ep = next((_r for _r in endpoints
                          if _r.get('name', None) == _name),
                      None)
            if ep is None:
                self.warn("{0} has been deleted behind our back".format(ep_res_name))
                update_endpoints(_name, None)
                continue
            properties = ep.get('properties', {})
            self.handle_changed_dict(_s_ep, 'target',
                                     properties.get('target', None),
                                     resource_name = ep_res_name)
            self.handle_changed_dict(_s_ep, 'endpointStatus',
                                     properties.get('endpointStatus', None),
                                     resource_name = ep_res_name)
            if self.traffic_routing_method == 'Weighted':
                self.handle_changed_dict(_s_ep, 'weight',
                                         properties.get('weight', None),
                                         resource_name = ep_res_name)
            if self.traffic_routing_method == 'Priority':
                self.handle_changed_dict(_s_ep, 'priority',
                                         properties.get('priority', None),
                                         resource_name = ep_res_name)
            if self.traffic_routing_method == 'Performance':
                self.handle_changed_dict(_s_ep, 'endpointLocation',
                                         normalize_location(
                                             properties.get('endpointLocation', None)),
                                         resource_name = ep_res_name)
            update_endpoints(_name, _s_ep)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_property_change(defn, 'resource_group')
        self.no_location_change(defn)

        self.copy_mgmt_credentials(defn)
        self.circuit_name = defn.circuit_name
        self.resource_group = defn.resource_group

        if check:
            circuit = self.get_settled_resource()
            if not circuit:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(circuit)
                self.handle_changed_property('tags', circuit.get('tags', {}))
                self.handle_changed_property('location',
                                             normalize_location(circuit.get('location', None)),
                                             can_fix = False)
                sku = circuit.get('sku', {})
                self.handle_changed_property('tier', sku.get('tier', None))
                self.handle_changed_property('family', sku.get('family', None))
                properties = circuit.get('properties', {})
                provider = properties.get('serviceProviderProperties', {})
                self.handle_changed_property('service_provider_name',
                                             provider.get('serviceProviderName', None))
                self.handle_changed_property('peering_location',
                                             provider.get('peeringLocation', None))
                self.handle_changed_property('bandwidth',
                                             provider.get('bandwidthInMbps', None))
                self.handle_changed_peerings(properties.get('peerings', []))
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating an express route circuit that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 9
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.network_name = defn.network_name
        self.resource_group = defn.resource_group

        if check:
            network = self.get_settled_resource()
            if not network:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(network)
                self.handle_changed_property('location',
                                             normalize_location(
                                                 network.location),
                                             can_fix=False)
                self.handle_changed_property('tags', network.tags)
                self.handle_changed_property(
                    'address_space', network.address_space.address_prefixes)
                self.handle_changed_subnets(network.subnets)
                self.handle_changed_property(
                    'dns_servers', network.dhcp_options
                    and network.dhcp_options.dns_servers)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a virtual network that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name,
                                                     defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.reserved_ip_address_name = defn.reserved_ip_address_name
        self.resource_group = defn.resource_group

        if check:
            address = self.get_settled_resource()
            if not address:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(address)
                self.handle_changed_property('location', normalize_location(address.location),
                                             can_fix = False)
                self.handle_changed_property('tags', address.tags)
                self.handle_changed_property('ip_address', address.ip_address, property_name = '')
                self.handle_changed_property('idle_timeout', address.idle_timeout_in_minutes)
                self.handle_changed_property('allocation_method', address.public_ip_allocation_method)
                _dns = address.dns_settings
                self.handle_changed_property('domain_name_label',
                                              _dns and _dns.domain_name_label)
                self.handle_changed_property('reverse_fqdn',
                                              _dns and _dns.reverse_fqdn)
                self.handle_changed_property('fqdn', _dns and _dns.fqdn)
            else:
                self.warn_not_supposed_to_exist(valuable_resource = True)
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a reserved IP address that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self.create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.create_or_update(defn)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.gateway_name = defn.gateway_name
        self.resource_group = defn.resource_group

        if check:
            gateway = self.get_settled_resource()
            if not gateway:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(gateway)
                self.handle_changed_property('location',
                                             normalize_location(
                                                 gateway.location),
                                             can_fix=False)
                self.handle_changed_property('tags', gateway.tags)
                self.handle_changed_property(
                    'address_space', gateway.local_network_site_address_space
                    and
                    gateway.local_network_site_address_space.address_prefixes)
                self.handle_changed_property('ip_address',
                                             gateway.gateway_ip_address)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a local network gateway that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 12
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)

        self.copy_mgmt_credentials(defn)
        self.resource_group_name = defn.resource_group_name

        if check:
            rg = self.get_settled_resource()
            if not rg:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(rg)
                self.handle_changed_property('location',
                                             normalize_location(rg.location),
                                             can_fix=False)
                self.handle_changed_property('tags', rg.tags)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a resource group that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name,
                                                     defn.location))
            self.rmc().resource_groups.create_or_update(
                defn.resource_group_name,
                ResourceGroup(location=defn.location, tags=defn.tags))
            self.state = self.UP
            self.copy_properties(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.rmc().resource_groups.create_or_update(
                defn.resource_group_name,
                ResourceGroup(location=defn.location, tags=defn.tags))
            self.copy_properties(defn)
Esempio n. 13
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.load_balancer_name = defn.load_balancer_name
        self.resource_group = defn.resource_group

        if check:
            lb = self.get_settled_resource()
            if not lb:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(lb)
                self.handle_changed_property('location',
                                             normalize_location(lb.location),
                                             can_fix=False)
                self.handle_changed_property('tags', lb.tags)
                self.handle_changed_probes(lb.probes)
                self.handle_changed_frontend_interfaces(
                    lb.frontend_ip_configurations)
                self.handle_changed_lb_rules(lb.load_balancing_rules)
                self.handle_changed_nat_rules(lb.inbound_nat_rules)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a load balancer that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name,
                                                     defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.network_name = defn.network_name
        self.resource_group = defn.resource_group

        if check:
            network = self.get_settled_resource()
            if not network:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(network)
                self.handle_changed_property('location',
                                             normalize_location(network.location),
                                             can_fix = False)
                self.handle_changed_property('tags', network.tags)
                self.handle_changed_property('address_space',
                                             network.address_space.address_prefixes)
                self.handle_changed_subnets(network.subnets)
                self.handle_changed_property('dns_servers',
                                             network.dhcp_options and
                                             network.dhcp_options.dns_servers)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a virtual network that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 15
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')
        self.no_property_change(defn, 'platform_update_domain_count')
        self.no_property_change(defn, 'platform_fault_domain_count')

        self.copy_mgmt_credentials(defn)
        self.availability_set_name = defn.availability_set_name
        self.resource_group = defn.resource_group

        if check:
            aset = self.get_settled_resource()
            if not aset:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.handle_changed_property('location', normalize_location(aset.location),
                                             can_fix = False)
                self.handle_changed_property('tags', aset.tags)
                self.handle_changed_property('platform_update_domain_count',
                                             aset.platform_update_domain_count,
                                             can_fix = False)
                self.handle_changed_property('platform_fault_domain_count',
                                             aset.platform_fault_domain_count,
                                             can_fix = False)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating an availability set that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)

        self.copy_mgmt_credentials(defn)
        self.resource_group_name = defn.resource_group_name

        if check:
            rg = self.get_settled_resource()
            if not rg:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(rg)
                self.handle_changed_property('location', normalize_location(rg.location),
                                             can_fix = False)
                self.handle_changed_property('tags', rg.tags)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a resource group that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self.rmc().resource_groups.create_or_update(
                defn.resource_group_name,
                ResourceGroup(location = defn.location,
                              tags = defn.tags))
            self.state = self.UP
            self.copy_properties(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.rmc().resource_groups.create_or_update(
                defn.resource_group_name,
                ResourceGroup(location = defn.location,
                              tags = defn.tags))
            self.copy_properties(defn)
Esempio n. 17
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, "resource_group")
        self.no_property_change(defn, "platform_update_domain_count")
        self.no_property_change(defn, "platform_fault_domain_count")

        self.copy_mgmt_credentials(defn)
        self.availability_set_name = defn.availability_set_name
        self.resource_group = defn.resource_group

        if check:
            aset = self.get_settled_resource()
            if not aset:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.handle_changed_property("location", normalize_location(aset.location), can_fix=False)
                self.handle_changed_property("tags", aset.tags)
                self.handle_changed_property(
                    "platform_update_domain_count", aset.platform_update_domain_count, can_fix=False
                )
                self.handle_changed_property(
                    "platform_fault_domain_count", aset.platform_fault_domain_count, can_fix=False
                )
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating an availability set that already exists; " "please run 'deploy --check' to fix this"
                )

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.gateway_name = defn.gateway_name
        self.resource_group = defn.resource_group

        if check:
            gateway = self.get_settled_resource()
            if not gateway:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(gateway)
                self.handle_changed_property('location',
                                             normalize_location(gateway.location), can_fix = False)
                self.handle_changed_property('tags', gateway.tags)
                self.handle_changed_property('address_space',
                                             gateway.local_network_site_address_space and
                                             gateway.local_network_site_address_space.address_prefixes)
                self.handle_changed_property('ip_address',
                                             gateway.gateway_ip_address)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a local network gateway that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 19
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.nsg_name = defn.nsg_name
        self.resource_group = defn.resource_group

        if check:
            nsg = self.get_settled_resource()
            if not nsg:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(nsg)
                self.handle_changed_property('location',
                                             normalize_location(nsg.location),
                                             can_fix=False)
                self.handle_changed_property('tags', nsg.tags)
                self.handle_changed_security_rules(nsg.security_rules)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a network security group that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name,
                                                     defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 20
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.load_balancer_name = defn.load_balancer_name
        self.resource_group = defn.resource_group

        if check:
            lb = self.get_settled_resource()
            if not lb:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(lb)
                self.handle_changed_property('location', normalize_location(lb.location),
                                             can_fix = False)
                self.handle_changed_property('tags', lb.tags)
                self.handle_changed_probes(lb.probes)
                self.handle_changed_frontend_interfaces(lb.frontend_ip_configurations)
                self.handle_changed_lb_rules(lb.load_balancing_rules)
                self.handle_changed_nat_rules(lb.inbound_nat_rules)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a load balancer that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 21
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.storage_name = defn.storage_name
        self.resource_group = defn.resource_group
        self.active_key = defn.active_key

        if check:
            storage = self.get_settled_resource()
            if not storage:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(storage)
                self.handle_changed_property('location', normalize_location(storage.location),
                                             can_fix = False)
                self.handle_changed_property('account_type', storage.account_type)
                self.handle_changed_property('tags', storage.tags)
                self.handle_changed_property('custom_domain', (storage.custom_domain and storage.custom_domain.name) or "")

                keys = self.smc().storage_accounts.list_keys(self.resource_group, self.storage_name).storage_account_keys
                self.handle_changed_property('primary_key', keys.key1)
                self.handle_changed_property('secondary_key', keys.key2)

                self.blob_service_properties = self._check_storage_service_properties(
                                                   self.blob_service_properties,
                                                   self.bs().get_blob_service_properties(),
                                                   'BLOB service')

                self.queue_service_properties = self._check_storage_service_properties(
                                                   self.queue_service_properties,
                                                   self.qs().get_queue_service_properties(),
                                                   'queue service')

                self.table_service_properties = self._check_storage_service_properties(
                                                   self.table_service_properties,
                                                   self.ts().get_table_service_properties(),
                                                   'table service')
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a storage that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0} in {1}...".format(self.full_name, defn.location))
            self.smc().storage_accounts.create(defn.resource_group, defn.storage_name,
                                               StorageAccountCreateParameters(
                                                   account_type = defn.account_type,
                                                   location = defn.location,
                                                   tags = defn.tags))
            self.state = self.UP
            self.copy_properties(defn)
            self.custom_domain = ""
            # getting keys fails until the storage is fully provisioned
            self.log("waiting for the storage to settle; this may take several minutes...")
            self.get_settled_resource()
            keys = self.smc().storage_accounts.list_keys(self.resource_group, self.storage_name).storage_account_keys
            self.primary_key = keys.key1
            self.secondary_key = keys.key2

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            # as per Azure documentation, this API can only
            # change one property per call, so we call it 3 times
            if self.tags != defn.tags:
                self.smc().storage_accounts.update(self.resource_group, self.storage_name,
                                                   StorageAccountUpdateParameters(tags = defn.tags))
                self.tags = defn.tags

            if self.account_type != defn.account_type:
                self.smc().storage_accounts.update(self.resource_group, self.storage_name,
                                                   StorageAccountUpdateParameters(
                                                       account_type = defn.account_type))
                self.account_type = defn.account_type

            if self.custom_domain != defn.custom_domain:
                self.smc().storage_accounts.update(self.resource_group, self.storage_name,
                                                   StorageAccountUpdateParameters(
                                                       custom_domain =
                                                           CustomDomain(name = defn.custom_domain)))
                self.custom_domain = defn.custom_domain

        if self.blob_service_properties != defn.blob_service_properties:
            self.log("updating BLOB service properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.bs().set_blob_service_properties(
                self._dict_to_storage_service_properties(defn.blob_service_properties))
            self.blob_service_properties = defn.blob_service_properties

        if self.queue_service_properties != defn.queue_service_properties:
            self.log("updating queue service properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.qs().set_queue_service_properties(
                self._dict_to_storage_service_properties(defn.queue_service_properties))
            self.queue_service_properties = defn.queue_service_properties

        if self.table_service_properties != defn.table_service_properties:
            self.log("updating table service properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self.ts().set_table_service_properties(
                self._dict_to_storage_service_properties(defn.table_service_properties))
            self.table_service_properties = defn.table_service_properties
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.gateway_name = defn.gateway_name
        self.resource_group = defn.resource_group

        if check:
            gateway = self.get_settled_resource()
            if not gateway:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(gateway)
                self.handle_changed_property('location',
                                             normalize_location(gateway['location']),
                                             can_fix = False)
                self.handle_changed_property('tags', gateway['tags'])
                properties = gateway['properties']
                # azure provides sku specification which doesn't directly map to gatewaySize
                # so we can't check gateway size
                #self.handle_changed_property('gateway_size', properties['gateway_size'])
                self.handle_changed_property('gateway_type', properties['vpnType'])
                self.handle_changed_property('bgp_enabled', properties['enableBgp'])
                ip_config = properties.get('ipConfigurations', [{}])[0].get('properties', {})
                self.handle_changed_property('subnet', ip_config['subnet']['id'])
                self.warn_if_changed(self.ip_address,
                                     ResId(ip_config.get('publicIPAddress', {}).get('id', None))['resource'],
                                     'public IP address resource', can_fix = False)
                try:
                    ip = self.fetch_public_ip()
                except azure.common.AzureMissingResourceHttpError:
                    ip = None
                    self.ip_address = None
                    self.warn('public IP address resource has been deleted behind our back')
                self.handle_changed_property('public_ipv4', ip)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.ip_address is None:
            self.log("getting an IP address")
            self.nrpc().public_ip_addresses.create_or_update(
                self.resource_group, self.ip_addr_name,
                PublicIpAddress(
                    location = defn.location,
                    public_ip_allocation_method = 'Dynamic',
                    idle_timeout_in_minutes = 4,
                ))
            self.ip_address = self.ip_addr_name

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception("tried creating a virtual network gateway that already exists; "
                                "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)
Esempio n. 23
0
    def create(self, defn, check, allow_reboot, allow_recreate):
        self.no_subscription_id_change(defn)
        self.no_location_change(defn)
        self.no_property_change(defn, 'resource_group')

        self.copy_mgmt_credentials(defn)
        self.gateway_name = defn.gateway_name
        self.resource_group = defn.resource_group

        if check:
            gateway = self.get_settled_resource()
            if not gateway:
                self.warn_missing_resource()
            elif self.state == self.UP:
                self.warn_if_failed(gateway)
                self.handle_changed_property('location',
                                             normalize_location(
                                                 gateway['location']),
                                             can_fix=False)
                self.handle_changed_property('tags', gateway['tags'])
                properties = gateway['properties']
                # azure provides sku specification which doesn't directly map to gatewaySize
                # so we can't check gateway size
                #self.handle_changed_property('gateway_size', properties['gateway_size'])
                self.handle_changed_property('gateway_type',
                                             properties['vpnType'])
                self.handle_changed_property('bgp_enabled',
                                             properties['enableBgp'])
                ip_config = properties.get('ipConfigurations',
                                           [{}])[0].get('properties', {})
                self.handle_changed_property('subnet',
                                             ip_config['subnet']['id'])
                self.warn_if_changed(
                    self.ip_address,
                    ResId(
                        ip_config.get('publicIPAddress',
                                      {}).get('id', None))['resource'],
                    'public IP address resource',
                    can_fix=False)
                try:
                    ip = self.fetch_public_ip()
                except azure.common.AzureMissingResourceHttpError:
                    ip = None
                    self.ip_address = None
                    self.warn(
                        'public IP address resource has been deleted behind our back'
                    )
                self.handle_changed_property('public_ipv4', ip)
            else:
                self.warn_not_supposed_to_exist()
                self.confirm_destroy()

        if self.ip_address is None:
            self.log("getting an IP address")
            self.nrpc().public_ip_addresses.create_or_update(
                self.resource_group, self.ip_addr_name,
                PublicIpAddress(
                    location=defn.location,
                    public_ip_allocation_method='Dynamic',
                    idle_timeout_in_minutes=4,
                ))
            self.ip_address = self.ip_addr_name

        if self.state != self.UP:
            if self.get_settled_resource():
                raise Exception(
                    "tried creating a virtual network gateway that already exists; "
                    "please run 'deploy --check' to fix this")

            self.log("creating {0}...".format(self.full_name))
            self._create_or_update(defn)

        if self.properties_changed(defn):
            self.log("updating properties of {0}...".format(self.full_name))
            self.get_settled_resource_assert_exists()
            self._create_or_update(defn)