Merge branch 'master' into feature/syndicate
diff --git a/views/ngXosLib/bower.json b/views/ngXosLib/bower.json
index bc9c23a..5677d00 100644
--- a/views/ngXosLib/bower.json
+++ b/views/ngXosLib/bower.json
@@ -17,7 +17,6 @@
     "angular": "1.4.7",
     "angular-ui-router": "0.2.15",
     "angular-resource": "1.4.7",
-    "ng-lodash": "0.3.0",
     "angular-cookies": "1.4.7",
     "angular-animate": "1.4.7",
     "lodash": "~4.11.1",
diff --git a/views/ngXosLib/generator-xos/app/templates/gulp/build.js b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
index 663a4cf..b66cdbc 100644
--- a/views/ngXosLib/generator-xos/app/templates/gulp/build.js
+++ b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
@@ -98,8 +98,8 @@
   gulp.task('copyHtml', function(){
     return gulp.src(options.src + 'index.html')
       // remove dev dependencies from html
-      .pipe(replace(/<!-- bower:css -->(\n.*)*\n<!-- endbower --><!-- endcss -->/, ''))
-      .pipe(replace(/<!-- bower:js -->(\n.*)*\n<!-- endbower --><!-- endjs -->/, ''))
+      .pipe(replace(/<!-- bower:css -->(\n^<link.*)*\n<!-- endbower -->/gmi, ''))
+      .pipe(replace(/<!-- bower:js -->(\n^<script.*)*\n<!-- endbower -->/gmi, ''))
       // injecting minified files
       .pipe(
         inject(
@@ -150,6 +150,7 @@
   gulp.task('build', function() {
     runSequence(
       'clean',
+      'sass',
       'templates',
       'babel',
       'scripts',
diff --git a/views/ngXosLib/generator-xos/package.json b/views/ngXosLib/generator-xos/package.json
old mode 100755
new mode 100644
index 58b5a33..0098496
--- a/views/ngXosLib/generator-xos/package.json
+++ b/views/ngXosLib/generator-xos/package.json
@@ -4,7 +4,7 @@
   "description": "View generator for XOS",
   "main": "index.js",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "test": "mocha test"
   },
   "author": "Matteo Scandolo",
   "license": "ISC",
@@ -13,5 +13,13 @@
   },
   "files": [
     "app"
-  ]
+  ],
+  "devDependencies": {
+    "mocha": "^2.4.5",
+    "mockery": "^1.7.0",
+    "rimraf": "^2.5.2",
+    "wiredep": "^4.0.0",
+    "yeoman-assert": "^2.2.1",
+    "yeoman-test": "^1.4.0"
+  }
 }
diff --git a/views/ngXosLib/generator-xos/test/build.spec.js b/views/ngXosLib/generator-xos/test/build.spec.js
new file mode 100644
index 0000000..dd49b03
--- /dev/null
+++ b/views/ngXosLib/generator-xos/test/build.spec.js
@@ -0,0 +1,182 @@
+'use strict';
+var path = require('path');
+var helpers = require('yeoman-test');
+var assert = require('yeoman-assert');
+var exec = require('child_process').exec;
+var fs = require('fs');
+const rimraf = require('rimraf');
+
+const getMillisec = min => min * 60 * 1000;
+const deleteFile = file => {
+  if(fs.existsSync(file)){
+    // console.log(`deleting: ${file}`);
+    fs.unlinkSync(file);
+  }
+}
+
+// source files
+const viewName = 'testDashboard';
+const fileName = viewName.replace(/^./, viewName[0].toUpperCase());
+const sourcePath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
+
+// dest files
+const basePath = '../../../../xos/core/xoslib';
+const destHtml = path.join(__dirname, basePath + '/dashboards/xosTestDashboard.html');
+const destJs = path.join(__dirname, basePath + '/static/js/xosTestDashboard.js');
+const destVendor = path.join(__dirname, basePath + '/static/js/vendor/xosTestDashboardVendor.js');
+const destCss = path.join(__dirname, basePath + '/static/css/xosTestDashboard.css');
+
+describe('The XOS Build script', function(){
+  const buildCmd = 'gulp build';
+  
+  this.timeout(getMillisec(5));
+
+  before(done => {
+    console.log('Running generator');
+    this.generator = helpers
+      .run(require.resolve('../app'))
+      .inDir(sourcePath)
+      .withOptions({ 'skip-install': false })
+      .withPrompts({
+        name: viewName,
+        host: 'test-host',
+        token: 'test-token',
+        session: 'test-session'
+      })
+      .on('end', () => {
+        process.stdout.write('Installing Node Modules');
+        let npmInstall = setInterval(() => {
+          process.stdout.write('.');
+        }, 1000);
+        exec('npm install', {
+          cwd: sourcePath
+        }, (err) => {
+          clearInterval(npmInstall);
+          process.stdout.write('\nInstalling Bower Components');
+          let bowerInstall = setInterval(() => {
+            process.stdout.write('.');
+          }, 1000);
+          exec('bower install', {
+            cwd: sourcePath
+          }, (err) => {
+            clearInterval(bowerInstall);
+            done(err);
+          });
+        });
+      });
+  });
+
+  describe('when no styles or vendors are added', () => {
+    
+    before((done) => {
+      process.stdout.write('\nBuilding App');
+      let appBuild = setInterval(() => {
+        process.stdout.write('.');
+      }, 1000);
+      exec(buildCmd, {
+        cwd: sourcePath
+      }, (err) => {
+        console.log(err);
+        clearInterval(appBuild);
+        done(err);
+      });
+    });
+
+    it('should have build the app', () => {
+      assert.file([destHtml, destJs]);
+    });
+
+    it('should include only minified files in the index', () => {
+      assert.fileContent(destHtml, `<script src="/static/js/xos${fileName}.js"></script>`);
+      assert.noFileContent(destHtml, `<!-- bower:css -->`);
+      assert.noFileContent(destHtml, `<!-- bower:js -->`);
+    });
+  });
+
+  describe('when a third party library is added', () => {
+    before((done) => {
+    process.stdout.write('\nInstalling 3rd party library');
+      let bowerInstall = setInterval(() => {
+        process.stdout.write('.');
+      }, 1000);
+      exec('bower install d3 --save', {
+        cwd: sourcePath
+      }, (err, out) => {
+        clearInterval(bowerInstall);
+        process.stdout.write('\nBuilding App');
+        let appBuild = setInterval(() => {
+          process.stdout.write('.');
+        }, 1000);
+        exec(buildCmd, {
+          cwd: sourcePath
+        }, (err) => {
+          console.log(err);
+          clearInterval(appBuild);
+          done(err);
+        }); 
+      });
+    });
+
+    it('should have build the app with a vendor file', () => {
+      assert.file([destHtml, destJs, destVendor]);
+    });
+
+    it('should include only minified files and minified deps in the index', () => {
+      assert.fileContent(destHtml, `<script src="/static/js/xos${fileName}.js"></script>`);
+      assert.fileContent(destHtml, `<script src="/static/js/vendor/xos${fileName}Vendor.js"></script>`);
+      assert.noFileContent(destHtml, `<!-- bower:css -->`);
+      assert.noFileContent(destHtml, `<!-- bower:js -->`);
+    });
+  });
+
+  describe('when some styles are added', () => {
+    before((done) => {
+      let styleContent = `
+        @import '../../../../style/sass/lib/_variables.scss';
+
+        #xosTestDashboard {
+          background: $brand-primary;
+        }
+      `;
+
+      fs.writeFile(`${sourcePath}src/sass/main.scss`, styleContent, function(err) {
+        process.stdout.write('\nBuilding the Application');
+        let appBuild = setInterval(() => {
+          process.stdout.write('.');
+        }, 1000);
+        exec('bower uninstall d3 --save', {
+          cwd: sourcePath
+        }, (err, out) => {
+          exec(buildCmd, {
+            cwd: sourcePath
+          }, (err, out) => {
+            clearInterval(appBuild);
+            done();
+          })
+        })
+      });
+    });
+
+    it('should have build the app with a css file', () => {
+      assert.file([destHtml, destJs, destCss]);
+    });
+
+    it('should include only minified files and minified deps in the index', () => {
+      assert.fileContent(destHtml, `<script src="/static/js/xos${fileName}.js"></script>`);
+      assert.fileContent(destHtml, `<link rel="stylesheet" href="/static/css/xos${fileName}.css">`);
+      assert.noFileContent(destHtml, `<!-- bower:css -->`);
+      assert.noFileContent(destHtml, `<!-- bower:js -->`);
+
+      assert.fileContent(destCss, `background:#337ab7`);
+    });
+  });
+
+  after(done => {
+    // deleting the folder used for test
+    deleteFile(destHtml);
+    deleteFile(destJs);
+    deleteFile(destVendor);
+    deleteFile(destCss);
+    rimraf(sourcePath, {}, done);
+  });
+});
\ No newline at end of file
diff --git a/views/ngXosLib/generator-xos/test/generator.spec.js b/views/ngXosLib/generator-xos/test/generator.spec.js
new file mode 100644
index 0000000..f75f444
--- /dev/null
+++ b/views/ngXosLib/generator-xos/test/generator.spec.js
@@ -0,0 +1,117 @@
+'use strict';
+
+const path = require('path');
+const helpers = require('yeoman-test');
+const assert = require('yeoman-assert');
+const rimraf = require('rimraf');
+const mockery = require('mockery');
+const wiredep = require('wiredep');
+
+const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase())
+
+// get bower deps installed in ngXosLib
+let bowerDeps = wiredep({
+  cwd: path.join(__dirname, '../../'), // pretending to be in the ngXosLib root
+  exclude: ['Chart.js']
+});
+bowerDeps = bowerDeps.js.map(d => d.match(/bower_components\/([a-zA-Z\-`.]+)\//)[1]);
+
+// test values
+const viewName = 'testDashboard';
+const fileName = firstCharTouppercase(viewName);
+const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
+
+const getDefaultFiles = () => {
+  return [
+    '.bowerrc',
+    '.eslintrc',
+    '.gitignore',
+    'bower.json',
+    'gulpfile.js',
+    'karma.conf.js',
+    'package.json',
+    'src/index.html',
+  ].map(i => `${testPath}${i}`);
+};
+
+const yeomanUserMock = {
+  git: {
+    name: () => 'Test User',
+    email: () => 'test@mail.org'
+  }
+}
+
+mockery.enable({
+  warnOnReplace: false,
+  warnOnUnregistered: false,
+  useCleanCache: true,
+});
+mockery.resetCache();
+mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
+
+describe('Yeoman XOS generator', function () {
+
+  beforeEach(() => {
+  });
+
+  before(done => {
+    this.generator = helpers
+      .run(require.resolve('../app'))
+      .inDir(testPath)
+      .withOptions({ 'skip-install': true })
+      .withPrompts({
+        name: viewName,
+        host: 'test-host',
+        token: 'test-token',
+        session: 'test-session'
+      })
+      .on('end', done);
+  });
+
+
+  it('should generate base files in the correct directory', () => {
+    assert.file(getDefaultFiles());
+  });
+
+  it('should create the env file with correct params', () => {
+    assert.fileContent(`${testPath}env/default.js`, 'host: \'test-host\'');
+    assert.fileContent(`${testPath}env/default.js`, 'xoscsrftoken: \'test-token\'');
+    assert.fileContent(`${testPath}env/default.js`, 'xossessionid: \'test-session\'');
+  });
+
+  it('should write username in package & bower json', () => {
+    assert.fileContent(`${testPath}package.json`, '"author": "Test User"');
+    assert.fileContent(`${testPath}bower.json`, '"Test User <test@mail.org>"')
+  });
+
+  it('should add all xosLib dependencies in the dev section of bower.json', () => {
+    bowerDeps.forEach(d => {
+      assert.fileContent(`${testPath}bower.json`, d);
+    });
+  });
+
+  it('should set the right module name in all the files', () => {
+    assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`)
+    assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`)
+    assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
+    assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`)
+  });
+
+  it('should set correct paths in build file', () => {
+    assert.fileContent(`${testPath}gulp/build.js`, `angular.module('xos.${viewName}')`)
+    assert.fileContent(`${testPath}gulp/build.js`, `options.dashboards + 'xos${fileName}.html'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.css'))`)
+    assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.js'))`)
+    assert.fileContent(`${testPath}gulp/build.js`, `module: 'xos.${viewName}'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/vendor/xos${fileName}Vendor.js'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/xos${fileName}.js'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
+    assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}Vendor.js'))`)
+  });
+
+  after(done => {
+    // deleting the folder used for test
+    rimraf(testPath, {}, done)
+  });
+});
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/.bowerrc b/views/ngXosViews/sampleView/.bowerrc
deleted file mode 100644
index e491038..0000000
--- a/views/ngXosViews/sampleView/.bowerrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "directory": "src/vendor/"
-}
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/.eslintrc b/views/ngXosViews/sampleView/.eslintrc
deleted file mode 100644
index c852748..0000000
--- a/views/ngXosViews/sampleView/.eslintrc
+++ /dev/null
@@ -1,42 +0,0 @@
-{
-    "ecmaFeatures": {
-        "blockBindings": true,
-        "forOf": true,
-        "destructuring": true,
-        "arrowFunctions": true,
-        "templateStrings": true
-    },
-    "env": { 
-        "browser": true,
-        "node": true,
-        "es6": true
-    },
-    "plugins": [
-        //"angular"
-    ],
-    "rules": {
-        "quotes": [2, "single"],
-        "camelcase": [1, {"properties": "always"}],
-        "no-underscore-dangle": 1,
-        "eqeqeq": [2, "smart"],
-        "no-alert": 1,
-        "key-spacing": [1, { "beforeColon": false, "afterColon": true }],
-        "indent": [2, 2],
-        "no-irregular-whitespace": 1,
-        "eol-last": 0,
-        "max-nested-callbacks": [2, 4],
-        "comma-spacing": [1, {"before": false, "after": true}],
-        "no-trailing-spaces": [1, { skipBlankLines: true }],
-        "no-unused-vars": [1, {"vars": "all", "args": "after-used"}],
-        "new-cap": 0,
-
-        //"angular/ng_module_name": [2, '/^xos\.*[a-z]*$/'],
-        //"angular/ng_controller_name": [2, '/^[a-z].*Ctrl$/'],
-        //"angular/ng_service_name": [2, '/^[A-Z].*Service$/'],
-        //"angular/ng_directive_name": [2, '/^[a-z]+[[A-Z].*]*$/'],
-        //"angular/ng_di": [0, "function or array"]
-    },
-    "globals" :{
-        "angular": true
-    } 
-}
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/.gitignore b/views/ngXosViews/sampleView/.gitignore
deleted file mode 100644
index 567aee4..0000000
--- a/views/ngXosViews/sampleView/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-dist/
-src/vendor
-.tmp
-node_modules
-npm-debug.log
-dist/
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/bower.json b/views/ngXosViews/sampleView/bower.json
deleted file mode 100644
index 5cc2226..0000000
--- a/views/ngXosViews/sampleView/bower.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
-  "name": "xos-sampleView",
-  "version": "0.0.0",
-  "authors": [
-    "Matteo Scandolo <teo@onlab.us>"
-  ],
-  "description": "The sampleView view",
-  "license": "MIT",
-  "ignore": [
-    "**/.*",
-    "node_modules",
-    "bower_components",
-    "static/js/vendor/",
-    "test",
-    "tests"
-  ],
-  "dependencies": {
-  },
-  "devDependencies": {
-    "jquery": "2.1.4",
-    "angular-mocks": "1.4.7",
-    "angular": "1.4.7",
-    "angular-ui-router": "0.2.15",
-    "angular-cookies": "1.4.7",
-    "angular-animate": "1.4.7",
-    "angular-resource": "1.4.7",
-    "lodash": "~4.11.1",
-    "bootstrap-css": "3.3.6",
-    "angular-chart.js": "~0.10.2"
-  }
-}
diff --git a/views/ngXosViews/sampleView/env/default.js b/views/ngXosViews/sampleView/env/default.js
deleted file mode 100644
index 465003d..0000000
--- a/views/ngXosViews/sampleView/env/default.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// This is a default configuration for your development environment.
-// You can duplicate this configuration for any of your Backend Environments.
-// Different configurations are loaded setting a NODE_ENV variable that contain the config file name.
-// `NODE_ENV=local npm start`
-//
-// If xoscsrftoken or xossessionid are not specified the browser value are used
-// (works only for local environment as both application are served on the same domain)
-
-module.exports = {
-  host: 'http://xos.dev:9999/',
-  xoscsrftoken: 'p5xTzNM2gHDnCpZO4GphloROs0kXmTDX',
-  xossessionid: 'fw0fio7kuwi9z5sm100xtat5cm5jbp5j'
-};
diff --git a/views/ngXosViews/sampleView/gulp/build.js b/views/ngXosViews/sampleView/gulp/build.js
deleted file mode 100644
index 36534fb..0000000
--- a/views/ngXosViews/sampleView/gulp/build.js
+++ /dev/null
@@ -1,163 +0,0 @@
-'use strict';
-
-// BUILD
-//
-// The only purpose of this gulpfile is to build a XOS view and copy the correct files into
-// .html => dashboards
-// .js (minified and concat) => static/js
-//
-// The template are parsed and added to js with angular $templateCache
-
-var gulp = require('gulp');
-var ngAnnotate = require('gulp-ng-annotate');
-var uglify = require('gulp-uglify');
-var templateCache = require('gulp-angular-templatecache');
-var runSequence = require('run-sequence');
-var concat = require('gulp-concat-util');
-var del = require('del');
-var wiredep = require('wiredep');
-var angularFilesort = require('gulp-angular-filesort');
-var _ = require('lodash');
-var eslint = require('gulp-eslint');
-var inject = require('gulp-inject');
-var rename = require('gulp-rename');
-var replace = require('gulp-replace');
-var postcss = require('gulp-postcss');
-var autoprefixer = require('autoprefixer');
-var mqpacker = require('css-mqpacker');
-var csswring = require('csswring');
-
-const TEMPLATE_FOOTER = `
-angular.module('xos.sampleView')
-.run(['$location', function(a){
-  a.path('/');
-}])
-`
-
-module.exports = function(options){
-  
-  // delete previous builded file
-  gulp.task('clean', function(){
-    return del(
-      [
-        options.dashboards + 'xosSampleView.html',
-        options.static + 'css/xosSampleView.css'
-      ],
-      {force: true}
-    );
-  });
-
-  // minify css
-  gulp.task('css', function () {
-    var processors = [
-      autoprefixer({browsers: ['last 1 version']}),
-      mqpacker,
-      csswring
-    ];
-
-    gulp.src([
-      `${options.css}**/*.css`,
-      `!${options.css}dev.css`
-    ])
-    .pipe(postcss(processors))
-    .pipe(gulp.dest(options.tmp + '/css/'));
-  });
-
-  // copy css in correct folder
-  gulp.task('copyCss', ['wait'], function(){
-    return gulp.src([`${options.tmp}/css/*.css`])
-    .pipe(concat('xosSampleView.css'))
-    .pipe(gulp.dest(options.static + 'css/'))
-  });
-
-  // compile and minify scripts
-  gulp.task('scripts', function() {
-    return gulp.src([
-      options.tmp + '**/*.js'
-    ])
-    .pipe(ngAnnotate())
-    .pipe(angularFilesort())
-    .pipe(concat('xosSampleView.js'))
-    .pipe(concat.header('//Autogenerated, do not edit!!!\n'))
-    .pipe(concat.footer(TEMPLATE_FOOTER))
-    .pipe(uglify())
-    .pipe(gulp.dest(options.static + 'js/'));
-  });
-
-  // set templates in cache
-  gulp.task('templates', function(){
-    return gulp.src('./src/templates/*.html')
-      .pipe(templateCache({
-        module: 'xos.sampleView',
-        root: 'templates/'
-      }))
-      .pipe(gulp.dest(options.tmp));
-  });
-
-  // copy html index to Django Folder
-  gulp.task('copyHtml', function(){
-    return gulp.src(options.src + 'index.html')
-      // remove dev dependencies from html
-      .pipe(replace(/<!-- bower:css -->(\n.*)*\n<!-- endbower --><!-- endcss -->/, ''))
-      .pipe(replace(/<!-- bower:js -->(\n.*)*\n<!-- endbower --><!-- endjs -->/, ''))
-      // injecting minified files
-      .pipe(
-        inject(
-          gulp.src([
-            options.static + 'js/vendor/xosSampleViewVendor.js',
-            options.static + 'js/xosSampleView.js',
-            options.static + 'css/xosSampleView.css'
-          ]),
-          {ignorePath: '/../../../xos/core/xoslib'}
-        )
-      )
-      .pipe(rename('xosSampleView.html'))
-      .pipe(gulp.dest(options.dashboards));
-  });
-
-  // minify vendor js files
-  gulp.task('wiredep', function(){
-    var bowerDeps = wiredep().js;
-    if(!bowerDeps){
-      return;
-    }
-
-    // remove angular (it's already loaded)
-    _.remove(bowerDeps, function(dep){
-      return dep.indexOf('angular/angular.js') !== -1;
-    });
-
-    return gulp.src(bowerDeps)
-      .pipe(concat('xosSampleViewVendor.js'))
-      .pipe(uglify())
-      .pipe(gulp.dest(options.static + 'js/vendor/'));
-  });
-
-  gulp.task('lint', function () {
-    return gulp.src(['src/js/**/*.js'])
-      .pipe(eslint())
-      .pipe(eslint.format())
-      .pipe(eslint.failAfterError());
-  });
-
-  gulp.task('wait', function (cb) {
-    // setTimeout could be any async task
-    setTimeout(function () {
-      cb();
-    }, 1000);
-  });
-
-  gulp.task('build', function() {
-    runSequence(
-      'clean',
-      'templates',
-      'babel',
-      'scripts',
-      'wiredep',
-      'css',
-      'copyCss',
-      'copyHtml',
-      'cleanTmp'
-    );
-  });
-};
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/gulp/server.js b/views/ngXosViews/sampleView/gulp/server.js
deleted file mode 100644
index c0678d9..0000000
--- a/views/ngXosViews/sampleView/gulp/server.js
+++ /dev/null
@@ -1,168 +0,0 @@
-'use strict';
-
-var gulp = require('gulp');
-var browserSync = require('browser-sync').create();
-var inject = require('gulp-inject');
-var runSequence = require('run-sequence');
-var angularFilesort = require('gulp-angular-filesort');
-var babel = require('gulp-babel');
-var wiredep = require('wiredep').stream;
-var httpProxy = require('http-proxy');
-var del = require('del');
-var sass = require('gulp-sass');
-
-const environment = process.env.NODE_ENV;
-
-if (environment){
-  var conf = require(`../env/${environment}.js`);
-}
-else{
-  var conf = require('../env/default.js')
-}
-
-var proxy = httpProxy.createProxyServer({
-  target: conf.host || 'http://0.0.0.0:9999'
-});
-
-
-proxy.on('error', function(error, req, res) {
-  res.writeHead(500, {
-    'Content-Type': 'text/plain'
-  });
-
-  console.error('[Proxy]', error);
-});
-
-module.exports = function(options){
-
-  gulp.task('browser', function() {
-    browserSync.init({
-      startPath: '#/',
-      snippetOptions: {
-        rule: {
-          match: /<!-- browserSync -->/i
-        }
-      },
-      server: {
-        baseDir: options.src,
-        routes: {
-          '/xos/core/xoslib/static/js/vendor': options.helpers,
-          '/xos/core/static': options.static + '../../static/'
-        },
-        middleware: function(req, res, next){
-          if(
-            // to be removed, deprecated API
-            // req.url.indexOf('/xos/') !== -1 ||
-            // req.url.indexOf('/xoslib/') !== -1 ||
-            // req.url.indexOf('/hpcapi/') !== -1 ||
-            req.url.indexOf('/api/') !== -1
-          ){
-            if(conf.xoscsrftoken && conf.xossessionid){
-              req.headers.cookie = `xoscsrftoken=${conf.xoscsrftoken}; xossessionid=${conf.xossessionid}`;
-              req.headers['x-csrftoken'] = conf.xoscsrftoken;
-            }
-            proxy.web(req, res);
-          }
-          else{
-            next();
-          }
-        }
-      }
-    });
-
-    gulp.watch(options.src + 'js/**/*.js', ['js-watch']);
-    gulp.watch(options.src + 'vendor/**/*.js', ['bower'], function(){
-      browserSync.reload();
-    });
-    gulp.watch(options.src + '**/*.html', function(){
-      browserSync.reload();
-    });
-    gulp.watch(options.css + '**/*.css', function(){
-      browserSync.reload();
-    });
-    gulp.watch(`${options.sass}/**/*.scss`, ['sass'], function(){
-      browserSync.reload();
-    });
-
-    gulp.watch([
-      options.helpers + 'ngXosHelpers.js',
-      options.static + '../../static/xosNgLib.css'
-    ], function(){
-      browserSync.reload();
-    });
-  });
-
-  // compile sass
-  gulp.task('sass', function () {
-    return gulp.src(`${options.sass}/**/*.scss`)
-      .pipe(sass().on('error', sass.logError))
-      .pipe(gulp.dest(options.css));
-  });
-
-  // transpile js with sourceMaps
-  gulp.task('babel', function(){
-    return gulp.src(options.scripts + '**/*.js')
-      .pipe(babel({sourceMaps: true}))
-      .pipe(gulp.dest(options.tmp));
-  });
-
-  // inject scripts
-  gulp.task('injectScript', ['cleanTmp', 'babel'], function(){
-    return gulp.src(options.src + 'index.html')
-      .pipe(
-        inject(
-          gulp.src([
-            options.tmp + '**/*.js',
-            options.helpers + 'ngXosHelpers.js'
-          ])
-          .pipe(angularFilesort()),
-          {
-            ignorePath: [options.src, '/../../ngXosLib']
-          }
-        )
-      )
-      .pipe(gulp.dest(options.src));
-  });
-
-  // inject CSS
-  gulp.task('injectCss', function(){
-    return gulp.src(options.src + 'index.html')
-      .pipe(
-        inject(
-          gulp.src([
-            options.src + 'css/*.css',
-            options.static + '../../static/xosNgLib.css'
-          ]),
-          {
-            ignorePath: [options.src]
-          }
-          )
-        )
-      .pipe(gulp.dest(options.src));
-  });
-
-  // inject bower dependencies with wiredep
-  gulp.task('bower', function () {
-    return gulp.src(options.src + 'index.html')
-    .pipe(wiredep({devDependencies: true}))
-    .pipe(gulp.dest(options.src));
-  });
-
-  gulp.task('js-watch', ['injectScript'], function(){
-    browserSync.reload();
-  });
-
-  gulp.task('cleanTmp', function(){
-    return del([options.tmp + '**/*']);
-  });
-
-  gulp.task('serve', function() {
-    runSequence(
-      'sass',
-      'bower',
-      'injectScript',
-      'injectCss',
-      ['browser']
-    );
-  });
-};
diff --git a/views/ngXosViews/sampleView/gulpfile.js b/views/ngXosViews/sampleView/gulpfile.js
deleted file mode 100644
index 08df554..0000000
--- a/views/ngXosViews/sampleView/gulpfile.js
+++ /dev/null
@@ -1,26 +0,0 @@
-'use strict';
-
-var gulp = require('gulp');
-var wrench = require('wrench');
-
-var options = {
-  src: 'src/',
-  css: 'src/css/',
-  sass: 'src/sass/',
-  scripts: 'src/js/',
-  tmp: 'src/.tmp',
-  dist: 'dist/',
-  api: '../../ngXosLib/api/',
-  helpers: '../../../xos/core/xoslib/static/js/vendor/',
-  static: '../../../xos/core/xoslib/static/', // this is the django static folder
-  dashboards: '../../../xos/core/xoslib/dashboards/' // this is the django html folder
-};
-
-wrench.readdirSyncRecursive('./gulp')
-.map(function(file) {
-  require('./gulp/' + file)(options);
-});
-
-gulp.task('default', function () {
-  gulp.start('build');
-});
diff --git a/views/ngXosViews/sampleView/karma.conf.js b/views/ngXosViews/sampleView/karma.conf.js
deleted file mode 100644
index 4123be9..0000000
--- a/views/ngXosViews/sampleView/karma.conf.js
+++ /dev/null
@@ -1,88 +0,0 @@
-// Karma configuration
-// Generated on Tue Oct 06 2015 09:27:10 GMT+0000 (UTC)
-
-/* eslint indent: [2,2], quotes: [2, "single"]*/
-
-/*eslint-disable*/
-var wiredep = require('wiredep');
-var path = require('path');
-
-var bowerComponents = wiredep( {devDependencies: true} )[ 'js' ].map(function( file ){
-  return path.relative(process.cwd(), file);
-});
-
-module.exports = function(config) {
-/*eslint-enable*/
-  config.set({
-
-    // base path that will be used to resolve all patterns (eg. files, exclude)
-    basePath: '',
-
-
-    // frameworks to use
-    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
-    frameworks: ['jasmine'],
-
-
-    // list of files / patterns to load in the browser
-    files: bowerComponents.concat([
-      '../../../xos/core/xoslib/static/js/vendor/ngXosVendor.js',
-      '../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js',
-      'src/js/**/*.js',
-      'spec/**/*.mock.js',
-      'spec/**/*.test.js',
-      'src/**/*.html'
-    ]),
-
-
-    // list of files to exclude
-    exclude: [
-    ],
-
-
-    // preprocess matching files before serving them to the browser
-    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
-    preprocessors: {
-      'src/js/**/*.js': ['babel'],
-      'spec/**/*.test.js': ['babel'],
-      'src/**/*.html': ['ng-html2js']
-    },
-
-    ngHtml2JsPreprocessor: {
-      stripPrefix: 'src/', //strip the src path from template url (http://stackoverflow.com/questions/22869668/karma-unexpected-request-when-testing-angular-directive-even-with-ng-html2js)
-      moduleName: 'templates' // define the template module name
-    },
-
-    // test results reporter to use
-    // possible values: 'dots', 'progress'
-    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
-    reporters: ['mocha'],
-
-
-    // web server port
-    port: 9876,
-
-
-    // enable / disable colors in the output (reporters and logs)
-    colors: true,
-
-
-    // level of logging
-    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
-    logLevel: config.LOG_INFO,
-
-
-    // enable / disable watching file and executing tests whenever any file changes
-    autoWatch: true,
-
-
-    // start these browsers
-    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
-    browsers: ['PhantomJS'],
-
-
-    // Continuous Integration mode
-    // if true, Karma captures browsers, runs the tests and exits
-    singleRun: false
-  });
-};
diff --git a/views/ngXosViews/sampleView/package.json b/views/ngXosViews/sampleView/package.json
deleted file mode 100644
index 0ffe32c..0000000
--- a/views/ngXosViews/sampleView/package.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
-  "name": "xos-sampleView",
-  "version": "1.0.0",
-  "description": "Angular Application for XOS, created with generator-xos",
-  "scripts": {
-    "prestart": "npm install && bower install",
-    "start": "gulp serve",
-    "prebuild": "npm install && bower install",
-    "build": "gulp",
-    "test": "karma start",
-    "test:ci": "karma start --single-run",
-    "lint": "eslint src/js/"
-  },
-  "keywords": [
-    "XOS",
-    "Angular",
-    "XOSlib"
-  ],
-  "author": "Matteo Scandolo",
-  "license": "MIT",
-  "dependencies": {},
-  "devDependencies": {
-    "autoprefixer": "^6.3.3",
-    "browser-sync": "^2.9.11",
-    "css-mqpacker": "^4.0.0",
-    "csswring": "^4.2.1",
-    "del": "^2.0.2",
-    "easy-mocker": "^1.2.0",
-    "eslint": "^1.8.0",
-    "eslint-plugin-angular": "linkmesrl/eslint-plugin-angular",
-    "gulp": "^3.9.0",
-    "gulp-angular-filesort": "^1.1.1",
-    "gulp-angular-templatecache": "^1.8.0",
-    "gulp-babel": "^5.3.0",
-    "gulp-concat": "^2.6.0",
-    "gulp-concat-util": "^0.5.5",
-    "gulp-eslint": "^1.0.0",
-    "gulp-inject": "^3.0.0",
-    "gulp-minify-html": "^1.0.4",
-    "gulp-ng-annotate": "^1.1.0",
-    "gulp-postcss": "^6.0.1",
-    "gulp-rename": "^1.2.2",
-    "gulp-replace": "^0.5.4",
-    "gulp-sass": "^2.2.0",
-    "gulp-uglify": "^1.4.2",
-    "http-proxy": "^1.12.0",
-    "ink-docstrap": "^0.5.2",
-    "jasmine-core": "~2.3.4",
-    "karma": "^0.13.14",
-    "karma-babel-preprocessor": "~5.2.2",
-    "karma-coverage": "^0.5.3",
-    "karma-jasmine": "~0.3.6",
-    "karma-mocha-reporter": "~1.1.1",
-    "karma-ng-html2js-preprocessor": "^0.2.0",
-    "karma-phantomjs-launcher": "~0.2.1",
-    "lodash": "^3.10.1",
-    "phantomjs": "^1.9.19",
-    "proxy-middleware": "^0.15.0",
-    "run-sequence": "^1.1.4",
-    "wiredep": "^3.0.0-beta",
-    "wrench": "^1.5.8"
-  }
-}
diff --git a/views/ngXosViews/sampleView/spec/sample.test.js b/views/ngXosViews/sampleView/spec/sample.test.js
deleted file mode 100644
index f0db699..0000000
--- a/views/ngXosViews/sampleView/spec/sample.test.js
+++ /dev/null
@@ -1,37 +0,0 @@
-'use strict';
-
-describe('The User List', () => {
-  
-  var scope, element, isolatedScope, httpBackend;
-
-  beforeEach(module('xos.sampleView'));
-  beforeEach(module('templates'));
-
-  beforeEach(inject(function($httpBackend, $compile, $rootScope){
-    
-    httpBackend = $httpBackend;
-    // Setting up mock request
-    $httpBackend.expectGET('/api/core/users/?no_hyperlinks=1').respond([
-      {
-        email: 'teo@onlab.us',
-        firstname: 'Matteo',
-        lastname: 'Scandolo' 
-      }
-    ]);
-  
-    scope = $rootScope.$new();
-    element = angular.element('<users-list></users-list>');
-    $compile(element)(scope);
-    scope.$digest();
-    isolatedScope = element.isolateScope().vm;
-  }));
-
-  it('should load 1 users', () => {
-    httpBackend.flush();
-    expect(isolatedScope.users.length).toBe(1);
-    expect(isolatedScope.users[0].email).toEqual('teo@onlab.us');
-    expect(isolatedScope.users[0].firstname).toEqual('Matteo');
-    expect(isolatedScope.users[0].lastname).toEqual('Scandolo');
-  });
-
-});
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/src/css/main.css b/views/ngXosViews/sampleView/src/css/main.css
deleted file mode 100644
index e69de29..0000000
--- a/views/ngXosViews/sampleView/src/css/main.css
+++ /dev/null
diff --git a/views/ngXosViews/sampleView/src/index.html b/views/ngXosViews/sampleView/src/index.html
deleted file mode 100644
index df9cb0e..0000000
--- a/views/ngXosViews/sampleView/src/index.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!-- browserSync -->
-<!-- bower:css -->
-<link rel="stylesheet" href="vendor/bootstrap-css/css/bootstrap.min.css" />
-<link rel="stylesheet" href="vendor/angular-chart.js/dist/angular-chart.css" />
-<!-- endbower -->
-<!-- endcss -->
-<!-- inject:css -->
-<link rel="stylesheet" href="/css/main.css">
-<link rel="stylesheet" href="/../../../xos/core/static/xosNgLib.css">
-<!-- endinject -->
-
-<div ng-app="xos.sampleView" id="xosSampleView" class="container-fluid">
-  <div class="row">
-    <div class="col-xs-12">
-      <h1>Hi Matteo!</h1>
-      <h3>Welcome to you development environment.</h3>
-      <p>
-        We provided this environment to help you creating a custom view.
-      </p>
-      <p>
-        When the environment is running you will have an
-        <code>auto-reload</code>
-        feature enabled, so any time you update one of your files, the browser will be reloaded.
-      </p>
-      <p> <i>Note that is environment is already functional and that it is loading information from the XOS APIs and presenting them using the
-          <code>xos-table</code>
-          component.</i> 
-      </p>
-      <h3>Development notes:</h3>
-      <p>
-        This views are designed using
-        <a href="https://angularjs.org/" target="_blank">Angular Js</a>
-        version 1.4.7 and
-        <a href="http://getbootstrap.com/" target="_blank">Bootstrap</a>
-        3.3.6 is included.
-      </p>
-      <p>
-        We just want to remind you that this development environment provide you three helper command:
-        <ul>
-          <li>
-            <code>npm start</code>
-            - will start your setup (you should already be familiar with it)
-          </li>
-          <li>
-            <code>npm test</code>
-            - will execute your unit tests defined with
-            <a href="https://karma-runner.github.io/0.13/index.html" target="_blank">Karma</a>
-            and
-            <a href="jasmine.github.io" target="_blank">Jasmine</a>
-            . You can check the
-            <code>spec/</code>
-            folder to see an example of your first test.
-          </li>
-          <li>
-            <code>npm run build</code>
-            - will build your dashboard and make it available to XOS
-          </li>
-        </ul>
-      </p>
-      <h3>Helpers:</h3>
-      <p>
-        We provide a set of helpers that you can leverage in your dashboard:
-        <ul>
-          <li>
-            <code>xos.helpers</code>
-            - A set of
-            <a href="https://docs.angularjs.org/guide/services" target="_blank">Angular Services</a>
-          </li>
-          <li>
-            <code>xos.uiComponents</code>
-            - A set of
-            <a href="https://docs.angularjs.org/guide/directive" target="_blank">Angular Directives</a>
-          </li>
-          <li>
-            <code>xos.rest</code>
-            - A set of
-            <a href="https://docs.angularjs.org/api/ngResource/service/$resource" target="_blank">Angular $resources</a>
-          </li>
-        </ul>
-        To know more about this helpers you can naviate to
-        <code>/views/ngXosLib/</code>
-        and generate the documentation with
-        <code>npm run doc</code>
-      </p>
-      <h3>Example:</h3>
-    </div>
-  </div>
-  <div ui-view></div>
-</div>
-
-<!-- bower:js -->
-<script src="vendor/jquery/dist/jquery.js"></script>
-<script src="vendor/angular/angular.js"></script>
-<script src="vendor/angular-mocks/angular-mocks.js"></script>
-<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
-<script src="vendor/angular-cookies/angular-cookies.js"></script>
-<script src="vendor/angular-animate/angular-animate.js"></script>
-<script src="vendor/angular-resource/angular-resource.js"></script>
-<script src="vendor/lodash/lodash.js"></script>
-<script src="vendor/bootstrap-css/js/bootstrap.min.js"></script>
-<script src="vendor/Chart.js/Chart.js"></script>
-<script src="vendor/angular-chart.js/dist/angular-chart.js"></script>
-<!-- endbower -->
-<!-- endjs -->
-<!-- inject:js -->
-<script src="/../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js"></script>
-<script src="/.tmp/main.js"></script>
-<!-- endinject -->
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/src/js/main.js b/views/ngXosViews/sampleView/src/js/main.js
deleted file mode 100644
index f008e22..0000000
--- a/views/ngXosViews/sampleView/src/js/main.js
+++ /dev/null
@@ -1,41 +0,0 @@
-'use strict';
-
-angular.module('xos.sampleView', [
-  'ngResource',
-  'ngCookies',
-  'ui.router',
-  'xos.helpers'
-])
-.config(($stateProvider) => {
-  $stateProvider
-  .state('user-list', {
-    url: '/',
-    template: '<users-list></users-list>'
-  });
-})
-.config(function($httpProvider){
-  $httpProvider.interceptors.push('NoHyperlinks');
-})
-.directive('usersList', function(){
-  return {
-    restrict: 'E',
-    scope: {},
-    bindToController: true,
-    controllerAs: 'vm',
-    templateUrl: 'templates/users-list.tpl.html',
-    controller: function(Users){
-
-      this.config = {
-        resource: 'Users',
-        groupBy: 'is_admin',
-        legend: true,
-        poll: 2,
-        labelFormatter: (labels) => {
-          console.log(labels);
-          return labels.map(l => l === 'true' ? 'Admin' : 'Non admin');
-        }
-      };
-      
-    }
-  };
-});
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/src/sass/main.scss b/views/ngXosViews/sampleView/src/sass/main.scss
deleted file mode 100644
index 76ed61e..0000000
--- a/views/ngXosViews/sampleView/src/sass/main.scss
+++ /dev/null
@@ -1,5 +0,0 @@
-@import '../../../../style/sass/lib/_variables.scss';
-
-#xosSampleView {
-  
-}
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/src/templates/users-list.tpl.html b/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
deleted file mode 100644
index 214622c..0000000
--- a/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<!-- <xos-table config="vm.tableConfig" data="vm.users"></xos-table> -->
-<xos-smart-pie config="vm.config"></xos-smart-pie>
\ No newline at end of file
diff --git a/xos/configurations/cord-pod/README-Tutorial.md b/xos/configurations/cord-pod/README-Tutorial.md
index 4bd68c5..94f5170 100644
--- a/xos/configurations/cord-pod/README-Tutorial.md
+++ b/xos/configurations/cord-pod/README-Tutorial.md
@@ -84,11 +84,9 @@
 ubuntu@xos:~/xos/xos/configurations/cord-pod$ make exampleservice
 ```
 
-Next, in the XOS UI, create an ExampleTenant. Go to *http://xos/admin/exampleservice*
-([caveat](https://github.com/open-cloud/xos/blob/master/xos/configurations/cord-pod/README.md#logging-into-xos-on-cloudlab-or-any-remote-host))
-and add / save an Example Tenant.  When creating the tenant, fill in a message that
-this tenant should display.  This will cause an Instance to be created
-in the the *mysite_exampleservice* slice.
+This will add the ExampleService to XOS.  It will also create an ExampleTenant,
+which causes a VM to be created with Apache running inside.
+
 
 ## Set up a Subscriber Device
 
diff --git a/xos/configurations/cord-pod/pod-exampleservice.yaml b/xos/configurations/cord-pod/pod-exampleservice.yaml
index ec45bb8..23add83 100644
--- a/xos/configurations/cord-pod/pod-exampleservice.yaml
+++ b/xos/configurations/cord-pod/pod-exampleservice.yaml
@@ -4,6 +4,7 @@
 
 imports:
    - custom_types/xos.yaml
+   - custom_types/exampleservice.yaml
 
 topology_template:
   node_templates:
@@ -73,6 +74,15 @@
           kind: exampleservice
           public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
           private_key_fn: /opt/xos/synchronizers/exampleservice/exampleservice_private_key
+          service_message: hello
       artifacts:
           pubkey: /opt/xos/synchronizers/exampleservice/exampleservice_public_key
 
+    tenant#exampletenant1:
+        type: tosca.nodes.ExampleTenant
+        properties:
+            tenant_message: world
+        requirements:
+          - tenant:
+              node: service#exampleservice
+              relationship: tosca.relationships.TenantOfService
diff --git a/xos/tosca/custom_types/exampleservice.m4 b/xos/tosca/custom_types/exampleservice.m4
new file mode 100644
index 0000000..720913e
--- /dev/null
+++ b/xos/tosca/custom_types/exampleservice.m4
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+# compile this with "m4 exampleservice.m4 > exampleservice.yaml"
+
+# include macros
+include(macros.m4)
+
+node_types:
+    tosca.nodes.ExampleService:
+        derived_from: tosca.nodes.Root
+        description: >
+            Example Service
+        capabilities:
+            xos_base_service_caps
+        properties:
+            xos_base_props
+            xos_base_service_props
+            service_message:
+                type: string
+                required: false
+
+    tosca.nodes.ExampleTenant:
+        derived_from: tosca.nodes.Root
+        description: >
+            A Tenant of the example service
+        properties:
+            xos_base_tenant_props
+            tenant_message:
+                type: string
+                required: false
+
diff --git a/xos/tosca/custom_types/exampleservice.yaml b/xos/tosca/custom_types/exampleservice.yaml
new file mode 100644
index 0000000..2cd70dd
--- /dev/null
+++ b/xos/tosca/custom_types/exampleservice.yaml
@@ -0,0 +1,101 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+# compile this with "m4 exampleservice.m4 > exampleservice.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.ExampleService:
+        derived_from: tosca.nodes.Root
+        description: >
+            Example 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.
+            service_message:
+                type: string
+                required: false
+
+    tosca.nodes.ExampleTenant:
+        derived_from: tosca.nodes.Root
+        description: >
+            A Tenant of the example 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
+            tenant_message:
+                type: string
+                required: false
+
diff --git a/xos/tosca/custom_types/macros.m4 b/xos/tosca/custom_types/macros.m4
new file mode 100644
index 0000000..1f48f10
--- /dev/null
+++ b/xos/tosca/custom_types/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/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index e83a22f..28a4205 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -1,90 +1,9 @@
 tosca_definitions_version: tosca_simple_yaml_1_0
 
-# 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
+# compile this with "m4 xos.m4 > xos.yaml"
 
-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
-#
-# compile this with "m4 custom_types/xos.m4 > custom_types/xos.yaml"
+# include macros
+include(macros.m4)
 
 node_types:
     tosca.nodes.Service:
@@ -317,17 +236,6 @@
             xos_base_props
             xos_base_service_props
 
-    tosca.nodes.ExampleService:
-        derived_from: tosca.nodes.Root
-        description: >
-            Example Service
-        capabilities:
-            xos_base_service_caps
-        properties:
-            xos_base_props
-            xos_base_service_props
-
-
     tosca.nodes.Subscriber:
         derived_from: tosca.nodes.Root
         description: XOS subscriber base class.
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index b41a6c7..d83ca09 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -1,5 +1,8 @@
 tosca_definitions_version: tosca_simple_yaml_1_0
 
+# compile this with "m4 xos.m4 > xos.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
@@ -14,8 +17,8 @@
 
 
 # end m4 macros
-#
-# compile this with "m4 custom_types/xos.m4 > custom_types/xos.yaml"
+
+
 
 node_types:
     tosca.nodes.Service:
@@ -667,65 +670,6 @@
                 required: false
                 description: Version number of Service.
 
-    tosca.nodes.ExampleService:
-        derived_from: tosca.nodes.Root
-        description: >
-            Example 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.
-
-
     tosca.nodes.Subscriber:
         derived_from: tosca.nodes.Root
         description: XOS subscriber base class.
diff --git a/xos/tosca/destroy.py b/xos/tosca/destroy.py
index d7f8300..6fa9101 100644
--- a/xos/tosca/destroy.py
+++ b/xos/tosca/destroy.py
@@ -7,9 +7,6 @@
 parentdir = os.path.dirname(currentdir)
 sys.path.append(parentdir)
 
-# a bit of a hack for developing -- run m4 to generate xos.yaml from xos.m4
-os.system("m4 %s/custom_types/xos.m4 > %s/custom_types/xos.yaml" % (currentdir, currentdir))
-
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
 import django
 django.setup()
diff --git a/xos/tosca/makedocs.py b/xos/tosca/makedocs.py
index 6a9e959..2db6db8 100644
--- a/xos/tosca/makedocs.py
+++ b/xos/tosca/makedocs.py
@@ -10,9 +10,6 @@
 parentdir = os.path.dirname(currentdir)
 sys.path.append(parentdir)
 
-# a bit of a hack for developing -- run m4 to generate xos.yaml from xos.m4
-os.system("m4 %s/custom_types/xos.m4 > %s/custom_types/xos.yaml" % (currentdir, currentdir))
-
 """
 {'derived_from': 'tosca.nodes.Root', 'capabilities': {'scalable': {'type': 'tosca.capabilities.Scalable'},
 'service': {'type': 'tosca.capabilities.xos.Service'}}, 'properties': {'icon_url': {'required': False,
diff --git a/xos/tosca/resources/exampleservice.py b/xos/tosca/resources/exampleservice.py
index 9d41807..f26b8b7 100644
--- a/xos/tosca/resources/exampleservice.py
+++ b/xos/tosca/resources/exampleservice.py
@@ -14,7 +14,7 @@
 class XOSExampleService(XOSResource):
     provides = "tosca.nodes.ExampleService"
     xos_model = ExampleService
-    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
+    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"]
 
     def postprocess(self, obj):
         for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
diff --git a/xos/tosca/resources/exampletenant.py b/xos/tosca/resources/exampletenant.py
new file mode 100644
index 0000000..d9239f9
--- /dev/null
+++ b/xos/tosca/resources/exampletenant.py
@@ -0,0 +1,36 @@
+import importlib
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+from core.models import Tenant, Service
+from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND
+
+from xosresource import XOSResource
+
+class XOSExampleTenant(XOSResource):
+    provides = "tosca.nodes.ExampleTenant"
+    xos_model = ExampleTenant
+    name_field = "service_specific_id"
+    copyin_props = ("tenant_message",)
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSExampleTenant, self).get_xos_args()
+
+        # ExampleTenant 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 ExampleTenant.get_tenant_objects().filter(provider_service=args["provider_service"], service_specific_id=args["service_specific_id"])
+        return []
+
+    def can_delete(self, obj):
+        return super(XOSExampleTenant, self).can_delete(obj)
+
diff --git a/xos/tosca/run.py b/xos/tosca/run.py
index 58dc22b..0ba2df9 100644
--- a/xos/tosca/run.py
+++ b/xos/tosca/run.py
@@ -7,9 +7,6 @@
 parentdir = os.path.dirname(currentdir)
 sys.path.append(parentdir)
 
-# a bit of a hack for developing -- run m4 to generate xos.yaml from xos.m4
-os.system("m4 %s/custom_types/xos.m4 > %s/custom_types/xos.yaml" % (currentdir, currentdir))
-
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
 import django
 django.setup()
diff --git a/xos/tosca/samples/exampleservice.yaml b/xos/tosca/samples/exampleservice.yaml
new file mode 100644
index 0000000..5b90ce2
--- /dev/null
+++ b/xos/tosca/samples/exampleservice.yaml
@@ -0,0 +1,47 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup the ExampleService
+
+imports:
+   - custom_types/xos.yaml
+   - custom_types/exampleservice.yaml
+
+topology_template:
+  node_templates:
+
+    mysite:
+      type: tosca.nodes.Site
+
+    mysite_exampleservice:
+      description: This slice holds the ExampleService
+      type: tosca.nodes.Slice
+
+      requirements:
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
+          - exmapleserver:
+              node: service#exampleservice
+              relationship: tosca.relationships.MemberOfService
+
+    service#exampleservice:
+      type: tosca.nodes.ExampleService
+      properties:
+          view_url: /admin/exampleservice/exampleservice/$id$/
+          kind: exampleservice
+          public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
+          private_key_fn: /opt/xos/synchronizers/exampleservice/exampleservice_private_key
+          service_message: hello
+      artifacts:
+          pubkey: /opt/xos/synchronizers/exampleservice/exampleservice_public_key
+
+
+    tenant#exampletenant1:
+        type: tosca.nodes.ExampleTenant
+        properties:
+            tenant_message: world
+        requirements:
+          - tenant:
+              node: service#exampleservice
+              relationship: tosca.relationships.TenantOfService
+