Initial commit of PassiveTest
Change-Id: Idcd9a0c72df5eae6b4eedc544e473ebc9763ccdb
diff --git a/xos/PassiveTest-onboard.yaml b/xos/PassiveTest-onboard.yaml
new file mode 100644
index 0000000..5b29c3d
--- /dev/null
+++ b/xos/PassiveTest-onboard.yaml
@@ -0,0 +1,26 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the PassiveTest
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ passivetest:
+ type: tosca.nodes.ServiceController
+ properties:
+ base_url: file:///opt/xos_services/PassiveTest/xos/
+ # The following will concatenate with base_url automatically, if
+ # base_url is non-null.
+ models: models.py
+ admin: admin.py
+ synchronizer: synchronizer/manifest
+ synchronizer_run: passivetest-synchronizer.py
+ tosca_custom_types: PassiveTest.yaml
+ tosca_resource: tosca/resources/passivetest.py, tosca/resources/passivetesttenant.py
+ rest_service: api/service/passivetest.py
+ rest_tenant: api/tenant/passivetesttenant.py
+ private_key: file:///opt/xos/key_import/passivetest_rsa
+ public_key: file:///opt/xos/key_import/passivetest_rsa.pub
+
diff --git a/xos/PassiveTest.m4 b/xos/PassiveTest.m4
new file mode 100644
index 0000000..a477bd4
--- /dev/null
+++ b/xos/PassiveTest.m4
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+# compile this with "m4 PassiveTest.m4 > PassiveTest.yaml"
+
+# include macros
+include(macros.m4)
+
+node_types:
+ tosca.nodes.PassiveTest:
+ derived_from: tosca.nodes.Root
+ description: >
+ PassiveTest Service
+ capabilities:
+ xos_base_service_caps
+ properties:
+ xos_base_props
+ xos_base_service_props
+ tap_ports:
+ type: string
+ required: false
+ reset_viv:
+ type: boolean
+ required: false
+
+ tosca.nodes.PassiveTestTenant:
+ derived_from: tosca.nodes.Root
+ description: >
+ A Tenant of the PassiveTest service
+ properties:
+ xos_base_tenant_props
+
diff --git a/xos/PassiveTest.yaml b/xos/PassiveTest.yaml
new file mode 100644
index 0000000..d3eb368
--- /dev/null
+++ b/xos/PassiveTest.yaml
@@ -0,0 +1,101 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+# compile this with "m4 PassiveTest.m4 > PassiveTest.yaml"
+
+# include macros
+# Note: Tosca derived_from isn't working the way I think it should, it's not
+# inheriting from the parent template. Until we get that figured out, use
+# m4 macros do our inheritance
+
+
+# Service
+
+
+# Subscriber
+
+
+
+
+# end m4 macros
+
+
+
+node_types:
+ tosca.nodes.PassiveTest:
+ derived_from: tosca.nodes.Root
+ description: >
+ PassiveTest Service
+ capabilities:
+ scalable:
+ type: tosca.capabilities.Scalable
+ service:
+ type: tosca.capabilities.xos.Service
+ properties:
+ no-delete:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to delete this object
+ no-create:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to create this object
+ no-update:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to update this object
+ replaces:
+ type: string
+ required: false
+ descrption: Replaces/renames this object
+ kind:
+ type: string
+ default: generic
+ description: Type of service.
+ view_url:
+ type: string
+ required: false
+ description: URL to follow when icon is clicked in the Service Directory.
+ icon_url:
+ type: string
+ required: false
+ description: ICON to display in the Service Directory.
+ enabled:
+ type: boolean
+ default: true
+ published:
+ type: boolean
+ default: true
+ description: If True then display this Service in the Service Directory.
+ public_key:
+ type: string
+ required: false
+ description: Public key to install into Instances to allows Services to SSH into them.
+ private_key_fn:
+ type: string
+ required: false
+ description: Location of private key file
+ versionNumber:
+ type: string
+ required: false
+ description: Version number of Service.
+ tap_ports:
+ type: string
+ required: false
+ reset_viv:
+ type: boolean
+ required: false
+
+ tosca.nodes.PassiveTestTenant:
+ derived_from: tosca.nodes.Root
+ description: >
+ A Tenant of the PassiveTest service
+ properties:
+ kind:
+ type: string
+ default: generic
+ description: Kind of tenant
+ service_specific_id:
+ type: string
+ required: false
+ description: Service specific ID opaque to XOS but meaningful to service
+
diff --git a/xos/admin.py b/xos/admin.py
new file mode 100644
index 0000000..e492e58
--- /dev/null
+++ b/xos/admin.py
@@ -0,0 +1,118 @@
+# admin.py - PassiveTest Django Admin
+
+from core.admin import ReadOnlyAwareAdmin, SliceInline
+from core.middleware import get_request
+from core.models import User
+
+from django import forms
+from django.contrib import admin
+
+from services.passivetest.models import *
+
+class PassiveTestForm(forms.ModelForm):
+
+ class Meta:
+ model = PassiveTestService
+ fields = '__all__'
+
+ def __init__(self, *args, **kwargs):
+ super(PassiveTestForm, self).__init__(*args, **kwargs)
+
+ if self.instance:
+ self.fields['tap_ports'].initial = self.instance.tap_ports
+ self.fields['reset_viv'].initial = self.instance.reset_viv
+
+ def save(self, commit=True):
+ self.instance.tap_ports = self.cleaned_data.get('tap_ports')
+ self.instance.reset_viv = self.cleaned_data.get('reset_viv')
+ return super(PassiveTestForm, self).save(commit=commit)
+
+class PassiveTestAdmin(ReadOnlyAwareAdmin):
+
+ model = PassiveTestService
+ verbose_name = PASSIVETEST_SERVICE_NAME_VERBOSE
+ verbose_name_plural = PASSIVETEST_SERVICE_NAME_VERBOSE_PLURAL
+ form = PassiveTestForm
+ inlines = [SliceInline]
+
+ list_display = ('backend_status_icon', 'name', 'tap_ports', 'reset_viv', 'enabled')
+ list_display_links = ('backend_status_icon', 'name', 'tap_ports', 'reset_viv')
+
+ fieldsets = [(None, {
+ 'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'tap_ports', 'reset_viv', 'description',],
+ 'classes':['suit-tab suit-tab-general',],
+ })]
+
+ readonly_fields = ('backend_status_text', )
+ user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
+
+ extracontext_registered_admins = True
+
+ suit_form_tabs = (
+ ('general', 'PassiveTest Details', ),
+ ('slices', 'Slices',),
+ )
+
+ suit_form_includes = ((
+ 'top',
+ 'administration'),
+ )
+
+ def get_queryset(self, request):
+ return PassiveTestService.get_service_objects_by_user(request.user)
+
+admin.site.register(PassiveTestService, PassiveTestAdmin)
+
+class PassiveTestTenantForm(forms.ModelForm):
+
+ class Meta:
+ model = PassiveTestTenant
+ fields = '__all__'
+
+ creator = forms.ModelChoiceField(queryset=User.objects.all())
+
+ def __init__(self, *args, **kwargs):
+ super(PassiveTestTenantForm, self).__init__(*args, **kwargs)
+
+ self.fields['kind'].widget.attrs['readonly'] = True
+ self.fields['kind'].initial = PASSIVETEST_KIND
+
+ self.fields['provider_service'].queryset = PassiveTestService.get_service_objects().all()
+
+ if self.instance:
+ self.fields['creator'].initial = self.instance.creator
+
+ if (not self.instance) or (not self.instance.pk):
+ self.fields['creator'].initial = get_request().user
+ if PassiveTestService.get_service_objects().exists():
+ self.fields['provider_service'].initial = PassiveTestService.get_service_objects().all()[0]
+
+ def save(self, commit=True):
+ self.instance.creator = self.cleaned_data.get('creator')
+ return super(PassiveTestTenantForm, self).save(commit=commit)
+
+
+class PassiveTestTenantAdmin(ReadOnlyAwareAdmin):
+
+ verbose_name = PASSIVETEST_TENANT_NAME_VERBOSE
+ verbose_name_plural = PASSIVETEST_TENANT_NAME_VERBOSE_PLURAL
+
+ list_display = ('id', 'backend_status_icon', 'instance')
+ list_display_links = ('backend_status_icon', 'instance', 'id')
+
+ fieldsets = [(None, {
+ 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator'],
+ 'classes': ['suit-tab suit-tab-general'],
+ })]
+
+ readonly_fields = ('backend_status_text', 'instance',)
+
+ form = PassiveTestTenantForm
+
+ suit_form_tabs = (('general', 'Details'),)
+
+ def get_queryset(self, request):
+ return PassiveTestTenant.get_tenant_objects_by_user(request.user)
+
+admin.site.register(PassiveTestTenant, PassiveTestTenantAdmin)
+
diff --git a/xos/api/service/passivetest.py b/xos/api/service/passivetest.py
new file mode 100644
index 0000000..f5b556d
--- /dev/null
+++ b/xos/api/service/passivetest.py
@@ -0,0 +1,38 @@
+from rest_framework.response import Response
+from rest_framework import serializers
+from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
+from services.passivetest.models import PassiveTestService
+
+class PassiveTestSerializer(PlusModelSerializer):
+ id = ReadOnlyField()
+ humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+ tap_ports = serializers.CharField(required=False)
+ reset_viv = serializers.BooleanField(required=False)
+
+ class Meta:
+ model = PassiveTestService
+ fields = ('humanReadableName',
+ 'id',
+ 'tap_ports',
+ 'reset_viv')
+
+ def getHumanReadableName(self, obj):
+ return obj.__unicode__()
+
+class PassiveTestViewSet(XOSViewSet):
+ base_name = "passivetest"
+ method_name = "passivetest"
+ method_kind = "viewset"
+ queryset = PassiveTestService.get_service_objects().all()
+ serializer_class = PassiveTestSerializer
+
+ @classmethod
+ def get_urlpatterns(self, api_path="^"):
+ patterns = super(PassiveTestViewSet, self).get_urlpatterns(api_path=api_path)
+ return patterns
+
+ def list(self, request):
+ object_list = self.filter_queryset(self.get_queryset())
+ serializer = self.get_serializer(object_list, many=True)
+ return Response(serializer.data)
+
diff --git a/xos/api/tenant/passivetesttenant.py b/xos/api/tenant/passivetesttenant.py
new file mode 100644
index 0000000..21c9b1a
--- /dev/null
+++ b/xos/api/tenant/passivetesttenant.py
@@ -0,0 +1,39 @@
+from rest_framework.response import Response
+from rest_framework import serializers
+from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
+
+from services.passivetest.models import PassiveTestTenant, PassiveTestService
+
+def get_default_passivetest_service():
+ passivetest_services = PassiveTestService.get_service_objects().all()
+ if passivetest_services:
+ return passivetest_services[0]
+ return None
+
+class PassiveTestTenantSerializer(PlusModelSerializer):
+ id = ReadOnlyField()
+ provider_service = serializers.PrimaryKeyRelatedField(queryset=PassiveTestService.get_service_objects().all(), default=get_default_passivetest_service)
+ backend_status = ReadOnlyField()
+
+ humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+
+ class Meta:
+ model = PassiveTestTenant
+ fields = ('humanReadableName', 'id', 'provider_service', 'backend_status')
+
+ def getHumanReadableName(self, obj):
+ return obj.__unicode__()
+
+class PassiveTestTenantViewSet(XOSViewSet):
+ base_name = "passivetesttenant"
+ method_name = "passivetesttenant"
+ method_kind = "viewset"
+ queryset = PassiveTestTenant.get_tenant_objects().all()
+ serializer_class = PassiveTestTenantSerializer
+
+
+ def list(self, request):
+ queryset = self.filter_queryset(self.get_queryset())
+ serializer = self.get_serializer(queryset, many=True)
+ return Response(serializer.data)
+
diff --git a/xos/macros.m4 b/xos/macros.m4
new file mode 100644
index 0000000..1f48f10
--- /dev/null
+++ b/xos/macros.m4
@@ -0,0 +1,84 @@
+# Note: Tosca derived_from isn't working the way I think it should, it's not
+# inheriting from the parent template. Until we get that figured out, use
+# m4 macros do our inheritance
+
+define(xos_base_props,
+ no-delete:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to delete this object
+ no-create:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to create this object
+ no-update:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to update this object
+ replaces:
+ type: string
+ required: false
+ descrption: Replaces/renames this object)
+# Service
+define(xos_base_service_caps,
+ scalable:
+ type: tosca.capabilities.Scalable
+ service:
+ type: tosca.capabilities.xos.Service)
+define(xos_base_service_props,
+ kind:
+ type: string
+ default: generic
+ description: Type of service.
+ view_url:
+ type: string
+ required: false
+ description: URL to follow when icon is clicked in the Service Directory.
+ icon_url:
+ type: string
+ required: false
+ description: ICON to display in the Service Directory.
+ enabled:
+ type: boolean
+ default: true
+ published:
+ type: boolean
+ default: true
+ description: If True then display this Service in the Service Directory.
+ public_key:
+ type: string
+ required: false
+ description: Public key to install into Instances to allows Services to SSH into them.
+ private_key_fn:
+ type: string
+ required: false
+ description: Location of private key file
+ versionNumber:
+ type: string
+ required: false
+ description: Version number of Service.)
+# Subscriber
+define(xos_base_subscriber_caps,
+ subscriber:
+ type: tosca.capabilities.xos.Subscriber)
+define(xos_base_subscriber_props,
+ kind:
+ type: string
+ default: generic
+ description: Kind of subscriber
+ service_specific_id:
+ type: string
+ required: false
+ description: Service specific ID opaque to XOS but meaningful to service)
+define(xos_base_tenant_props,
+ kind:
+ type: string
+ default: generic
+ description: Kind of tenant
+ service_specific_id:
+ type: string
+ required: false
+ description: Service specific ID opaque to XOS but meaningful to service)
+
+# end m4 macros
+
diff --git a/xos/make_synchronizer_manifest.sh b/xos/make_synchronizer_manifest.sh
new file mode 100644
index 0000000..4058982
--- /dev/null
+++ b/xos/make_synchronizer_manifest.sh
@@ -0,0 +1,2 @@
+#! /bin/bash
+find synchronizer -type f | cut -b 14- > synchronizer/manifest
diff --git a/xos/models.py b/xos/models.py
new file mode 100644
index 0000000..53b0d0e
--- /dev/null
+++ b/xos/models.py
@@ -0,0 +1,67 @@
+# models.py - ExampleService Models
+
+from core.models import Service, TenantWithContainer
+from django.db import models, transaction
+
+PASSIVETEST_KIND = 'PassiveTest'
+PASSIVETEST_SERVICE_NAME = 'passivetest'
+PASSIVETEST_SERVICE_NAME_VERBOSE = 'PASSIVETEST Service'
+PASSIVETEST_SERVICE_NAME_VERBOSE_PLURAL = 'PASSIVETEST Services'
+PASSIVETEST_TENANT_NAME_VERBOSE = 'PASSIVETEST Tenant'
+PASSIVETEST_TENANT_NAME_VERBOSE_PLURAL = 'PASSIVETEST Tenants'
+
+class PassiveTestService(Service):
+
+ KIND = PASSIVETEST_KIND
+
+ class Meta:
+ app_label = PASSIVETEST_SERVICE_NAME
+ verbose_name = PASSIVETEST_SERVICE_NAME_VERBOSE
+
+ tap_ports = models.CharField(max_length=254, help_text="Neutron Port ids of the ports we want to tap (comma delimited)")
+ reset_viv = models.BooleanField(default=False, help_text="Reset the VIV's input and output configurations!")
+
+
+class PassiveTestTenant(TenantWithContainer):
+
+ KIND = PASSIVETEST_KIND
+
+ class Meta:
+ verbose_name = PASSIVETEST_TENANT_NAME_VERBOSE
+
+ def __init__(self, *args, **kwargs):
+ passivetestservice = PassiveTestService.get_service_objects().all()
+ if passivetestservice:
+ self._meta.get_field('provider_service').default = passivetestservice[0].id
+ super(PassiveTestTenant, self).__init__(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ super(PassiveTestTenant, self).save(*args, **kwargs)
+ model_policy_passivetesttenant(self.pk)
+
+ def delete(self, *args, **kwargs):
+ self.cleanup_container()
+ super(PassiveTestTenant, self).delete(*args, **kwargs)
+
+ @property
+ def public_ip(self):
+ for port in self.instance.ports.all():
+ if "public" in port.network.name.lower():
+ return port.ip
+ return None
+
+ @property
+ def synchronizer_ip(self):
+ for port in self.instance.ports.all():
+ if "management" in port.network.name.lower():
+ return port.ip
+ return None
+
+def model_policy_passivetesttenant(pk):
+ with transaction.atomic():
+ tenant = PassiveTestTenant.objects.select_for_update().filter(pk=pk)
+ if not tenant:
+ return
+ tenant = tenant[0]
+ tenant.manage_container()
+
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
new file mode 100644
index 0000000..dd23436
--- /dev/null
+++ b/xos/synchronizer/manifest
@@ -0,0 +1,20 @@
+passivetest-synchronizer.yaml
+manifest
+passivetest_config
+monitoring_stats_notifier.py
+passivetest-synchronizer.py
+steps/sync_passivetesttenant.py
+steps/passivetesttenant_playbook.yaml
+steps/sync_monitoring_agent.yaml
+steps/roles/setup_probe/tasks/main.yml
+steps/roles/setup_probe/files/README
+steps/roles/setup_probe/files/debs/docker.io_1.6.2~dfsg1-1ubuntu4~14.04.1_amd64.deb
+steps/roles/setup_probe/files/debs/cgroup-lite_1.11~ubuntu14.04.2_all.deb
+steps/roles/setup_probe/files/debs/liberror-perl_0.17-1.1_all.deb
+steps/roles/setup_probe/files/debs/aufs-tools_3.2+20130722-1.1_amd64.deb
+steps/roles/setup_probe/files/debs/git-man_1.9.1-1ubuntu0.3_all.deb
+steps/roles/setup_probe/files/debs/git_1.9.1-1ubuntu0.3_amd64.deb
+steps/roles/setup_probe/files/passivetest_rsa.pub
+steps/roles/setup_probe/files/viv
+steps/roles/setup_probe/files/xcp.docker
+model-deps
diff --git a/xos/synchronizer/model-deps b/xos/synchronizer/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/synchronizer/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/synchronizer/monitoring_stats_notifier.py b/xos/synchronizer/monitoring_stats_notifier.py
new file mode 100644
index 0000000..bbfc0db
--- /dev/null
+++ b/xos/synchronizer/monitoring_stats_notifier.py
@@ -0,0 +1,111 @@
+import six, uuid, csv, datetime, threading, socket, shutil, argparse, glob, os, copy, pprint, time, sys
+from kombu.connection import BrokerConnection
+from kombu.messaging import Exchange, Queue, Consumer, Producer
+
+XAGG_CSV_DIR="/xsight/var/opt/xagg/tmp"
+XAGG_CSV_PROCESSED_DIR="/xsight/var/opt/xagg/tmp/processed"
+
+class RabbitMQ:
+ def __init__(self, rabbit_host, rabbit_user, rabbit_password, exchange_name):
+ exchange = Exchange(exchange_name, "topic", durable=False)
+ connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
+ channel = connection.channel()
+ self.producer = Producer(channel, exchange=exchange, routing_key="notifications.info")
+
+ def publish(self, stats):
+ self.producer.publish(stats)
+
+
+class CeilometerStats:
+ def __init__(self, keystone_user_id, keystone_tenant_id):
+ self.message_template = {'publisher_id': "monitoring_on_"+socket.gethostname(),
+ 'priority':'INFO'}
+ self.keystone_user_id = keystone_user_id
+ self.keystone_tenant_id = keystone_tenant_id
+
+ def _get_stat_template(self):
+ retval = copy.copy(self.message_template)
+ retval['message_id'] = six.text_type(uuid.uuid4())
+ retval['timestamp'] = datetime.datetime.now().isoformat()
+ retval['payload'] = {'user_id':self.keystone_user_id,'project_id':self.keystone_tenant_id}
+ return retval
+
+ def get_stat(self,name,event_type,stats={}):
+ retval = self._get_stat_template()
+ retval['event_type']=event_type
+ retval['payload']['resource_id']=name
+ for k,v in stats.iteritems():
+ retval['payload'][k]=v
+ return retval
+
+
+class XaggStatsReader:
+ XAGG_COLUMNS=[
+ {"name":"dn_thruput_min","unit":"kb/s","type":"gauge"},
+ {"name":"dn_thruput_max","unit":"kb/s","type":"gauge"},
+ {"name":"dn_thruput_avg","unit":"kb/s","type":"gauge"},
+ {"name":"up_thruput_min","unit":"kb/s","type":"gauge"},
+ {"name":"up_thruput_max","unit":"kb/s","type":"gauge"},
+ {"name":"up_thruput_avg","unit":"kb/s","type":"gauge"},
+ {"name":"up_byte","unit":"B","type":"cumulative"},
+ {"name":"dn_byte","unit":"B","type":"cumulative"},
+ {"name":"up_pkt","unit":"packet","type":"cumulative"},
+ {"name":"dn_pkt","unit":"packet","type":"cumulative"},
+ {"name":"tcp_rtt","unit":"ms","type":"gauge"},
+ {"name":"tcp_dn_retrans","unit":"packet","type":"gauge"},
+ {"name":"tcp_up_retrans","unit":"packet","type":"gauge"},
+ {"name":"tcp_attempt","unit":"attempt","type":"gauge"},
+ {"name":"tcp_success","unit":"attempt","type":"gauge"}
+ ]
+ CSV_FILE_COLUMNS=["user_src_ip","user_dst_ip","enb_id","customer_group","technology",
+ "handset","os","apn","service_category","service_type","service_name",
+ "application_name","app_attempt","app_success","app_response_time",
+ "dn_byte","dn_thruput_min","dn_thruput_max","dn_thruput_avg","up_byte",
+ "up_thruput_min","up_thruput_max","up_thruput_avg","tcp_dn_retrans",
+ "tcp_up_retrans","dn_pkt","up_pkt","tcp_rtt","tcp_attempt","tcp_success"]
+ def __init__(self, ceilometer_stats):
+ self.stats = ceilometer_stats
+
+ def get_stats(self, csvfile):
+ fp = open(csvfile)
+ f = csv.DictReader(filter(lambda row: row[0] !='#',fp),fieldnames=self.CSV_FILE_COLUMNS)
+ retval = []
+ for row in f:
+ name=row["user_src_ip"]+"_"+row["user_dst_ip"]
+ for stat in self.XAGG_COLUMNS:
+ stat['volume'] = row[stat["name"]]
+ retval.append(self.stats.get_stat(name,"passivetest.stats",stat))
+ return retval
+
+def periodic_publish(rabbit_mq,xagg_stats_reader):
+ for stats_file in glob.glob(XAGG_CSV_DIR+"/*.csv"):
+ if not os.path.isdir(stats_file):
+ stats = xagg_stats_reader.get_stats(stats_file)
+ for stat in stats:
+ rabbit_mq.publish(stat)
+ shutil.move(stats_file,XAGG_CSV_PROCESSED_DIR)
+
+ # Publish every minute
+ threading.Timer(60, periodic_publish, args=(rabbit_mq, xagg_stats_reader)).start()
+
+def main():
+ parser = argparse.ArgumentParser(description='Process xagg telemetry and send to ceilometer/monitoring service.')
+ for arg in ["keystone-tenant-id","keystone-user-id","rabbit-host","rabbit-user","rabbit-password","rabbit-exchange-name"]:
+ parser.add_argument("--"+arg,required=True)
+
+ args = parser.parse_args()
+
+ while True:
+ try:
+ rabbit_mq = RabbitMQ(args.rabbit_host, args.rabbit_user, args.rabbit_password, args.rabbit_exchange_name)
+ ceilometer_stats = CeilometerStats(args.keystone_user_id, args.keystone_tenant_id)
+ xagg_stats_reader = XaggStatsReader(ceilometer_stats)
+ periodic_publish(rabbit_mq,xagg_stats_reader)
+ except Exception as e:
+ print(e)
+ sys.stdout.flush()
+ print("Trying again in one minute...")
+ time.sleep(60)
+
+if __name__ == "__main__":
+ exit(main())
diff --git a/xos/synchronizer/passivetest-synchronizer.py b/xos/synchronizer/passivetest-synchronizer.py
new file mode 100644
index 0000000..90d2c98
--- /dev/null
+++ b/xos/synchronizer/passivetest-synchronizer.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+# Runs the standard XOS synchronizer
+
+import importlib
+import os
+import sys
+
+synchronizer_path = os.path.join(os.path.dirname(
+ os.path.realpath(__file__)), "../../synchronizers/base")
+sys.path.append(synchronizer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
+
diff --git a/xos/synchronizer/passivetest-synchronizer.yaml b/xos/synchronizer/passivetest-synchronizer.yaml
new file mode 100644
index 0000000..b1ad5d3
--- /dev/null
+++ b/xos/synchronizer/passivetest-synchronizer.yaml
@@ -0,0 +1,14 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: This recipe provides additional configuration for the onboarded services.
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ servicecontroller#passivetest:
+ type: tosca.nodes.ServiceController
+ properties:
+ no-create: true
+ synchronizer_config: /root/setup/files/passivetest_config
diff --git a/xos/synchronizer/passivetest_config b/xos/synchronizer/passivetest_config
new file mode 100644
index 0000000..b0f051a
--- /dev/null
+++ b/xos/synchronizer/passivetest_config
@@ -0,0 +1,30 @@
+# Required by XOS
+[db]
+name=xos
+user=postgres
+password=password
+host=xos_db
+port=5432
+
+# Required by XOS
+[api]
+nova_enabled=True
+
+# Sets options for the synchronizer
+[observer]
+name=passivetest
+dependency_graph=/opt/xos/synchronizers/passivetest/model-deps
+steps_dir=/opt/xos/synchronizers/passivetest/steps
+sys_dir=/opt/xos/synchronizers/passivetest/sys
+logfile=/var/log/xos_backend.log
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=True
+proxy_ssh_key=/root/setup/node_key
+proxy_ssh_user=root
+enable_watchers=True
+
+[networking]
+use_vtn=True
+
diff --git a/xos/synchronizer/steps/passivetesttenant_playbook.yaml b/xos/synchronizer/steps/passivetesttenant_playbook.yaml
new file mode 100644
index 0000000..6bbf222
--- /dev/null
+++ b/xos/synchronizer/steps/passivetesttenant_playbook.yaml
@@ -0,0 +1,16 @@
+---
+# passivetesttenant_playbook - sets up the controller
+
+- hosts: "{{ instance_name }}"
+ connection: ssh
+ user: root
+ sudo: yes
+ gather_facts: no
+ vars:
+ - public_ip: "{{ public_ip }}"
+ - synchronizer_ip: "{{ synchronizer_ip }}"
+ - tap_ports: "{{ tap_ports }}"
+ - reset_viv: {{ reset_viv }}
+
+ roles:
+ - setup_probe
diff --git a/xos/synchronizer/steps/roles/setup_probe/files/viv b/xos/synchronizer/steps/roles/setup_probe/files/viv
new file mode 100755
index 0000000..7cd7375
--- /dev/null
+++ b/xos/synchronizer/steps/roles/setup_probe/files/viv
@@ -0,0 +1,268 @@
+#!/usr/bin/env python
+import requests, sys, getopt, json
+
+COMMANDS = [ 'show','reset', 'add','delete','deploy',"V_BUFS","NUM_BUFS", "INPUT_MODE", "TX_MODE", "QUEUE_TYPE" ]
+trafficTypes = ['TSA_CP','TSA_UP', 'TAA_CP', 'TAA_UP']
+INPUT_MODES=["mmap","pfring","pfring_zc","dpdk"]
+TX_MODES=["frp_udp","frp_tcp","viv"]
+QUEUE_TYPES=["CLFFIFO","dpdk"]
+RESOURCE_NAMES = [ 'V_BUFS', 'NUM_BUFS', 'INPUT_MODE', 'TX_MODE', 'QUEUE_TYPE']
+
+settings = {
+ 'ipAddress':'127.0.0.1',
+ 'port':'8080',
+ 'api_version':'v1.0',
+ 'resource': 'vivs/1',
+ 'operation':'GET',
+ 'verbose': False,
+ 'data': None
+ }
+
+class restClient:
+
+ def doIt( self, settings ):
+ try:
+ hdrs = { 'Accept':'application/json','content-type':'application/json' }
+ url = "http://%s:%s/%s" % ( settings['ipAddress'], settings['port'], settings['api_version'] )
+ if settings['resource']:
+ url = "%s/%s" % (url, settings['resource'])
+
+ if settings['operation'] == 'GET':
+ r = requests.get( url, headers = hdrs )
+ elif settings['operation'] == 'POST':
+ data = json.loads(settings['data'])
+ r = requests.post( url, data=json.dumps(data), headers = hdrs )
+
+ if r.status_code == requests.codes.ok:
+ if r.headers['content-type'] == 'application/json':
+ print json.dumps( r.json(), indent=4 )
+ else:
+ print "Received unexpected content type: %s" % r.headers['content-type']
+ if settings['verbose']:
+ print r.text
+
+ if settings['verbose']:
+ print "\nOperation:\n %s" % settings['operation']
+ print "\nURL:\n %s" % r.url
+ print "\nHeaders sent:\n %s" % r.request.headers
+ print "\nResponse status code:\n %s" % r.status_code
+
+ except requests.ConnectionError as e:
+ print e
+ raise # re-raise exception
+ except ValueError as e:
+ print "Invalid JSON: %s" % e
+ raise # re-raise exception
+
+
+def stringFromList( p ):
+ """
+ e.g. ['a', 'b', 'c' ] becomes "[a|b|c]"
+ """
+ return str( p ).replace("'","").replace(", ","|")
+
+def usage():
+ print "Usage:"
+ print " $ %s [-i ip][-p port][-a version][-v] command" % sys.argv[0]
+ print ""
+ print "optional arguments:"
+ print " -i <ip> IP address of server. (Default: 127.0.0.1)"
+ print " -p <port> Port on server. (Default: 8080)"
+ print " -a <version> API version to use. (Default: v1.0)"
+ print " -v Be verbose"
+ print ""
+ print "command"
+ print "-------"
+ print " show [<path>]"
+ print " add input <device> <type> [<type> [...]]"
+ print " add output <ip_address> <port> <type>"
+ print " delete input <device> [<type> [<type> [...]]]"
+ print " delete output <ip_address>[:<port>] [<type> [<type> [...]]]"
+ print " reset"
+ print " deploy"
+ print ""
+ print " V_BUFS <value>"
+ print " NUM_BUFS <value>"
+ print " INPUT_MODE <input-mode>"
+ print " TX_MODE <tx-mode>"
+ print " QUEUE_TYPE <queue-type>"
+ print ""
+ print ""
+ print " Where:"
+ print " <type> = %s" % stringFromList( trafficTypes )
+ print " <input_mode> = %s" % stringFromList(INPUT_MODES )
+ print " <tx-mode> = %s" % stringFromList( QUEUE_TYPES )
+ print ""
+
+
+def getTrafficTypes( args ):
+ traffic_types=[]
+ while len(args) > 0:
+ t = args.pop(0)
+ if t not in trafficTypes:
+ raise ValueError("Invalid traffic type '%s'" % t )
+ traffic_types.append( t )
+ return traffic_types
+
+def parseAddInputCommand( args ):
+ if len( args ) < 2:
+ raise ValueError("Usage: %s add input <device> <traffic_type> [<traffic_type> [...]]" % sys.argv[0] )
+
+ device = args.pop(0)
+ tt = getTrafficTypes( args )
+ data = { "inputs":[{"device":device,"traffic_types":tt}]}
+ settings['resource']='vivs/1/add'
+ settings['operation']='POST'
+ settings['data'] = json.dumps( data )
+
+def parseAddOutputCommand( args ):
+ if len( args ) != 3:
+ raise ValueError("Usage: %s add output <ip_address> <port> <traffic_type>" % sys.argv[0] )
+
+ ip_address = args.pop(0)
+ port = args.pop(0)
+ traffic_type = args.pop(0)
+ if traffic_type not in trafficTypes:
+ raise ValueError("Invalid traffic type '%s'" % traffic_type )
+
+ data = {"outputs":[{"ip_address":ip_address,"type":traffic_type,"port":port}]}
+ settings['resource']='vivs/1/add'
+ settings['operation']='POST'
+ settings['data'] = json.dumps( data )
+
+def parseDeleteInputCommand( args ):
+ if len( args ) < 1:
+ raise ValueError( "Usage: %s delete input <device> [<traffic_type> [<traffic_type> [...]]]" % sys.argv[0] )
+
+ device = args.pop(0)
+ tt = getTrafficTypes( args )
+ data = {"inputs":[{"device":device,"traffic_types":tt}]}
+ settings['resource']='vivs/1/delete'
+ settings['operation']='POST'
+ settings['data'] = json.dumps( data )
+
+def parseDeleteOutputCommand( args ):
+ if len(args) == 0:
+ raise ValueError( "Usage: %s delete output <ip_address>[:<port>] [<traffic_type> [<traffic_type> [...]]]" % sys.argv[0] )
+
+ ipp = args.pop(0).split(':')
+ ip_address = ipp[0]
+ try:
+ port = ipp[1]
+ except IndexError:
+ # No port was specified
+ # All ports with spec'd traffic types will be removed for
+ # the IP given.
+ port = None
+
+ tt = getTrafficTypes( args )
+ data = {"outputs":[{"ip_address":ip_address,"port":port, "traffic_types":tt}]}
+ settings['resource']='vivs/1/delete'
+ settings['operation']='POST'
+ settings['data'] = json.dumps( data )
+
+def parseArgs( argv ):
+ try:
+ opts,args = getopt.getopt( argv,
+ "i:p:a:vh", ["ip=","port=","api_version="])
+ except getopt.GetoptError as e:
+ print e
+ raise # re-raise exception
+ for opt,arg in opts:
+ if opt == '-h':
+ usage()
+ sys.exit()
+ elif opt == '-v':
+ settings['verbose'] = True
+ elif opt in ("-i","--ip"):
+ settings['ipAddress'] = arg
+ elif opt in ("-p","--port"):
+ settings['port'] = arg
+ elif opt in ("-a","--api_version"):
+ settings['api_version'] = arg
+
+ # process residual non option args
+ if len(args) == 0:
+ raise ValueError( "Expected one of: %s" % str( COMMANDS ) )
+
+ cmd = args.pop(0)
+ if cmd not in COMMANDS:
+ print 'Unknown command', cmd
+ sys.exit(1)
+
+ if cmd in ['show']:
+ if len(args) != 0:
+ settings['resource'] = args.pop(0)
+
+ elif cmd in ['reset']:
+ settings['resource']='vivs/1/reset'
+ settings['operation'] = 'POST'
+ settings['data'] = json.dumps( {} )
+
+ elif cmd in ['add']:
+
+ if len(args) == 0:
+ raise ValueError("Expected 'input' or 'output'")
+
+ direction = args.pop(0)
+ if direction not in ['input','output']:
+ raise ValueError( "expected 'input' or 'output', found '%s'" % direction )
+
+ if direction == 'input':
+ parseAddInputCommand( args )
+ else:
+ parseAddOutputCommand( args )
+
+ elif cmd in ['delete']:
+ if len(args) == 0:
+ raise ValueError("Expected 'input' or 'output'" )
+
+ direction = args.pop(0)
+ if direction not in ['input','output']:
+ raise ValueError("expected 'input' or 'output', found '%s'" % direction )
+
+ if direction == 'input':
+ parseDeleteInputCommand( args )
+ else:
+ parseDeleteOutputCommand( args )
+
+ elif cmd in ['deploy']:
+ settings['resource']='vivs/1/deploy'
+ settings['operation'] = 'POST'
+ settings['data'] = '{}'
+
+ else:
+
+ if cmd in RESOURCE_NAMES:
+ if len( args ) == 0 :
+ raise ValueError( 'No value supplied' )
+
+ val = args.pop(0)
+ # The server will complain if it does not like the value.
+ settings['resource']='vivs/1/%s' % cmd
+ settings['operation'] = 'POST'
+ settings['data'] = json.dumps( { cmd : val } )
+
+
+ return settings
+
+
+def RestClient(argv):
+ settings = parseArgs( argv )
+ client = restClient()
+ client.doIt( settings )
+
+
+if __name__ == '__main__':
+ try:
+ RestClient(sys.argv[1:])
+ except ValueError as e:
+ print e
+ sys.exit(2)
+ except getopt.GetoptError as e:
+ print e
+ sys.exit(3)
+ except requests.ConnectionError as e:
+ print e
+ sys.exit(4)
+
diff --git a/xos/synchronizer/steps/roles/setup_probe/tasks/main.yml b/xos/synchronizer/steps/roles/setup_probe/tasks/main.yml
new file mode 100644
index 0000000..ae2d5fb
--- /dev/null
+++ b/xos/synchronizer/steps/roles/setup_probe/tasks/main.yml
@@ -0,0 +1,22 @@
+---
+- name: setup authorized key for user ubuntu since service chaining uses it
+ authorized_key:
+ user: ubuntu
+ key: "{{ lookup('file', 'passivetest_rsa.pub') }}"
+ state: present
+
+- name: copy viv client
+ copy: src=viv dest=/usr/bin mode=0755
+
+- name: reset viv (if needed)
+ shell: viv -i 172.27.0.1 reset
+ when: reset_viv
+
+- name: configure input
+ shell: viv -i 172.27.0.1 add input {{ tap_ports }} TSA_CP
+ ignore_errors: True
+
+- name: register probe with viv
+ shell: viv -i 172.27.0.1 add output {{ synchronizer_ip }} 50002 TSA_CP
+ ignore_errors: True
+
diff --git a/xos/synchronizer/steps/sync_monitoring_agent.yaml b/xos/synchronizer/steps/sync_monitoring_agent.yaml
new file mode 100644
index 0000000..93f805e
--- /dev/null
+++ b/xos/synchronizer/steps/sync_monitoring_agent.yaml
@@ -0,0 +1,36 @@
+---
+- hosts: {{ instance_name }}
+ gather_facts: False
+ connection: ssh
+ user: root
+ vars:
+ keystone_tenant_id: {{ keystone_tenant_id }}
+ keystone_user_id: {{ keystone_user_id }}
+ rabbit_user: {{ rabbit_user }}
+ rabbit_password: {{ rabbit_password }}
+ rabbit_host: {{ rabbit_host }}
+
+ tasks:
+ - name: Verify if monitoring_stats_notifier ([] is to avoid capturing the shell process) job is already running
+ shell: pgrep -f [m]onitoring_stats_notifier | wc -l
+ register: job_pids_count
+
+ - name: make sure /usr/local/share/monitoring_agent exists
+ file: path=/usr/local/share/monitoring_agent state=directory owner=root group=root
+ when: job_pids_count.stdout == "0"
+
+ - name: make a processed file folder
+ file: path=/xsight/var/opt/xagg/tmp/processed state=directory owner=root group=root
+ when: job_pids_count.stdout == "0"
+
+ - name: Copy job to destination
+ copy: src=/opt/xos/synchronizers/passivetest/monitoring_stats_notifier.py
+ dest=/usr/local/share/monitoring_agent/monitoring_stats_notifier.py
+ when: job_pids_count.stdout == "0"
+
+ - name: Initiate monitoring_stats_notifier job
+ command: python /usr/local/share/monitoring_agent/monitoring_stats_notifier.py --keystone-tenant-id={{ keystone_tenant_id }} --keystone-user-id={{ keystone_user_id }} --rabbit-user={{ rabbit_user }} --rabbit-password={{ rabbit_password }} --rabbit-host={{ rabbit_host }} --rabbit-exchange-name='passivetestservice'
+ async: 9999999999999999
+ poll: 0
+ when: job_pids_count.stdout == "0"
+
diff --git a/xos/synchronizer/steps/sync_passivetesttenant.py b/xos/synchronizer/steps/sync_passivetesttenant.py
new file mode 100644
index 0000000..fb60667
--- /dev/null
+++ b/xos/synchronizer/steps/sync_passivetesttenant.py
@@ -0,0 +1,95 @@
+import os
+import sys
+from django.db.models import Q, F
+from services.passivetest.models import PassiveTestService, PassiveTestTenant
+from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from core.models import ModelLink, CoarseTenant, ServiceMonitoringAgentInfo
+from xos.logger import Logger, logging
+from urlparse import urlparse
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+logger = Logger(level=logging.INFO)
+
+class SyncPassiveTestTenant(SyncInstanceUsingAnsible):
+ provides = [PassiveTestTenant]
+ observes = PassiveTestTenant
+ requested_interval = 0
+ template_name = "passivetesttenant_playbook.yaml"
+ service_key_name = "/opt/xos/synchronizers/passivetest/passivetest_private_key"
+ watches = [ModelLink(CoarseTenant,via='coarsetenant'),
+ ModelLink(ServiceMonitoringAgentInfo,via='monitoringagentinfo')]
+
+ def __init__(self, *args, **kwargs):
+ super(SyncPassiveTestTenant, self).__init__(*args, **kwargs)
+
+ def fetch_pending(self, deleted):
+
+ if (not deleted):
+ objs = PassiveTestTenant.get_tenant_objects().filter(
+ Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+ else:
+ # If this is a deletion we get all of the deleted tenants..
+ objs = PassiveTestTenant.get_deleted_tenant_objects()
+
+ return objs
+
+ def get_passivetestservice(self, o):
+ if not o.provider_service:
+ return None
+
+ passivetestservice = PassiveTestService.get_service_objects().filter(id=o.provider_service.id)
+
+ if not passivetestservice:
+ return None
+
+ return passivetestservice[0]
+
+ # Gets the attributes that are used by the Ansible template but are not
+ # part of the set of default attributes.
+ def get_extra_attributes(self, o):
+ passivetestservice = self.get_passivetestservice(o)
+ return { "public_ip": o.public_ip,
+ "synchronizer_ip": o.synchronizer_ip,
+ "tap_ports": passivetestservice.tap_ports,
+ "reset_viv": passivetestservice.reset_viv}
+
+ def handle_service_monitoringagentinfo_watch_notification(self, monitoring_agent_info):
+ if not monitoring_agent_info.service:
+ logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
+ return
+
+ if not monitoring_agent_info.target_uri:
+ logger.info("handle watch notifications for service monitoring agent info...ignoring because target_uri attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
+ return
+
+ objs = PassiveTestTenant.get_tenant_objects().all()
+ for obj in objs:
+ if obj.provider_service.id != monitoring_agent_info.service.id:
+ logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is not matching" % (monitoring_agent_info))
+ return
+
+ instance = self.get_instance(obj)
+ if not instance:
+ logger.warn("handle watch notifications for service monitoring agent info...: No valid instance found for object %s" % (str(obj)))
+ return
+
+ logger.info("handling watch notification for monitoring agent info:%s for PassiveTestTenant object:%s" % (monitoring_agent_info, obj))
+
+ #Run ansible playbook to update the routing table entries in the instance
+ fields = self.get_ansible_fields(instance)
+ fields["ansible_tag"] = obj.__class__.__name__ + "_" + str(obj.id) + "_service_monitoring"
+
+ #Parse the monitoring agent target_uri
+ url = urlparse(monitoring_agent_info.target_uri)
+
+ #Assuming target_uri is rabbitmq URI
+ fields["rabbit_user"] = url.username
+ fields["rabbit_password"] = url.password
+ fields["rabbit_host"] = url.hostname
+
+ template_name = "sync_monitoring_agent.yaml"
+ super(SyncPassiveTestTenant, self).run_playbook(obj, fields, template_name)
+ pass
+
diff --git a/xos/tosca/resources/passivetest.py b/xos/tosca/resources/passivetest.py
new file mode 100644
index 0000000..9ec5d11
--- /dev/null
+++ b/xos/tosca/resources/passivetest.py
@@ -0,0 +1,30 @@
+from core.models import CoarseTenant
+from services.passivetest.models import PassiveTestService
+
+from xosresource import XOSResource
+
+class XOSPassiveTestService(XOSResource):
+ provides = "tosca.nodes.PassiveTest"
+ xos_model = PassiveTestService
+ copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "tap_ports", "reset_viv"]
+
+ def postprocess(self, obj):
+ for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
+ provider_service = self.get_xos_object(PassiveTestService, name=provider_service_name)
+
+ existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj)
+ if existing_tenancy:
+ self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
+ else:
+ tenancy = CoarseTenant(provider_service = provider_service,
+ subscriber_service = obj)
+ tenancy.save()
+
+ self.info("Created Tenancy relationship from %s to %s" % (str(obj), str(provider_service)))
+
+ def can_delete(self, obj):
+ if obj.slices.exists():
+ self.info("Service %s has passive slices; skipping delete" % obj.name)
+ return False
+ return super(XOSPassiveTestService, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/passivetesttenant.py b/xos/tosca/resources/passivetesttenant.py
new file mode 100644
index 0000000..84ac28f
--- /dev/null
+++ b/xos/tosca/resources/passivetesttenant.py
@@ -0,0 +1,29 @@
+from core.models import Tenant, Service
+from services.passivetest.models import PassiveTestTenant
+
+from xosresource import XOSResource
+
+class XOSPassiveTestTenant(XOSResource):
+ provides = "tosca.nodes.PassiveTestTenant"
+ xos_model = PassiveTestTenant
+ name_field = "service_specific_id"
+ copyin_props = ("tenant_message",)
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSPassiveTestTenant, self).get_xos_args()
+
+ # PassiveTestTenant must always have a provider_service
+ provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
+ if provider_name:
+ args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=False)
+ return PassiveTestTenant.get_tenant_objects().filter(provider_service=args["provider_service"], service_specific_id=args["service_specific_id"])
+ return []
+
+ def can_delete(self, obj):
+ return super(XOSPassiveTestTenant, self).can_delete(obj)
+