Beispiel #1
0
 def create_port_precommit(self, context):
     LOG.debug("Create_port_precommit: %s" % context.current)
     if not self._check_dev_owner(context):
         return
     net_svc = self.network_client
     resource_group = azure_conf.resource_group
     region = azure_conf.region
     network_name = self._azure_subnet_network_name(context)
     details = context.current['fixed_ips'][0]
     subnet_name = 'subnet-' + details['subnet_id']
     ip_address = details['ip_address']
     nic_name = 'nic-' + context.current['id']
     ipc_name = 'ipc-' + context.current['id']
     azure_subnet = utils.get_subnet(net_svc, resource_group, network_name,
                                     subnet_name)
     body = {
         'location':
         region,
         'ip_configurations': [{
             'name': ipc_name,
             'private_ip_address': ip_address,
             'private_ip_allocation_method': 'Static',
             'subnet': {
                 'id': azure_subnet.id
             },
         }]
     }
     security_groups = context.current['security_groups']
     if security_groups and len(security_groups) == 1:
         sg_name = self._azure_secgrp_id(security_groups[0])
         sg = utils.get_sg(net_svc, resource_group, sg_name)
         body['network_security_group'] = {'id': sg.id}
     utils.create_nic(net_svc, resource_group, nic_name, body)
     LOG.info("Created NIC %s on Azure." % nic_name)
Beispiel #2
0
 def _create_secrule(self, **kwargs):
     net_svc = self.network_client
     resource_group = azure_conf.resource_group
     rule = kwargs['security_group_rule']
     azure_rule = utils.convert_sg_rule(rule)
     sg_name = self._azure_secgrp_id(rule['security_group_id'])
     name = self._azure_secrule_id(rule['id'])
     sg = utils.get_sg(net_svc, resource_group, sg_name)
     # Each Azure security rule has a priority.
     # The value can be between 100 and 4096. The priority number must be
     # unique for each rule in the collection. The lower the priority
     # number, the higher the priority of the rule.
     previous_priorities = sorted([i.priority for i in sg.security_rules])
     if previous_priorities:
         priority = previous_priorities[-1] + 1
     else:
         priority = 100
     azure_rule['priority'] = priority
     utils.create_sg_rule(net_svc, resource_group, sg_name, name,
                          azure_rule)