Example #1
0
 def create_member(self, context, member):
     v = member['member']
     tenant_id = self._get_tenant_id_for_create(context, v)
     member_id = ''
     if 'id' in v:
         member_id = v['id']
     else:
         member_id = uuidutils.generate_uuid()
     try:
         with context.session.begin(subtransactions=True):
             # ensuring that pool exists
             self._get_resource(context, Pool, v['pool_id'])
             member_db = Member(id=member_id,
                                tenant_id=tenant_id,
                                pool_id=v['pool_id'],
                                address=v['address'],
                                protocol_port=v['protocol_port'],
                                weight=v['weight'],
                                admin_state_up=v['admin_state_up'],
                                status=constants.ACTIVE)
             context.session.add(member_db)
             return self._make_member_dict(member_db)
     except exception.DBDuplicateEntry:
         raise loadbalancer.MemberExists(
             address=v['address'],
             port=v['protocol_port'],
             pool=v['pool_id'])
Example #2
0
 def create_firewall_rule(self, context, firewall_rule):
     LOG.debug(_("create_firewall_rule() called"))
     fwr = firewall_rule['firewall_rule']
     tenant_id = self._get_tenant_id_for_create(context, fwr)
     src_port_min, src_port_max = self._get_min_max_ports_from_range(
         fwr['source_port'])
     dst_port_min, dst_port_max = self._get_min_max_ports_from_range(
         fwr['destination_port'])
     with context.session.begin(subtransactions=True):
         rule_id = ''
         if 'id' in fwr:
             rule_id = fwr['id']
         else:
             rule_id = uuidutils.generate_uuid()
         fwr_db = FirewallRule(id=rule_id,
                               tenant_id=tenant_id,
                               name=fwr['name'],
                               description=fwr['description'],
                               shared=fwr['shared'],
                               protocol=fwr['protocol'],
                               ip_version=fwr['ip_version'],
                               source_ip_address=fwr['source_ip_address'],
                               destination_ip_address=
                               fwr['destination_ip_address'],
                               source_port_range_min=src_port_min,
                               source_port_range_max=src_port_max,
                               destination_port_range_min=dst_port_min,
                               destination_port_range_max=dst_port_max,
                               action=fwr['action'],
                               enabled=fwr['enabled'])
         context.session.add(fwr_db)
     return self._make_firewall_rule_dict(fwr_db)
Example #3
0
 def create_dummy(self, context, dummy):
     d = dummy['dummy']
     d['id'] = uuidutils.generate_uuid()
     self.dummys[d['id']] = d
     fanoutmsg = {}
     fanoutmsg.update({'method':'create_dummy','payload':self.dummys})
     delta={}
     version = 0
     delta[version] = fanoutmsg
     self.send_fanout(context,'call_consumer',delta)
     return d
Example #4
0
 def create_config_handle(self, context, config_handle):
     n = config_handle['config_handle']
     tenant_id = self._get_tenant_id_for_create(context, n)
     with context.session.begin(subtransactions=True):
         config_handle = crd_config_handle(tenant_id=tenant_id,
                                     id=n.get('id') or uuidutils.generate_uuid(),
                                     name=n['name'],
                                     status=n['status'],
                                     slug=n['slug'],
                                     config_mode=n['config_mode'])
         context.session.add(config_handle)
         ####  Delta Start ###########################
         data = self._make_config_handle_dict(config_handle)
         delta = {}
         data.update({'operation':'create'})
         delta.update({'config_handles_delta': data})
         self.create_config_handles_delta(context, delta)
         ####  Delta End ###########################
     return self._make_config_handle_dict(config_handle)
Example #5
0
 def create_firewall_policy(self, context, firewall_policy):
     LOG.debug(_("create_firewall_policy() called"))
     fwp = firewall_policy['firewall_policy']
     tenant_id = self._get_tenant_id_for_create(context, fwp)
     with context.session.begin(subtransactions=True):
         policy_id = ''
         if 'id' in fwp:
             policy_id = fwp['id']
         else:
             policy_id = uuidutils.generate_uuid()
         fwp_db = FirewallPolicy(id=policy_id,
                                 tenant_id=tenant_id,
                                 name=fwp['name'],
                                 description=fwp['description'],
                                 shared=fwp['shared'])
         context.session.add(fwp_db)
         self._set_rules_for_policy(context, fwp_db,
                                    fwp['firewall_rules'])
         fwp_db.audited = fwp['audited']
     return self._make_firewall_policy_dict(fwp_db)
