def create_vpnservice(self, context, vpnservice): vpns = vpnservice['vpnservice'] tenant_id = self._get_tenant_id_for_create(context, vpns) validator = self._get_validator() service_type = vpns["service_type"] router_id = vpns["router_id"] count = self._get_collection_count(context, vpn_models.VPNService, filters={"service_type": service_type, "router_id": router_id}) if count: if service_type == vpn_constants.SERVICE_TYPE_PPTP: raise pptp.PPTPServiceExisted(router_id=router_id) elif service_type == vpn_constants.SERVICE_TYPE_OPENVPN: raise openvpn.OpenVpnServiceExisted(router_id=router_id) with context.session.begin(subtransactions=True): validator.validate_vpnservice(context, vpns) subnet_id = vpns.get("subnet_id", None) if not subnet_id: subnet_id = None vpnservice_db = vpn_models.VPNService( id=uuidutils.generate_uuid(), tenant_id=tenant_id, name=vpns['name'], description=vpns['description'], service_type=service_type, subnet_id=subnet_id, router_id=router_id, admin_state_up=vpns['admin_state_up'], status=constants.PENDING_CREATE) context.session.add(vpnservice_db) return self._make_vpnservice_dict(vpnservice_db)
def create_vpnservice(self, context, vpnservice): vpns = vpnservice['vpnservice'] validator = self._get_validator() with context.session.begin(subtransactions=True): validator.validate_vpnservice(context, vpns) vpnservice_db = vpn_models.VPNService( id=uuidutils.generate_uuid(), tenant_id=vpns['tenant_id'], name=vpns['name'], description=vpns['description'], subnet_id=vpns['subnet_id'], router_id=vpns['router_id'], admin_state_up=vpns['admin_state_up'], status=p_constants.PENDING_CREATE) context.session.add(vpnservice_db) return self._make_vpnservice_dict(vpnservice_db)
def create_vpnservice(self, context, vpnservice): vpns = vpnservice['vpnservice'] flavor_id = vpns.get('flavor_id', None) validator = self._get_validator() with db_api.CONTEXT_WRITER.using(context): validator.validate_vpnservice(context, vpns) vpnservice_db = vpn_models.VPNService( id=uuidutils.generate_uuid(), tenant_id=vpns['tenant_id'], name=vpns['name'], description=vpns['description'], subnet_id=vpns['subnet_id'], router_id=vpns['router_id'], flavor_id=flavor_id, admin_state_up=vpns['admin_state_up'], status=lib_constants.PENDING_CREATE) context.session.add(vpnservice_db) return self._make_vpnservice_dict(vpnservice_db)