Example #6
0
    def create_firewall(self, context, firewall):
        LOG.debug(_("create_firewall() called"))
        fw = firewall['firewall']
        tenant_id = self._get_tenant_id_for_create(context, fw)
        with context.session.begin(subtransactions=True):
	    fw_id = ''
	    if 'id' in fw:
		fw_id = fw['id']
	    else:
		fw_id = uuidutils.generate_uuid()
            firewall_db = Firewall(id=fw_id,
                                   tenant_id=tenant_id,
                                   name=fw['name'],
                                   description=fw['description'],
                                   firewall_policy_id=
                                   fw['firewall_policy_id'],
                                   admin_state_up=fw['admin_state_up'],
                                   status=const.PENDING_CREATE)
            context.session.add(firewall_db)
        return self._make_firewall_dict(firewall_db)
Example #7
0
File: nova.py Project: Open-SFC/cns
 def create_ofcluster_ofcontroller(self, context, params, cluster_id):
     """ Creiate a New Openflow Controller record """
     # Check whether a row exists with this data in the table
     try:
         with context.session.begin(subtransactions=True):
             controller = OpenflowController(id=str(uuidutils.generate_uuid()),
                                             name=str(params['name']),
                                             ip_address=str(params['ip_address']),
                                             port=str(params['port']),
                                             cell=str(params['cell']),
                                             cluster_id=str(cluster_id),
                                             created_at=datetime.datetime.now(),
                                             updated_at=None,
                                             status='Active',
                                             deleted_at=None)
             
             context.session.add(controller)
             return self._make_controller_dict(controller)
     except BaseException:
         LOG.error("OF-Controller Already exist")
         return {}
Example #8
0
File: nova.py Project: Open-SFC/cns
 def create_ofcluster(self, context, params):
     """ Create a New Openflow Cluster record """
     
     # check any other cluster exists with the same name and key-cert
     db_record = self._check_ofcluster( context, params)
     if db_record is None:
         with context.session.begin(subtransactions=True):
             cluster = OpenflowCluster(id=str(uuidutils.generate_uuid()),
                                       name=str(params['name']),
                                       ca_cert_pem=str(params['ca_cert_path']),
                                       private_key_pem=str(params['private_key_path']),
                                       root_cert_pem=str(params['root_cert_path']),
                                       inter_cert_pem=str(params['inter_cert_path']),
                                       created_at=datetime.datetime.now(),
                                       updated_at=None,
                                       deleted_at=None)
             context.session.add(cluster)
         new_cluster = self._make_cluster_dict(cluster)    
         return new_cluster
     else:
         return db_record
Example #9
0
File: nova.py Project: Open-SFC/cns
 def create_ofcluster_ofcontroller_logicalswitch(self, context, params,
                                                 cluster_id, controller_id=None):
     """ Create a New Switch record """
     if self._check_ofcluster_ofcontroller_logicalswitch(context, params) is None:
         with context.session.begin(subtransactions=True):
             controller = OpenflowSwitch(id=str(uuidutils.generate_uuid()),
                                         datapath_id=str(params['datapath_id']),
                                         name=str(params['name']),
                                         ip_address=str(params['ip_address']),
                                         port=str(params['port']),
                                         certificate_pem=str(params['certificate_pem']),
                                         private_key_pem=str(params['private_key_pem']),
                                         created_at=datetime.datetime.now(),
                                         updated_at=None,
                                         deleted_at=None,
                                         cluster_id=cluster_id,
                                         controller_id=controller_id)
             context.session.add(controller)
         return self._make_switch_dict(controller)
     else:
         LOG.debug(_("Create Logical Switch failed."
                     "Duplicate record found."))
Example #10
0
 def create_health_monitor(self, context, health_monitor):
     v = health_monitor['health_monitor']
     tenant_id = self._get_tenant_id_for_create(context, v)
     monitor_id = ''
     if 'id' in v:
         monitor_id = v['id']
     else:
         monitor_id = uuidutils.generate_uuid()        
     with context.session.begin(subtransactions=True):
         # setting ACTIVE status since healthmon is shared DB object
         monitor_db = HealthMonitor(id=monitor_id,
                                    tenant_id=tenant_id,
                                    type=v['type'],
                                    delay=v['delay'],
                                    timeout=v['timeout'],
                                    max_retries=v['max_retries'],
                                    http_method=v['http_method'],
                                    url_path=v['url_path'],
                                    expected_codes=v['expected_codes'],
                                    admin_state_up=v['admin_state_up'])
         context.session.add(monitor_db)
     return self._make_health_monitor_dict(monitor_db)
Example #11
0
 def create_config_handles_delta(self, context, config_handles_delta):
     n = config_handles_delta['config_handles_delta']
     LOG.error('Delta %s' % str(n))
     tenant_id = self._get_tenant_id_for_create(context, n)
     user_id = context.user_id
             
     with context.session.begin(subtransactions=True):
         version_id = self.create_version(context, tenant_id)
         config_handles_delta = crd_config_handles_delta(tenant_id=tenant_id,
                                      id=uuidutils.generate_uuid(),
                                      config_handle_id = n['id'],
                                      name=n['name'],
                                      status=n['status'],
                                      slug=n['slug'],
                                      operation = n['operation'],
                                      user_id=user_id,
                                      logged_at=datetime.datetime.now(),
                                      version_id=version_id)
         context.session.add(config_handles_delta)
     payload = self._make_config_handles_delta_dict(config_handles_delta)
     method = n['operation']+"_config_handle"
     return self._make_config_handles_delta_dict(config_handles_delta)
Example #12
0
    def create_pool(self, context, pool):
        v = pool['pool']

        tenant_id = self._get_tenant_id_for_create(context, v)
        pool_id = ''
        if 'id' in v:
            pool_id = v['id']
        else:
            pool_id = uuidutils.generate_uuid()
        with context.session.begin(subtransactions=True):
            pool_db = Pool(id=pool_id,
                           tenant_id=tenant_id,
                           name=v['name'],
                           description=v['description'],
                           subnet_id=v['subnet_id'],
                           protocol=v['protocol'],
                           lb_method=v['lb_method'],
                           admin_state_up=v['admin_state_up'],
                           status=constants.ACTIVE)
            pool_db.stats = self._create_pool_stats(context, pool_db['id'])
            context.session.add(pool_db)

        return self._make_pool_dict(pool_db)
Example #13
0
    def create_vip(self, context, vip):
        core_db = network_db.CrdNetworkDb()
        v = vip['vip']
        tenant_id = self._get_tenant_id_for_create(context, v)
        
        vip_id = ''
        if 'id' in v:
            vip_id = v['id']
        else:
            vip_id = uuidutils.generate_uuid()
        with context.session.begin(subtransactions=True):
            if v['pool_id']:
                pool = self._get_resource(context, Pool, v['pool_id'])
                # validate that the pool has same tenant
                if pool['tenant_id'] != tenant_id:
                    raise n_exc.NotAuthorized()
                # validate that the pool has same protocol
                if pool['protocol'] != v['protocol']:
                    raise loadbalancer.ProtocolMismatch(
                        vip_proto=v['protocol'],
                        pool_proto=pool['protocol'])
                if pool['status'] == constants.PENDING_DELETE:
                    raise loadbalancer.StateInvalid(state=pool['status'],
                                                    id=pool['id'])
            else:
                pool = None
            vip_port_address = v['address']
            port_id = None
            filters = {}
            filters['ip_address'] = [vip_port_address]
            vip_port = core_db.get_ports(context, filters=filters)[0]
            port_id = vip_port['id']
            
            vip_db = Vip(id=vip_id,
                         tenant_id=tenant_id,
                         name=v['name'],
                         description=v['description'],
                         port_id=port_id,
                         protocol_port=v['protocol_port'],
                         protocol=v['protocol'],
                         pool_id=v['pool_id'],
                         connection_limit=v['connection_limit'],
                         admin_state_up=v['admin_state_up'],
                         status=constants.ACTIVE)

            session_info = v['session_persistence']

            if session_info:
                s_p = self._create_session_persistence_db(
                    session_info,
                    vip_db['id'])
                vip_db.session_persistence = s_p

            try:
                context.session.add(vip_db)
                context.session.flush()
            except exception.DBDuplicateEntry:
                raise loadbalancer.VipExists(pool_id=v['pool_id'])

            # create a port to reserve address for IPAM
            #self._create_port_for_vip(
            #    context,
            #    vip_db,
            #    v['subnet_id'],
            #    v.get('address')
            #)

            if pool:
                pool['vip_id'] = vip_db['id']
            
        return self._make_vip_dict(vip_db)
Example #14
0
              'default': '', 'is_visible': True},
     'tenant_id': {'allow_post': True, 'allow_put': False,
                   'validate': {'type:string': None},
                   'required_by_policy': True,
                   'is_visible': True},
     'status': {'allow_post': True, 'allow_put': True,
                'default': True, 'is_visible': True},
     'slug': {'allow_post': True, 'allow_put': True,
              'default': '', 'is_visible': True},
     'config_mode': {'allow_post': True, 'allow_put': True,
                     'default': '', 'is_visible': True},
 },
 'chainsets': {
     'id': {'allow_post': True, 'allow_put': False,
            'validate': {'type:regex': attr.UUID_PATTERN},
            'default': uuidutils.generate_uuid(),
            'is_visible': True},
     'name': {'allow_post': True, 'allow_put': True,
              'validate': {'type:string': None},
              'default': '', 'is_visible': True},
     'type': {'allow_post': False, 'allow_put': True,
              'validate': {'type:string': None},
              'default': '-Mode', 'is_visible': True},
     'zonefull': {'allow_post': True,
                  'allow_put': True,
                  'default': True,
                  'convert_to': attr.convert_to_boolean,
                  'is_visible': True},
     'direction': {'allow_post': True,
                  'allow_put': True,
                  'default': '2',