diff --git a/views/ngXosLib/.eslintrc b/views/ngXosLib/.eslintrc
new file mode 100644
index 0000000..cf02168
--- /dev/null
+++ b/views/ngXosLib/.eslintrc
@@ -0,0 +1,41 @@
+{
+    "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": [0, {"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,
+        "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/ngXosLib/.gitignore b/views/ngXosLib/.gitignore
index bb93d68..5df6f2d 100644
--- a/views/ngXosLib/.gitignore
+++ b/views/ngXosLib/.gitignore
@@ -1,2 +1,5 @@
 node_modules
-bower_components
\ No newline at end of file
+bower_components
+docs
+xosHelpers/.tmp
+xos
\ No newline at end of file
diff --git a/views/ngXosLib/README.md b/views/ngXosLib/README.md
index cfce430..2eb73cb 100644
--- a/views/ngXosLib/README.md
+++ b/views/ngXosLib/README.md
@@ -10,9 +10,9 @@
 
 Usage: `npm run apigen`
 
-This tool will automatically generate an angular resource file for each endpoint available in Swagger.
+This tool will automatically generate an angular resource file for each endpoint available in Apiary.
 
->You can generate api related documentation with: `npm run apidoc`. The output is locate in `api/docs`. You can have a list of available method also trough Swagger at `http://localhost:9999/docs/`
+>You can generate api related documentation with: `npm run doc`. The output is locate in `api/docs`. You can have a list of available method also trough Apiary at `http://docs.xos.apiary.io/#`
 
 ### Vendors
 
@@ -21,9 +21,10 @@
 - angular-route
 - angular-resource
 - angular-cookie
+- angular-animate
 - ng-lodash
 
-This libraries are server through Django, so they will not be included in your minified vendor file. To add a library and generate a new file (that will override the old one), you should:
+This libraries are served through Django, so they will not be included in your minified vendor file. To add a library and generate a new file (that will override the old one), you should:
 - enter `ngXosLib` folder
 - run `bower install [myPackage] --save`
 - rebuild the file with `gulp vendor`
@@ -45,12 +46,11 @@
 It will automatically ad a `token` to all your request, eventually you can take advantage of some other services:
 
 - **NoHyperlinks Interceptor**: will add a `?no_hyperlinks=1` to your request, to tell Django to return ids instead of links.
-- **XosApi** wrapper for `/xos` endpoints.
-- **XoslibApi** wrapper for `/xoslib` endpoints.
-- **HpcApi** wrapper for `/hpcapi` endpoints.
 
 >_NOTE: for the API related service, check documentation in [Apigen](#apigen) section._
 
+To develop components inside this folder there is a particular command: `npm run dev`, this will watch the helpers file and rebuild them with sourcemaps. For this reason remember to build them when done developing.
+
 When some changes are applied to this common library it should be rebuilt with: `npm run build`
 
 ### Yo Xos
@@ -85,7 +85,7 @@
 
 To install a local dependency use bower with `--save`. Common modules are saved in `devDependencies` as they already loaded in the Django template.
 
-The `npm start` command is watching your dependencies and will automatically inject it in your `index.html`.
+The `npm start` command is watching your dependencies and will automatically inject them in your `index.html`.
 
 #### Linting
 
@@ -98,6 +98,4 @@
 
 ## TODO
 
-- Use Angular $resource instead of $http
-- Use ngDoc instead of jsDoc
 - Define styleguide (both visual and js) and if needed define some UI components
\ No newline at end of file
diff --git a/views/ngXosLib/api/ng-hpcapi.js b/views/ngXosLib/api/ng-hpcapi.js
deleted file mode 100755
index 762b304..0000000
--- a/views/ngXosLib/api/ng-hpcapi.js
+++ /dev/null
@@ -1,5440 +0,0 @@
-/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.hpcapi', [])
-    .factory('hpcapi', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class hpcapi
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var hpcapi = (function() {
-            function hpcapi(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            hpcapi.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            hpcapi.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            hpcapi.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Api_Root_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Api_Root_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_List_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['resource_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['resource_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_List_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_List_GET
-             * 
-             */
-            hpcapi.prototype.Origin_Server_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['protocol'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: protocol'));
-                    return deferred.promise;
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['protocol'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: protocol'));
-                    return deferred.promise;
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_List_GET
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['prefix'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: prefix'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['prefix'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: prefix'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_List_GET
-             * 
-             */
-            hpcapi.prototype.Service_Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['hpcService'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: hpcService'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['hpcService'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: hpcService'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_List_GET
-             * 
-             */
-            hpcapi.prototype.Content_Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['serviceProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['serviceProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_List_GET
-             * 
-             */
-            hpcapi.prototype.Access_Map_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_List_GET
-             * 
-             */
-            hpcapi.prototype.Site_Map_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return hpcapi;
-        })();
-
-        return hpcapi;
-    }]);
\ No newline at end of file
diff --git a/views/ngXosLib/api/ng-xos.js b/views/ngXosLib/api/ng-xos.js
deleted file mode 100755
index 20ea691..0000000
--- a/views/ngXosLib/api/ng-xos.js
+++ /dev/null
@@ -1,39957 +0,0 @@
-/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.xos', [])
-    .factory('xos', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class xos
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var xos = (function() {
-            function xos(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            xos.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            xos.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            xos.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name xos#Api_Root_GET
-             * 
-             */
-            xos.prototype.Api_Root_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_List_GET
-             * 
-             */
-            xos.prototype.Site_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_List_GET
-             * 
-             */
-            xos.prototype.Service_Attribute_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_List_GET
-             * 
-             */
-            xos.prototype.Controller_Images_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['site_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['site_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_List_GET
-             * 
-             */
-            xos.prototype.Image_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['disk_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: disk_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['container_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: container_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['disk_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: disk_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['container_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: container_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_List_GET
-             * 
-             */
-            xos.prototype.Network_Parameter_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['parameter'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: parameter'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['parameter'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: parameter'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_List_GET
-             * 
-             */
-            xos.prototype.Site_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['location'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: location'));
-                    return deferred.promise;
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['login_base'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: login_base'));
-                    return deferred.promise;
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters['abbreviated_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: abbreviated_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['location'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: location'));
-                    return deferred.promise;
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['login_base'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: login_base'));
-                    return deferred.promise;
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters['abbreviated_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: abbreviated_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_List_GET
-             * 
-             */
-            xos.prototype.Slice_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_List_GET
-             * 
-             */
-            xos.prototype.Tag_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tag_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tag_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_List_GET
-             * 
-             */
-            xos.prototype.Invoice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Slice_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_List_GET
-             * 
-             */
-            xos.prototype.Flavor_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Flavor_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Flavor_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_List_GET
-             * 
-             */
-            xos.prototype.Port_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Port_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Port_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_List_GET
-             * 
-             */
-            xos.prototype.Controller_Site_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_List_GET
-             * 
-             */
-            xos.prototype.Project_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Project_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Project_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_List_GET
-             * 
-             */
-            xos.prototype.Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_List_GET
-             * 
-             */
-            xos.prototype.Network_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['template'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: template'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['template'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: template'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_List_GET
-             * 
-             */
-            xos.prototype.Service_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_List_GET
-             * 
-             */
-            xos.prototype.Service_Class_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['commitment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: commitment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFee'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFee'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['membershipFeeMonths'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFeeMonths'));
-                    return deferred.promise;
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['commitment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: commitment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFee'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFee'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['membershipFeeMonths'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFeeMonths'));
-                    return deferred.promise;
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_List_GET
-             * 
-             */
-            xos.prototype.Payment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Payment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Payment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_List_GET
-             * 
-             */
-            xos.prototype.Subscriber_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_List_GET
-             * 
-             */
-            xos.prototype.Instance_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['node'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: node'));
-                    return deferred.promise;
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['numberCores'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: numberCores'));
-                    return deferred.promise;
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Instance_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['node'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: node'));
-                    return deferred.promise;
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['numberCores'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: numberCores'));
-                    return deferred.promise;
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Instance_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_List_GET
-             * 
-             */
-            xos.prototype.Charge_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['state'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: state'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['object'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['coreHours'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: coreHours'));
-                    return deferred.promise;
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Charge_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['state'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: state'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['object'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['coreHours'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: coreHours'));
-                    return deferred.promise;
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Charge_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_List_GET
-             * 
-             */
-            xos.prototype.Program_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Program_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Program_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_List_GET
-             * 
-             */
-            xos.prototype.Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_List_GET
-             * 
-             */
-            xos.prototype.Usable_Object_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_List_GET
-             * 
-             */
-            xos.prototype.Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_List_GET
-             * 
-             */
-            xos.prototype.Slice_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_List_GET
-             * 
-             */
-            xos.prototype.Node_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site_deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Node_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site_deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Node_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_List_GET
-             * 
-             */
-            xos.prototype.Controller_Network_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_List_GET
-             * 
-             */
-            xos.prototype.Image_Deployments_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_List_GET
-             * 
-             */
-            xos.prototype.Controller_User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_List_GET
-             * 
-             */
-            xos.prototype.Reserved_Resource_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['instance'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: instance'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['resource'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource'));
-                    return deferred.promise;
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['quantity'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: quantity'));
-                    return deferred.promise;
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters['reservationSet'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: reservationSet'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['instance'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: instance'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['resource'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource'));
-                    return deferred.promise;
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['quantity'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: quantity'));
-                    return deferred.promise;
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters['reservationSet'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: reservationSet'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_List_GET
-             * 
-             */
-            xos.prototype.Network_Template_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['visibility'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: visibility'));
-                    return deferred.promise;
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['translation'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: translation'));
-                    return deferred.promise;
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['topology_kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: topology_kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['visibility'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: visibility'));
-                    return deferred.promise;
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['translation'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: translation'));
-                    return deferred.promise;
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['topology_kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: topology_kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_List_GET
-             * 
-             */
-            xos.prototype.Network_Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.User_Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_List_GET
-             * 
-             */
-            xos.prototype.Controller_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['backend_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['version'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: version'));
-                    return deferred.promise;
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['backend_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['version'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: version'));
-                    return deferred.promise;
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_List_GET
-             * 
-             */
-            xos.prototype.User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_List_POST
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['password'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: password'));
-                    return deferred.promise;
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['last_login'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: last_login'));
-                    return deferred.promise;
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['email'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: email'));
-                    return deferred.promise;
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['username'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: username'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['firstname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firstname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['lastname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: lastname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters['timezone'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: timezone'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['password'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: password'));
-                    return deferred.promise;
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['last_login'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: last_login'));
-                    return deferred.promise;
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['email'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: email'));
-                    return deferred.promise;
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['username'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: username'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['firstname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firstname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['lastname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: lastname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters['timezone'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: timezone'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_List_GET
-             * 
-             */
-            xos.prototype.Deployment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters['accessControl'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: accessControl'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters['accessControl'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: accessControl'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_List_GET
-             * 
-             */
-            xos.prototype.Reservation_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['startTime'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: startTime'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters['duration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: duration'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['startTime'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: startTime'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters['duration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: duration'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Site_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_List_GET
-             * 
-             */
-            xos.prototype.Controller_Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_List_GET
-             * 
-             */
-            xos.prototype.Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_List_GET
-             * 
-             */
-            xos.prototype.Account_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Account_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Account_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_List_GET
-             * 
-             */
-            xos.prototype.Controller_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_List_GET
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_List_GET
-             * 
-             */
-            xos.prototype.Site_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Deployment_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['slice_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['slice_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_List_GET
-             * 
-             */
-            xos.prototype.Site_Deployment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_List_GET
-             * 
-             */
-            xos.prototype.Tenant_With_Container_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_List_GET
-             * 
-             */
-            xos.prototype.Deployment_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_List_GET
-             * 
-             */
-            xos.prototype.User_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['tenant_root'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: tenant_root'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['tenant_root'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: tenant_root'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_List_GET
-             * 
-             */
-            xos.prototype.Slice_Tag_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_List_GET
-             * 
-             */
-            xos.prototype.Coarse_Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_List_GET
-             * 
-             */
-            xos.prototype.Router_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Router_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Router_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_List_GET
-             * 
-             */
-            xos.prototype.Service_Resource_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['serviceClass'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceClass'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsDeployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsDeployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxUnitsNode'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsNode'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['maxDuration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxDuration'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketInRate'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketInRate'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['bucketMaxSize'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketMaxSize'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['cost'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cost'));
-                    return deferred.promise;
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['serviceClass'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceClass'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsDeployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsDeployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxUnitsNode'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsNode'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['maxDuration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxDuration'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketInRate'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketInRate'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['bucketMaxSize'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketMaxSize'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['cost'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cost'));
-                    return deferred.promise;
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Service_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return xos;
-        })();
-
-        return xos;
-    }]);
\ No newline at end of file
diff --git a/views/ngXosLib/api/ng-xoslib.js b/views/ngXosLib/api/ng-xoslib.js
deleted file mode 100755
index 16b5d9b..0000000
--- a/views/ngXosLib/api/ng-xoslib.js
+++ /dev/null
@@ -1,6174 +0,0 @@
-/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.xoslib', [])
-    .factory('xoslib', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class xoslib
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var xoslib = (function() {
-            function xoslib(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            xoslib.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            xoslib.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            xoslib.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_List_GET
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_List_POST
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Hpc_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Hpc_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/hpcview/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Hpc_List_GET
-             * 
-             */
-            xoslib.prototype.Hpc_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/hpcview/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/tenantview/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Tenant_List_GET
-             * 
-             */
-            xoslib.prototype.Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/tenantview/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Port_Forwarding_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Port_Forwarding_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/portforwarding/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Port_Forwarding_List_GET
-             * 
-             */
-            xoslib.prototype.Port_Forwarding_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/portforwarding/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Ssh_Key_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Ssh_Key_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/sshkeys/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Ssh_Key_List_GET
-             * 
-             */
-            xoslib.prototype.Ssh_Key_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/sshkeys/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Debug_get_vbng_dump
-             * 
-             */
-            xoslib.prototype.Cord_Debug_get_vbng_dump = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/cord_debug/vbng_dump/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_PUT
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_PATCH
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_List_GET
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_List_POST
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_list
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_list = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_partial_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_partial_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_destroy
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_destroy = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_retrieve
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_retrieve = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_vcpe_synced
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_vcpe_synced = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/vcpe_synced/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_url_filter
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_url_filter = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/url_filter/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_set_url_filter
-             * @param {string} pk - 
-             * @param {string} level - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_set_url_filter = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/url_filter/{level}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{level}', parameters['level']);
-
-                if (parameters['level'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: level'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_services
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_services = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_enable_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_enable_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/true/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_disable_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_disable_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/false/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_users
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/newuser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/newuser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_delete_user
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_delete_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_user_level
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_user_level = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/url_filter/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_set_user_level
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * @param {string} level - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_set_user_level = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/url_filter/{level}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{level}', parameters['level']);
-
-                if (parameters['level'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: level'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_bbsdump
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_bbsdump = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/bbsdump/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_initdemo
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_initdemo = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/initdemo/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_initdemo
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_initdemo = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/initdemo/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_ssiddetail
-             * @param {string} ssid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_ssiddetail = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subidlookup/{ssid}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{ssid}', parameters['ssid']);
-
-                if (parameters['ssid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: ssid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_ssidlist
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_ssidlist = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subidlookup/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_vbng_mapping
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_vbng_mapping = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/vbng_mapping/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_PUT
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_List_GET
-             * 
-             */
-            xoslib.prototype.Cord_User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_List_POST
-             * 
-             */
-            xoslib.prototype.Cord_User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service_specific_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters['vlan_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vlan_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_List_GET
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_List_POST
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service_specific_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters['vlan_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vlan_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_List_GET
-             * 
-             */
-            xoslib.prototype.Slice_Plus_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_List_POST
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return xoslib;
-        })();
-
-        return xoslib;
-    }]);
\ No newline at end of file
diff --git a/views/ngXosLib/apiTemplates/custom-angular-class.mustache b/views/ngXosLib/apiTemplates/custom-angular-class.mustache
deleted file mode 100644
index c92a870..0000000
--- a/views/ngXosLib/apiTemplates/custom-angular-class.mustache
+++ /dev/null
@@ -1,82 +0,0 @@
-/*jshint -W069 */
-/*global angular:false */
-angular.module('{{&moduleName}}', [])
-.factory('{{&className}}', ['$q', '$http', '$rootScope', function($q, $http, $rootScope){
-    'use strict';
-
-    /**
-     * {{&description}}
-     * @class {{&className}}
-     * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-     * @param {string} [domainOrOptions.domain] - The project domain
-     * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-     * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-     * @param {string} [cache] - An angularjs cache implementation
-     */
-    var {{&className}} = (function(){
-        function {{&className}}(options, cache){
-            var domain = (typeof options === 'object') ? options.domain : options;
-            this.domain = typeof(domain) === 'string' ? domain : '{{&domain}}';
-            cache = cache || ((typeof options === 'object') ? options.cache : cache);
-            this.cache = cache;
-            {{#isSecure}}
-                this.token = (typeof options === 'object') ? (options.token ? options.token : {}) : {};
-            {{/isSecure}}
-        }
-
-        {{&className}}.prototype.$on = function($scope, path, handler){
-            var url = domain + path;
-            $scope.$on(url, function(){
-                handler();
-            });
-            return this;
-        };
-
-        {{&className}}.prototype.$broadcast = function(path){
-            var url = domain + path;
-            //cache.remove(url);
-            $rootScope.$broadcast(url);
-            return this;
-        };
-
-        {{&className}}.transformRequest = function(obj) {
-            var str = [];
-            for(var p in obj) {
-                var val = obj[p];
-                if(angular.isArray(val)) {
-                   val.forEach(function(val){
-                     str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                   });
-                } else {
-                   str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                }
-            }
-            return str.join("&");
-        };
-
-        {{#isSecure}}
-            /**
-             * Set Token
-             * @method
-             * @name {{&className}}#setToken
-             * @param {string} value - token's value
-             * @param {string} headerOrQueryName - the header or query name to send the token at
-             * @param {boolean} isQuery - true if send the token as query param, otherwise, send as header param
-             *
-             */
-            {{&className}}.prototype.setToken = function (value, headerOrQueryName, isQuery) {
-                this.token.value = value;
-                this.token.headerOrQueryName = headerOrQueryName;
-                this.token.isQuery = isQuery;
-            };
-        {{/isSecure}}
-
-        {{#methods}}
-            {{> method}}
-        {{/methods}}
-
-  return {{&className}};
-    })();
-
-    return {{&className}};
-}]);
diff --git a/views/ngXosLib/apigen/blueprintToNgResource.js b/views/ngXosLib/apigen/blueprintToNgResource.js
new file mode 100644
index 0000000..2a3cde3
--- /dev/null
+++ b/views/ngXosLib/apigen/blueprintToNgResource.js
@@ -0,0 +1,78 @@
+'use strict';
+
+const protagonist = require('protagonist');
+const fs = require('fs');
+const P = require('bluebird');
+const _ = require('lodash');
+const chalk = require('chalk');
+const Handlebars = require('handlebars');
+const util = require('util');
+const path = require('path');
+
+P.promisifyAll(fs);
+P.promisifyAll(protagonist);
+
+const angualarModuleName = 'xos.helpers'
+
+// format href in angular format
+const formatHref = url => url.replace('{', ':').replace('}', '');
+
+const formatTitle = title => title.split(' ').join('-');
+
+const getParamName = url => url.match(/\{([^)]+)\}/) ? url.match(/\{([^)]+)\}/)[1] : '';
+
+// Get Group description
+const getGroupDescription = (group) => _.find(group, {element: 'copy'}) ? _.find(group, {element: 'copy'}).content.replace(/\n$/, '') : '';
+
+// Loop APIs endpoint
+const loopApiEndpoint = (group) => {
+  // {name: 'ResourceName', attributes: {href: '/ahhsiiis'}}
+  _.remove(group, {element: 'copy'})
+  // console.log(group);
+  // _.forEach(group, d => console.log(d));
+
+  return _.map(group, g => {
+    return {
+      name: formatTitle(g.meta.title),
+      param: {href: formatHref(g.attributes.href), name: getParamName(g.attributes.href)},
+    }
+  })
+};
+
+// Loop APIs groups
+const loopApiGroups = (defs) => {
+  if (!Array.isArray(defs)) {
+    return;
+  }
+  _.forEach(defs, d => {
+    console.info(chalk.blue.bold(`Parsing Group: ${d.meta.title}`));
+    var data = {
+      description: getGroupDescription(d.content),
+      ngModule: angualarModuleName,
+      resources: loopApiEndpoint(d.content)
+    };
+    fs.writeFileSync(path.join(__dirname, `../xosHelpers/src/services/rest/${formatTitle(d.meta.title)}.js`), handlebarsTemplate(data));
+  });
+
+  console.info(chalk.green.bold(`Api Generated`));
+
+};
+
+// Loop the top level definitions
+const loopApiDefinitions = (defs) => {
+  // console.log(util.inspect(defs, false, null));
+  _.forEach(defs, d => loopApiGroups(d.content));
+};
+
+let handlebarsTemplate;
+
+// read blueprint docs and parse
+fs.readFileAsync(path.join(__dirname, './ngResourceTemplate.handlebars'), 'utf8')
+.then((template) => {
+  handlebarsTemplate = Handlebars.compile(template);
+  return fs.readFileAsync(path.join(__dirname, '../../../xos/tests/api/apiary.apib'), 'utf8')
+})
+.then(data => protagonist.parseAsync(data))
+.then(result => loopApiDefinitions(result.content))
+.catch(console.warn);
+
diff --git a/views/ngXosLib/apigen/ngResourceTemplate.handlebars b/views/ngXosLib/apigen/ngResourceTemplate.handlebars
new file mode 100644
index 0000000..6176633
--- /dev/null
+++ b/views/ngXosLib/apigen/ngResourceTemplate.handlebars
@@ -0,0 +1,15 @@
+(function() {
+  'use strict';
+
+  angular.module('{{ngModule}}')
+  {{#each resources}}
+  /**
+  * @ngdoc service
+  * @name {{../ngModule}}.{{name}}
+  * @description Angular resource to fetch {{param.href}}
+  **/
+  .service('{{name}}', function($resource){
+    return $resource('{{param.href}}'{{#if param.name}}, { {{param.name}}: '@id' }{{/if}});
+  })
+  {{/each}}
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/bower.json b/views/ngXosLib/bower.json
index 71777ba..3726b85 100644
--- a/views/ngXosLib/bower.json
+++ b/views/ngXosLib/bower.json
@@ -18,7 +18,8 @@
     "angular-ui-router": "0.2.15",
     "angular-resource": "1.4.7",
     "ng-lodash": "0.3.0",
-    "angular-cookies": "1.4.7"
+    "angular-cookies": "1.4.7",
+    "angular-animate": "1.4.7"
   },
   "devDependencies": {
     "angular-mocks": "1.4.7"
diff --git a/views/ngXosLib/generator-xos/app/templates/bower.json b/views/ngXosLib/generator-xos/app/templates/bower.json
index 667a7ac..721e2de 100644
--- a/views/ngXosLib/generator-xos/app/templates/bower.json
+++ b/views/ngXosLib/generator-xos/app/templates/bower.json
@@ -22,8 +22,9 @@
     "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",
     "ng-lodash": "0.3.0",
-    "bootstrap-css": "2.3.2"
+    "bootstrap-css": "3.3.6"
   }
 }
diff --git a/views/ngXosLib/generator-xos/app/templates/gulp/build.js b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
index bd31a25..663a4cf 100644
--- a/views/ngXosLib/generator-xos/app/templates/gulp/build.js
+++ b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
@@ -13,7 +13,7 @@
 var uglify = require('gulp-uglify');
 var templateCache = require('gulp-angular-templatecache');
 var runSequence = require('run-sequence');
-var concat = require('gulp-concat');
+var concat = require('gulp-concat-util');
 var del = require('del');
 var wiredep = require('wiredep');
 var angularFilesort = require('gulp-angular-filesort');
@@ -22,31 +22,31 @@
 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.<%= name %>')
+.run(['$location', function(a){
+  a.path('/');
+}])
+`
 
 module.exports = function(options){
   
   // delete previous builded file
   gulp.task('clean', function(){
     return del(
-      [options.dashboards + 'xos<%= fileName %>.html'],
+      [
+        options.dashboards + 'xos<%= fileName %>.html',
+        options.static + 'css/xos<%= fileName %>.css'
+      ],
       {force: true}
     );
   });
 
-  // inject CSS
-  gulp.task('injectCss', function(){
-    return gulp.src(options.src + 'index.html')
-      .pipe(
-        inject(
-          gulp.src(options.src + 'css/*.css'),
-          {
-            ignorePath: [options.src]
-          }
-          )
-        )
-      .pipe(gulp.dest(options.src));
-  });
-
   // minify css
   gulp.task('css', function () {
     var processors = [
@@ -64,9 +64,9 @@
   });
 
   // copy css in correct folder
-  gulp.task('copyCss', ['css'], function(){
+  gulp.task('copyCss', ['wait'], function(){
     return gulp.src([`${options.tmp}/css/*.css`])
-    .pipe(concat('xosDiagnostic.css'))
+    .pipe(concat('xos<%= fileName %>.css'))
     .pipe(gulp.dest(options.static + 'css/'))
   });
 
@@ -78,6 +78,8 @@
     .pipe(ngAnnotate())
     .pipe(angularFilesort())
     .pipe(concat('xos<%= fileName %>.js'))
+    .pipe(concat.header('//Autogenerated, do not edit!!!\n'))
+    .pipe(concat.footer(TEMPLATE_FOOTER))
     .pipe(uglify())
     .pipe(gulp.dest(options.static + 'js/'));
   });
@@ -93,7 +95,7 @@
   });
 
   // copy html index to Django Folder
-  gulp.task('copyHtml', ['clean'], function(){
+  gulp.task('copyHtml', function(){
     return gulp.src(options.src + 'index.html')
       // remove dev dependencies from html
       .pipe(replace(/<!-- bower:css -->(\n.*)*\n<!-- endbower --><!-- endcss -->/, ''))
@@ -103,7 +105,8 @@
         inject(
           gulp.src([
             options.static + 'js/vendor/xos<%= fileName %>Vendor.js',
-            options.static + 'js/xos<%= fileName %>.js'
+            options.static + 'js/xos<%= fileName %>.js',
+            options.static + 'css/xos<%= fileName %>.css'
           ]),
           {ignorePath: '/../../../xos/core/xoslib'}
         )
@@ -137,13 +140,22 @@
       .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',
-      'injectCss',
+      'css',
+      'copyCss',
       'copyHtml',
       'cleanTmp'
     );
diff --git a/views/ngXosLib/generator-xos/app/templates/gulp/server.js b/views/ngXosLib/generator-xos/app/templates/gulp/server.js
index 1c8a0a7..13659c3 100644
--- a/views/ngXosLib/generator-xos/app/templates/gulp/server.js
+++ b/views/ngXosLib/generator-xos/app/templates/gulp/server.js
@@ -50,14 +50,14 @@
       server: {
         baseDir: options.src,
         routes: {
-          '/api': options.api,
           '/xosHelpers/src': options.helpers
         },
         middleware: function(req, res, next){
           if(
             req.url.indexOf('/xos/') !== -1 ||
             req.url.indexOf('/xoslib/') !== -1 ||
-            req.url.indexOf('/hpcapi/') !== -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}`;
@@ -108,8 +108,7 @@
         inject(
           gulp.src([
             options.tmp + '**/*.js',
-            options.api + '*.js',
-            options.helpers + '**/*.js'
+            options.helpers + '**/*.js' // todo add Babel here
           ])
           .pipe(angularFilesort()),
           {
diff --git a/views/ngXosLib/generator-xos/app/templates/karma.conf.js b/views/ngXosLib/generator-xos/app/templates/karma.conf.js
index 83d3f63..4123be9 100644
--- a/views/ngXosLib/generator-xos/app/templates/karma.conf.js
+++ b/views/ngXosLib/generator-xos/app/templates/karma.conf.js
@@ -26,8 +26,8 @@
 
     // list of files / patterns to load in the browser
     files: bowerComponents.concat([
-      '../../static/js/xosApi.js',
-      '../../static/js/vendor/ngXosHelpers.js',
+      '../../../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',
diff --git a/views/ngXosLib/generator-xos/app/templates/package.json b/views/ngXosLib/generator-xos/app/templates/package.json
index 7c0a016..b0f77f9 100644
--- a/views/ngXosLib/generator-xos/app/templates/package.json
+++ b/views/ngXosLib/generator-xos/app/templates/package.json
@@ -8,6 +8,7 @@
     "prebuild": "npm install && bower install",
     "build": "gulp",
     "test": "karma start",
+    "test:ci": "karma start --single-run",
     "lint": "eslint src/js/"
   },
   "keywords": [
@@ -19,28 +20,44 @@
   "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",
-    "gulp-ng-annotate": "^1.1.0",
-    "lodash": "^3.10.1",
-    "eslint": "^1.8.0",
-    "eslint-plugin-angular": "linkmesrl/eslint-plugin-angular",
-    "gulp-eslint": "^1.0.0"
+    "wrench": "^1.5.8"
   }
 }
diff --git a/views/ngXosLib/generator-xos/app/templates/spec/sample.test.js b/views/ngXosLib/generator-xos/app/templates/spec/sample.test.js
index 10a74ad..b00fa5e 100644
--- a/views/ngXosLib/generator-xos/app/templates/spec/sample.test.js
+++ b/views/ngXosLib/generator-xos/app/templates/spec/sample.test.js
@@ -11,7 +11,7 @@
     
     httpBackend = $httpBackend;
     // Setting up mock request
-    $httpBackend.expectGET('/xos/users/?no_hyperlinks=1').respond([
+    $httpBackend.expectGET('/api/core/users/?no_hyperlinks=1').respond([
       {
         email: '<%= user.email %>',
         firstname: '<%= user.firstname %>',
diff --git a/views/ngXosLib/generator-xos/app/templates/src/index.html b/views/ngXosLib/generator-xos/app/templates/src/index.html
index b271d11..eeb0dec 100644
--- a/views/ngXosLib/generator-xos/app/templates/src/index.html
+++ b/views/ngXosLib/generator-xos/app/templates/src/index.html
@@ -4,7 +4,7 @@
 <!-- inject:css -->
 <!-- endinject -->
 
-<div ng-app="xos.<%= name %>" id="xos<%= fileName %>">
+<div ng-app="xos.<%= name %>" id="xos<%= fileName %>" class="container-fluid">
     <div ui-view></div>
 </div>
 
diff --git a/views/ngXosLib/generator-xos/app/templates/src/js/main.js b/views/ngXosLib/generator-xos/app/templates/src/js/main.js
index 878e4eb..9c0e259 100644
--- a/views/ngXosLib/generator-xos/app/templates/src/js/main.js
+++ b/views/ngXosLib/generator-xos/app/templates/src/js/main.js
@@ -24,9 +24,9 @@
     bindToController: true,
     controllerAs: 'vm',
     templateUrl: 'templates/users-list.tpl.html',
-    controller: function(XosApi){
+    controller: function(Users){
       // retrieving user list
-      XosApi.User_List_GET()
+      Users.query().$promise
       .then((users) => {
         this.users = users;
       })
diff --git a/views/ngXosLib/generator-xos/app/templates/src/sass/main.scss b/views/ngXosLib/generator-xos/app/templates/src/sass/main.scss
index 3d8a1c1..6f8a791 100644
--- a/views/ngXosLib/generator-xos/app/templates/src/sass/main.scss
+++ b/views/ngXosLib/generator-xos/app/templates/src/sass/main.scss
@@ -1,3 +1,5 @@
+@import '../../../../style/sass/lib/_variables.scss';
+
 #xos<%=fileName%> {
   
 }
\ No newline at end of file
diff --git a/views/ngXosLib/generator-xos/app/templates/src/templates/users-list.tpl.html b/views/ngXosLib/generator-xos/app/templates/src/templates/users-list.tpl.html
index 2983ad0..fd8d208 100644
--- a/views/ngXosLib/generator-xos/app/templates/src/templates/users-list.tpl.html
+++ b/views/ngXosLib/generator-xos/app/templates/src/templates/users-list.tpl.html
@@ -1,14 +1,16 @@
 <div class="row">
-  <h1>Users List</h1>
-  <p>This is only an example view.</p>
+  <div class="col-xs-12">
+    <h1>Users List</h1>
+    <p>This is only an example view.</p>
+  </div>
 </div>
 <div class="row">
-  <div class="span4">Email</div>
-  <div class="span4">First Name</div>
-  <div class="span4">Last Name</div>
+  <div class="col-xs-4">Email</div>
+  <div class="col-xs-4">First Name</div>
+  <div class="col-xs-4">Last Name</div>
 </div>  
 <div class="row" ng-repeat="user in vm.users">
-  <div class="span4">{{user.email}}</div>
-  <div class="span4">{{user.firstname}}</div>
-  <div class="span4">{{user.lastname}}</div>
+  <div class="col-xs-4">{{user.email}}</div>
+  <div class="col-xs-4">{{user.firstname}}</div>
+  <div class="col-xs-4">{{user.lastname}}</div>
 </div>  
\ No newline at end of file
diff --git a/views/ngXosLib/gulp/ngXosHelpers.js b/views/ngXosLib/gulp/ngXosHelpers.js
index cc68513..f046681 100644
--- a/views/ngXosLib/gulp/ngXosHelpers.js
+++ b/views/ngXosLib/gulp/ngXosHelpers.js
@@ -1,16 +1,119 @@
 var gulp = require('gulp');
 var uglify = require('gulp-uglify');
-var concat = require("gulp-concat");
+var concat = require('gulp-concat');
 var ngAnnotate = require('gulp-ng-annotate');
 var angularFilesort = require('gulp-angular-filesort');
+var gulpDocs = require('gulp-ngdocs');
+var del = require('del');
+var babel = require('gulp-babel');
+const sourcemaps = require('gulp-sourcemaps');
+var browserSync = require('browser-sync').create();
 
 module.exports = function(options){
-  gulp.task('helpers', function(){
-    return gulp.src([options.xosHelperSource + '**/*.js'])
+
+  // transpile js with sourceMaps
+  gulp.task('babel', function(){
+    return gulp.src(options.xosHelperSource + '**/*.js')
+      .pipe(babel({
+        presets: ['es2015']
+      }))
+      .pipe(gulp.dest(options.xosHelperTmp));
+  });
+
+  gulp.task('babelDev', function(){
+    return gulp.src(options.xosHelperSource + '**/*.js')
+      .pipe(sourcemaps.init())
+      .pipe(babel({
+        presets: ['es2015']
+      }))
+      .pipe(sourcemaps.write('./maps'))
+      .pipe(gulp.dest(options.xosHelperTmp));
+  });
+
+  // build
+  gulp.task('helpers', ['babel'], function(){
+    return gulp.src([options.xosHelperTmp + '**/*.js'])
       .pipe(angularFilesort())
       .pipe(concat('ngXosHelpers.js'))
       .pipe(ngAnnotate())
       .pipe(uglify())
       .pipe(gulp.dest(options.ngXosVendor));
   });
+
+  // build Dev (no minify, sourcemaps)
+  gulp.task('helpersDev', ['babelDev'], function(){
+    return gulp.src([options.xosHelperTmp + '**/*.js'])
+      .pipe(angularFilesort())
+      .pipe(concat('ngXosHelpers.js'))
+      .pipe(ngAnnotate())
+      .pipe(gulp.dest(options.ngXosVendor));
+  });
+
+  gulp.task('cleanDocs', function(){
+    return del([options.docs + '**/*']);
+  });
+
+  gulp.task('makeDocs', ['cleanDocs'], function(){
+    var ngOptions = {
+      scripts: [
+        'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js',
+        'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.min.js',
+        `${options.ngXosVendor}ngXosHelpers.js`
+      ],
+      styles: [
+        'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css',
+      ],
+      html5Mode: false,
+      title: 'XOS Helpers documentation',
+      startPage: '/module',
+    }
+
+    return gulpDocs.sections({
+      module: {
+        glob: [
+          options.xosHelperSource + '*.js',
+          options.xosHelperSource + 'services/*.js',
+          options.xosHelperSource + 'ui_components/**/*.js'
+        ],
+        title: 'Module Documentation',
+      },
+      'rest-api': {
+        glob: [
+          options.xosHelperSource + 'services/rest/*.js'
+        ],
+        api: true,
+        title: 'API Documentation',
+      }
+    }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
+  });
+
+  gulp.task('serveDocs', function(){
+    browserSync.init({
+      server: {
+        baseDir: './docs',
+        routes: {
+          '/xos/core/xoslib/static/js/vendor': options.ngXosVendor
+        }
+      }
+    });
+  });
+
+  gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
+    
+    var files = [
+      options.xosHelperSource + '*.js',
+      options.xosHelperSource + 'services/*.js',
+      options.xosHelperSource + 'ui_components/**/*.js'
+    ];
+
+    gulp.watch(files, ['makeDocs']);
+
+    gulp.watch(files, function(){
+      browserSync.reload();
+    });
+  })
+
+  gulp.task('dev', function(){
+    gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
+  });
 };
\ No newline at end of file
diff --git a/views/ngXosLib/gulpfile.js b/views/ngXosLib/gulpfile.js
index d893755..77a5c07 100644
--- a/views/ngXosLib/gulpfile.js
+++ b/views/ngXosLib/gulpfile.js
@@ -5,7 +5,9 @@
 
 var options = {
   ngXosVendor: '../../xos/core/xoslib/static/js/vendor/', //save here the minfied vendor file, this is automatically loaded in the django page
-  xosHelperSource: './xosHelpers/src/'
+  xosHelperSource: './xosHelpers/src/',
+  xosHelperTmp: './xosHelpers/.tmp/',
+  docs: './docs'
 };
 
 wrench.readdirSyncRecursive('./gulp')
diff --git a/views/ngXosLib/karma.conf.js b/views/ngXosLib/karma.conf.js
index 060e7dd..b602d66 100644
--- a/views/ngXosLib/karma.conf.js
+++ b/views/ngXosLib/karma.conf.js
@@ -13,7 +13,7 @@
 
 var files = bowerComponents.concat([
   'api/**/*.js',
-  'xosHelpers/src/*.module.js',
+  'xosHelpers/src/**/*.module.js',
   'xosHelpers/src/**/*.js',
   'xosHelpers/spec/**/*.test.js'
 ]);
@@ -43,7 +43,7 @@
     // preprocess matching files before serving them to the browser
     // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
     preprocessors: {
-      '**/*.test.js': ['babel']
+      'xosHelpers/**/*.js': ['babel'],
     },
 
     babelPreprocessor: {
@@ -86,7 +86,7 @@
 
     // start these browsers
     // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
-    browsers: ['PhantomJS', 'Chrome'],
+    browsers: ['PhantomJS'],
 
 
     // Continuous Integration mode
diff --git a/views/ngXosLib/package.json b/views/ngXosLib/package.json
index b2d092d..9e8906c 100644
--- a/views/ngXosLib/package.json
+++ b/views/ngXosLib/package.json
@@ -5,10 +5,11 @@
   "main": "index.js",
   "scripts": {
     "test": "karma start",
-    "apigen": "node xos-resource-generator.js",
+    "apigen": "node apigen/blueprintToNgResource.js",
     "swagger": "node xos-swagger-def.js",
-    "apidoc": "jsdoc api/ng-xos.js api/ng-xoslib.js api/ng-hpcapi.js -d api/docs",
-    "build": "gulp vendor && gulp helpers"
+    "doc": "gulp docs; cd ./docs",
+    "build": "gulp vendor && gulp helpers",
+    "dev": "gulp dev"
   },
   "author": "Matteo Scandolo",
   "license": "ISC",
@@ -24,10 +25,16 @@
   },
   "devDependencies": {
     "babel-preset-es2015": "^6.6.0",
+    "browser-sync": "^2.12.3",
+    "concat": "^2.0.0",
+    "del": "^2.2.0",
     "gulp": "^3.9.0",
     "gulp-angular-filesort": "^1.1.1",
+    "gulp-babel": "^6.1.2",
     "gulp-concat": "^2.6.0",
     "gulp-ng-annotate": "^1.1.0",
+    "gulp-ngdocs": "^0.2.13",
+    "gulp-sourcemaps": "^1.6.0",
     "gulp-uglify": "^1.4.2",
     "jasmine-core": "^2.4.1",
     "karma": "^0.13.19",
diff --git a/views/ngXosLib/xos-resource-generator.js b/views/ngXosLib/xos-resource-generator.js
deleted file mode 100644
index b24bf9b..0000000
--- a/views/ngXosLib/xos-resource-generator.js
+++ /dev/null
@@ -1,99 +0,0 @@
-'use strict';
-
-var fs = require('fs');
-var CodeGen = require('swagger-js-codegen').CodeGen;
-var fetchSchema = require('fetch-swagger-schema');
-var P = require('bluebird');
-var chalk = require('chalk');
-var concat = require('concat')
-
-/////////////
-// HELPERS //
-/////////////
-
-var fetchSwagger = P.promisify(function(url, done){
-  fetchSchema(url, function(error, schema){
-    if(error) {
-      return done(error);
-    }
-    done(null, schema);
-  });
-});
-
-// Write to file promisified
-var writeToFile = P.promisify(function(file, content, done) {
-  fs.writeFile(file, content, function(err) {
-    if(err) {
-        return done(err);
-    }
-
-    done(null, file + ' has been saved');
-  }); 
-});
-
-var concatFiles = P.promisify(function(files, dest, done){
-  concat(files, dest, function (error) {
-    if(error){
-      return done(error);
-    }
-    done();
-  })
-});
-
-////////////////////
-// generator loop //
-////////////////////
-
-P.coroutine(function*(){
-  
-  var generatedFiles = [];
-
-  console.log(chalk.green('Generating APIs '));
-
-  let mainDef = yield fetchSwagger('http://localhost:9999/docs/api-docs/');
-
-  for(let i = 0; i < mainDef.apis.length; i++){
-    
-    const path = mainDef.apis[i].path.replace('/', '');
-  
-    process.stdout.write(chalk.green(`Starting ${path} generation `));
-    
-    let loader = setInterval(function(){
-      process.stdout.write(chalk.green('.'));
-    }, 500);
-
-
-    let def = yield fetchSwagger(`http://localhost:9999/docs/api-docs/${path}`);
-    yield writeToFile(`api/ng-${path}.js`, CodeGen.getAngularCode({ 
-      moduleName: `xos.${path}`, 
-      className: `${path}`, 
-      swagger: def,
-      lint: false,
-      template: {
-        class: fs.readFileSync('apiTemplates/custom-angular-class.mustache', 'utf-8'),
-        method: fs.readFileSync('node_modules/swagger-js-codegen/templates/method.mustache', 'utf-8'),
-        request: fs.readFileSync('node_modules/swagger-js-codegen/templates/angular-request.mustache', 'utf-8')
-    }
-    }));
-  
-    generatedFiles.push(`api/ng-${path}.js`);
-
-    clearInterval(loader);
-    process.stdout.write('\n');
-  }
-
-  // TODO rewrite concat to minify API
-  // evaluate to use gulp instead to manage this
-  // at least minify
-  yield concatFiles(generatedFiles, '../static/js/xosApi.js');
-
-  console.log(chalk.green('APIs Ready!'));
-
-  process.exit();
-
-})()
-.catch(function(e){
-  process.stdout.write('\n');
-  console.error(e);
-  process.exit(e.code);
-});
diff --git a/views/ngXosLib/xos-swagger-def.js b/views/ngXosLib/xos-swagger-def.js
deleted file mode 100644
index 64db936..0000000
--- a/views/ngXosLib/xos-swagger-def.js
+++ /dev/null
@@ -1,96 +0,0 @@
-// This was generating the files needed from https://github.com/signalfx/swagger-angular-client
-// But this module is not parsing the format in which our Swagger is generating JSON files
-
-'use strict';
-
-var fs = require('fs');
-var CodeGen = require('swagger-js-codegen').CodeGen;
-var fetchSchema = require('fetch-swagger-schema');
-var P = require('bluebird');
-var chalk = require('chalk');
-var concat = require('concat')
-
-/////////////
-// HELPERS //
-/////////////
-
-var fetchSwagger = P.promisify(function(url, done){
-  fetchSchema(url, function(error, schema){
-    if(error) {
-      return done(error);
-    }
-    done(null, schema);
-  });
-});
-
-// Write to file promisified
-var writeToFile = P.promisify(function(file, content, done) {
-  fs.writeFile(file, content, function(err) {
-    if(err) {
-        return done(err);
-    }
-
-    done(null, file + ' has been saved');
-  }); 
-});
-
-var concatFiles = P.promisify(function(files, dest, done){
-  concat(files, dest, function (error) {
-    if(error){
-      return done(error);
-    }
-    done();
-  })
-});
-
-////////////////////
-// generator loop //
-////////////////////
-
-P.coroutine(function*(){
-  
-  var generatedFiles = [];
-
-  console.log(chalk.green('Generating APIs '));
-
-  let mainDef = yield fetchSwagger('http://localhost:9999/docs/api-docs/');
-
-  yield writeToFile(`api/ngXosApi-runtime.js`, `window.XosApi = ${JSON.stringify(mainDef)}`)
-
-  for(let i = 0; i < mainDef.apis.length; i++){
-    
-    const path = mainDef.apis[i].path.replace('/', '');
-  
-    process.stdout.write(chalk.green(`Starting ${path} generation `));
-    
-    let loader = setInterval(function(){
-      process.stdout.write(chalk.green('.'));
-    }, 500);
-
-
-    let def = yield fetchSwagger(`http://localhost:9999/docs/api-docs/${path}`);
-    
-    yield writeToFile(`api/ng-${path}.json`, JSON.stringify(def));
-    yield writeToFile(`api/ng-${path}.js`, `window.${path}Api = ${JSON.stringify(def)}`)
-  
-    generatedFiles.push(`api/ng-${path}.js`);
-
-    clearInterval(loader);
-    process.stdout.write('\n');
-  }
-
-  // TODO rewrite concat to minify API
-  // evaluate to use gulp instead to manage this
-  // at least minify
-  yield concatFiles(generatedFiles, '../static/js/xosApi.js');
-
-  console.log(chalk.green('APIs Ready!'));
-
-  process.exit();
-
-})()
-.catch(function(e){
-  process.stdout.write('\n');
-  console.error(e);
-  process.exit(e.code);
-});
diff --git a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
index 200014d..8901bde 100644
--- a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
+++ b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
@@ -34,6 +34,7 @@
       httpBackend.when('POST', 'http://example.com', null, function(headers) {
         expect(headers['X-CSRFToken']).toBe(fakeToken);
         done();
+        return headers;
       }).respond(200, {name: 'example' });
 
       http.post('http://example.com');
diff --git a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
index 560f4dc..7b6e9d0 100644
--- a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
+++ b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
@@ -9,43 +9,43 @@
 (function () {
   'use strict';
 
-  describe('The NoHyperlinks factory', () => {
+  describe('The xos.helper module', function(){
+    describe('The NoHyperlinks factory', () => {
 
-    let httpProviderObj, httpBackend, http, noHyperlinks;
+      let httpProviderObj, noHyperlinks;
 
-    beforeEach(() => {
-      module(
-        'xos.helpers',
-        ($httpProvider) => {
-          //save our interceptor
-          httpProviderObj = $httpProvider;
-        }
-      );
+      beforeEach(() => {
+        module(
+          'xos.helpers',
+          ($httpProvider) => {
+            //save our interceptor
+            httpProviderObj = $httpProvider;
+          }
+        );
 
-      inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
-        httpBackend = _$httpBackend_;
-        http = _$http_;
-        noHyperlinks = _NoHyperlinks_
+        inject(function (_NoHyperlinks_) {
+          noHyperlinks = _NoHyperlinks_
+        });
+
+        httpProviderObj.interceptors.push('NoHyperlinks');
+
       });
 
-      httpProviderObj.interceptors.push('NoHyperlinks');
+      it('should set NoHyperlinks interceptor', () => {
+        expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
+      });
+
+      it('should attach ?no_hyperlinks=1 to the request url', () => {
+        let result = noHyperlinks.request({url: 'sample.url'});
+        expect(result.url).toEqual('sample.url?no_hyperlinks=1');
+      });
+
+      it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
+        let result = noHyperlinks.request({url: 'sample.html'});
+        expect(result.url).toEqual('sample.html');
+      });
 
     });
-
-    it('should set NoHyperlinks interceptor', () => {
-      expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
-    });
-
-    it('should attach ?no_hyperlinks=1 to the request url', () => {
-      let result = noHyperlinks.request({url: 'sample.url'});
-      expect(result.url).toEqual('sample.url?no_hyperlinks=1');
-    });
-
-    it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
-      let result = noHyperlinks.request({url: 'sample.html'});
-      expect(result.url).toEqual('sample.html');
-    });
-
   });
 })();
 
diff --git a/views/ngXosLib/xosHelpers/spec/ui/alert.test.js b/views/ngXosLib/xosHelpers/spec/ui/alert.test.js
new file mode 100644
index 0000000..c67d03a
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/alert.test.js
@@ -0,0 +1,131 @@
+/**
+ * © OpenCORD
+ *
+ * Created by teone on 4/15/16.
+ */
+
+(function () {
+  'use strict';
+
+  describe('The xos.helper module', function(){
+    describe('The xos-alert component', () => {
+
+      let element, scope, isolatedScope;
+
+      let message = 'Test Error Message';
+
+      beforeEach(module('xos.helpers'));
+
+      it('should throw an error if no config is specified', inject(($compile, $rootScope) => {
+        function errorFunctionWrapper(){
+          $compile(angular.element('<xos-alert></xos-alert>'))($rootScope);
+          $rootScope.$digest();
+        }
+        expect(errorFunctionWrapper).toThrow(new Error('[xosAlert] Please provide a configuration via the "config" attribute'));
+      }));
+
+      describe('when correctly configured', () => {
+        beforeEach(inject(($compile, $rootScope) => {
+
+          scope = $rootScope.$new();
+
+          scope.config = {
+            type: 'danger',
+            closeBtn: true
+          };
+
+          element = angular.element(`<xos-alert config="config">${message}</xos-alert>`);
+          $compile(element)(scope);
+          scope.$digest();
+          isolatedScope = element.isolateScope().vm;
+        }));
+
+        it('should transclude the message', () => {
+          let textContainer = element[0].getElementsByTagName('p')[0];
+          let text = angular.element(textContainer).text();
+          expect(text).toEqual(message)
+        });
+
+        it('should have a close button', () => {
+          let btn = element[0].getElementsByTagName('button');
+          expect(btn.length).toEqual(1);
+        });
+
+        describe('when the close button is clicked', () => {
+          it('should hide the alert', () => {
+            let btn = element[0].getElementsByTagName('button')[0];
+            btn.click();
+            let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+            expect(alert.hasClass('ng-hide')).toBeTruthy();
+          });
+        });
+
+        describe('when autoHide is set', () => {
+
+          let to;
+
+          beforeEach(inject(($compile, $rootScope, $timeout) => {
+            scope = $rootScope.$new();
+
+            scope.config = {
+              type: 'danger',
+              closeBtn: true,
+              autoHide: 500
+            };
+
+            to = $timeout;
+
+            element = angular.element(`<xos-alert config="config">${message}</xos-alert>`);
+            $compile(element)(scope);
+            scope.$digest();
+            isolatedScope = element.isolateScope().vm;
+          }));
+
+          it('should hide the alert', () => {
+            to.flush();
+            expect(isolatedScope.show).toBeFalsy();
+            let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+            expect(alert.hasClass('ng-hide')).toBeTruthy();
+          });
+        });
+
+        describe('when show is set to false', () => {
+
+          beforeEach(inject(($compile, $rootScope) => {
+            scope = $rootScope.$new();
+
+            scope.config = {
+              type: 'danger',
+              closeBtn: true
+            };
+
+            scope.show = false;
+
+            element = angular.element(`<xos-alert config="config" show="show">${message}</xos-alert>`);
+            $compile(element)(scope);
+            scope.$digest();
+            isolatedScope = element.isolateScope().vm;
+          }));
+
+          it('should hide the alert', () => {
+            let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+            expect(alert.hasClass('ng-hide')).toBeTruthy();
+          });
+
+          describe('when show is changed to true', () => {
+            beforeEach(() => {
+              scope.show = true;
+              scope.$digest();
+            });
+
+            it('should show the alert', () => {
+              let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+              expect(alert.hasClass('ng-hide')).toBeFalsy();
+            });
+          });
+        });
+
+      });
+    });
+  });
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js b/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js
new file mode 100644
index 0000000..a8a7482
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js
@@ -0,0 +1,53 @@
+(function () {
+  'use strict';
+
+  describe('The xos.helper module', function(){
+    describe('The xos-pagination component', () => {
+
+      let scope, element, isolatedScope;
+      let cb = jasmine.createSpy('callback')
+
+      beforeEach(module('xos.helpers'));
+
+      beforeEach(inject(function ($compile, $rootScope) {
+        scope = $rootScope.$new();
+
+        scope.pageSize = 2;
+
+        scope.totalElements = 5;
+
+        scope.change = cb;
+
+        element = angular.element('<xos-pagination page-size="pageSize" total-elements="totalElements" change="change"></xos-table>');
+        $compile(element)(scope);
+        scope.$digest();
+        isolatedScope = element.isolateScope().vm;
+      }));
+
+      it('should contain 3 pages', function() {
+        var li = element[0].getElementsByTagName('li');
+        expect(li.length).toEqual(5);
+      });
+
+      it('should call the change function', () => {
+        var li = element[0].getElementsByTagName('li')[3];
+        let link = li.getElementsByTagName('a')[0];
+        link.click();
+        expect(cb).toHaveBeenCalledWith(2);
+      });
+
+      describe('when elements number is less than page size', () => {
+        beforeEach(() => {
+          isolatedScope.pageSize = 10;
+          isolatedScope.totalElements = 9;
+          scope.$digest();
+        });
+
+        it('should not be rendered', () => {
+          var pagination = element[0].getElementsByClassName('pagination');
+          expect(pagination.length).toEqual(0);
+        });
+      });
+    });
+  });
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/spec/ui/table.test.js b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
new file mode 100644
index 0000000..50a5d72
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/table.test.js
@@ -0,0 +1,200 @@
+/**
+ * © OpenCORD
+ *
+ * Created by teone on 3/24/16.
+ */
+
+(function () {
+  'use strict';
+
+  describe('The xos.helper module', function(){
+    describe('The xos-table component', () => {
+
+      beforeEach(module('xos.helpers'));
+
+      it('should throw an error if no config is specified', inject(($compile, $rootScope) => {
+        function errorFunctionWrapper(){
+          $compile(angular.element('<xos-table></xos-table>'))($rootScope);
+          $rootScope.$digest();
+        }
+        expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a configuration via the "config" attribute'));
+      }));
+
+      it('should throw an error if no config columns are specified', inject(($compile, $rootScope) => {
+        function errorFunctionWrapper(){
+          // setup the parent scope
+          let scope = $rootScope.$new();
+          scope.config = 'green';
+          $compile(angular.element('<xos-table config="config"></xos-table>'))(scope);
+          $rootScope.$digest();
+        }
+        expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a columns list in the configuration'));
+      }));
+
+      describe('when basicly configured', function() {
+        var scope, element, isolatedScope;
+
+        beforeEach(inject(function ($compile, $rootScope) {
+          scope = $rootScope.$new();
+
+          scope.config = {
+            columns: [
+              {
+                label: 'Label 1',
+                prop: 'label-1'
+              },
+              {
+                label: 'Label 2',
+                prop: 'label-2'
+              }
+            ]
+          };
+
+          scope.data = [
+            {
+              'label-1': 'Sample 1.1',
+              'label-2': 'Sample 1.2'
+            },
+            {
+              'label-1': 'Sample 2.1',
+              'label-2': 'Sample 2.2'
+            }
+          ]
+
+          element = angular.element('<xos-table config="config" data="data"></xos-table>');
+          $compile(element)(scope);
+          scope.$digest();
+          isolatedScope = element.isolateScope().vm;
+        }));
+
+        it('should contain 2 columns', function() {
+          var th = element[0].getElementsByTagName('th');
+          expect(th.length).toEqual(2);
+          expect(isolatedScope.columns.length).toEqual(2);
+        });
+
+        it('should contain 3 rows', function() {
+          var tr = element[0].getElementsByTagName('tr');
+          expect(tr.length).toEqual(3);
+        });
+
+        describe('when no data are provided', () => {
+          beforeEach(() => {
+            isolatedScope.data = [];
+            scope.$digest();
+          });
+          it('should render an alert', () => {
+            let alert = element[0].getElementsByClassName('alert');
+            let table = element[0].getElementsByTagName('table');
+            expect(alert.length).toEqual(1);
+            expect(table.length).toEqual(1);
+          });
+        });
+
+        describe('when actions are passed', () => {
+
+          let cb = jasmine.createSpy('callback')
+
+          beforeEach(() => {
+            isolatedScope.config.actions = [
+              {
+                label: 'delete',
+                icon: 'remove',
+                cb: cb,
+                color: 'red'
+              }
+            ];
+            scope.$digest();
+          });
+
+          it('should have 3 columns', () => {
+            var th = element[0].getElementsByTagName('th');
+            expect(th.length).toEqual(3);
+            expect(isolatedScope.columns.length).toEqual(2);
+          });
+
+          it('when clicking on action should invoke callback', () => {
+            var link = element[0].getElementsByTagName('a')[0];
+            link.click();
+            expect(cb).toHaveBeenCalledWith(scope.data[0]);
+          });
+        });
+
+        describe('when filter is fulltext', () => {
+          beforeEach(() => {
+            isolatedScope.config.filter = 'fulltext';
+            scope.$digest();
+          });
+
+          it('should render a text field', () => {
+            var textField = element[0].getElementsByTagName('input');
+            expect(textField.length).toEqual(1);
+          });
+
+          describe('and a value is enterd', () => {
+            beforeEach(() => {
+              isolatedScope.query = '2.2';
+              scope.$digest();
+            });
+
+            it('should contain 2 rows', function() {
+              var tr = element[0].getElementsByTagName('tr');
+              expect(tr.length).toEqual(2);
+            });
+          });
+        });
+
+        describe('when filter is field', () => {
+          beforeEach(() => {
+            isolatedScope.config.filter = 'field';
+            scope.$digest();
+          });
+
+          it('should render a text field for each column', () => {
+            var textField = element[0].getElementsByTagName('input');
+            expect(textField.length).toEqual(2);
+          });
+
+          describe('and a value is enterd', () => {
+            beforeEach(() => {
+              isolatedScope.query = {'label-1': '2.1'};
+              scope.$digest();
+            });
+
+            it('should contain 3 rows', function() {
+              var tr = element[0].getElementsByTagName('tr');
+              expect(tr.length).toEqual(3);
+            });
+          });
+        });
+
+        describe('when order is true', () => {
+          beforeEach(() => {
+            isolatedScope.config.order = true;
+            scope.$digest();
+          });
+
+          it('should render a arrows beside', () => {
+            var arrows = element[0].getElementsByTagName('i');
+            expect(arrows.length).toEqual(4);
+          });
+
+          describe('and an order is set', () => {
+            beforeEach(() => {
+              isolatedScope.orderBy = 'label-1';
+              isolatedScope.reverse = true;
+              scope.$digest();
+            });
+
+            it('should orderBy', function() {
+              var tr = element[0].getElementsByTagName('tr');
+              expect(angular.element(tr[1]).text()).toContain('Sample 2.2');
+              expect(angular.element(tr[2]).text()).toContain('Sample 1.1');
+            });
+          });
+        });
+      });
+    });
+  });
+})();
+
diff --git a/views/ngXosLib/xosHelpers/src/services/api.services.js b/views/ngXosLib/xosHelpers/src/services/api.services.js
deleted file mode 100644
index c7384f8..0000000
--- a/views/ngXosLib/xosHelpers/src/services/api.services.js
+++ /dev/null
@@ -1,32 +0,0 @@
-(function() {
-  'use strict';
-
-    angular
-        .module('xos.helpers')
-        .service('XosApi', xosApi)
-        .service('XoslibApi', xoslibApi)
-        .service('HpcApi', hpcApi);
-
-    var xosApiCache, xoslibApiCache, hpcApiCache;
-
-    function xosApi(xos) { 
-      if(!xosApiCache){
-        xosApiCache = new xos({domain: ''});
-      }
-      return xosApiCache;
-    }
-
-    function xoslibApi(xoslib) { 
-      if(!xoslibApiCache){
-        xoslibApiCache = new xoslib({domain: ''});
-      }
-      return xoslibApiCache;
-    }
-
-    function hpcApi(hpcapi) { 
-      if(!hpcApiCache){
-        hpcApiCache = new hpcapi({domain: ''});
-      }
-      return hpcApiCache;
-    }
-})();
diff --git a/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js b/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
index 283e90d..5f87de5 100644
--- a/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
+++ b/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
@@ -1,18 +1,24 @@
 (function() {
-    'use strict';
+  'use strict';
 
-    angular
-        .module('xos.helpers')
-        .factory('SetCSRFToken', setCSRFToken);
+  /**
+  * @ngdoc service
+  * @name xos.helpers.SetCSRFToken
+  * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will the CSRF-Token to your request headers
+  **/
 
-    function setCSRFToken($cookies) {
-      return {
-        request: function(request){
-          if(request.method !== 'GET'){
-            request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken');
-          }
-          return request;
+  angular
+      .module('xos.helpers')
+      .factory('SetCSRFToken', setCSRFToken);
+
+  function setCSRFToken($cookies) {
+    return {
+      request: function(request){
+        if(request.method !== 'GET'){
+          request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken');
         }
-      };
-    }
+        return request;
+      }
+    };
+  }
 })();
diff --git a/views/ngXosLib/xosHelpers/src/services/noHyperlinks.interceptor.js b/views/ngXosLib/xosHelpers/src/services/noHyperlinks.interceptor.js
index 6059f99..af3dd63 100644
--- a/views/ngXosLib/xosHelpers/src/services/noHyperlinks.interceptor.js
+++ b/views/ngXosLib/xosHelpers/src/services/noHyperlinks.interceptor.js
@@ -1,18 +1,24 @@
 (function() {
-    'use strict';
+  'use strict';
 
-    angular
-        .module('xos.helpers')
-        .factory('NoHyperlinks', noHyperlinks);
+  /**
+  * @ngdoc service
+  * @name xos.helpers.NoHyperlinks
+  * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will add ?no_hyperlinks=1 to your api request, that is required by django
+  **/
 
-    function noHyperlinks() { 
-      return {
-        request: function(request){
-          if(request.url.indexOf('.html') === -1){
-            request.url += '?no_hyperlinks=1';
-          }
-          return request;
+  angular
+      .module('xos.helpers')
+      .factory('NoHyperlinks', noHyperlinks);
+
+  function noHyperlinks() {
+    return {
+      request: function(request){
+        if(request.url.indexOf('.html') === -1){
+          request.url += '?no_hyperlinks=1';
         }
-      };
-    }
+        return request;
+      }
+    };
+  }
 })();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Apps.js b/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Apps.js
new file mode 100644
index 0000000..8d4c104
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Apps.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.ONOS-App-Collection
+  * @description Angular resource to fetch /api/tenant/onos/app/
+  **/
+  .service('ONOS-App-Collection', function($resource){
+    return $resource('/api/tenant/onos/app/');
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Services.js b/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Services.js
new file mode 100644
index 0000000..19270e1
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/ONOS-Services.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.ONOS-Services-Collection
+  * @description Angular resource to fetch /api/service/onos/
+  **/
+  .service('ONOS-Services-Collection', function($resource){
+    return $resource('/api/service/onos/');
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Subscribers.js b/views/ngXosLib/xosHelpers/src/services/rest/Subscribers.js
new file mode 100644
index 0000000..ebab252
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Subscribers.js
@@ -0,0 +1,61 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscribers
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/
+  **/
+  .service('Subscribers', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/
+  **/
+  .service('Subscriber-features', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features-uplink_speed
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/uplink_speed/
+  **/
+  .service('Subscriber-features-uplink_speed', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/uplink_speed/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features-downlink_speed
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/downlink_speed/
+  **/
+  .service('Subscriber-features-downlink_speed', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/downlink_speed/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features-cdn
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/cdn/
+  **/
+  .service('Subscriber-features-cdn', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/cdn/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features-uverse
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/uverse/
+  **/
+  .service('Subscriber-features-uverse', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/uverse/', { subscriber_id: '@id' });
+  })
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Subscriber-features-status
+  * @description Angular resource to fetch /api/tenant/cord/subscriber/:subscriber_id/features/status/
+  **/
+  .service('Subscriber-features-status', function($resource){
+    return $resource('/api/tenant/cord/subscriber/:subscriber_id/features/status/', { subscriber_id: '@id' });
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Truckroll.js b/views/ngXosLib/xosHelpers/src/services/rest/Truckroll.js
new file mode 100644
index 0000000..9927967
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Truckroll.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Truckroll-Collection
+  * @description Angular resource to fetch /api/tenant/truckroll/:truckroll_id/
+  **/
+  .service('Truckroll-Collection', function($resource){
+    return $resource('/api/tenant/truckroll/:truckroll_id/', { truckroll_id: '@id' });
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Users.js b/views/ngXosLib/xosHelpers/src/services/rest/Users.js
new file mode 100644
index 0000000..deb18a4
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Users.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.Users
+  * @description Angular resource to fetch /api/core/users/
+  **/
+  .service('Users', function($resource){
+    return $resource('/api/core/users/');
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/vOLT.js b/views/ngXosLib/xosHelpers/src/services/rest/vOLT.js
new file mode 100644
index 0000000..f182c06
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/vOLT.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.vOLT-Collection
+  * @description Angular resource to fetch /api/tenant/cord/volt/:volt_id/
+  **/
+  .service('vOLT-Collection', function($resource){
+    return $resource('/api/tenant/cord/volt/:volt_id/', { volt_id: '@id' });
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/vSG.js b/views/ngXosLib/xosHelpers/src/services/rest/vSG.js
new file mode 100644
index 0000000..121b5a3
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/vSG.js
@@ -0,0 +1,13 @@
+(function() {
+  'use strict';
+
+  angular.module('xos.helpers')
+  /**
+  * @ngdoc service
+  * @name xos.helpers.vSG-Collection
+  * @description Angular resource to fetch /api/service/vsg/
+  **/
+  .service('vSG-Collection', function($resource){
+    return $resource('/api/service/vsg/');
+  })
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js
new file mode 100644
index 0000000..7d7a026
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js
@@ -0,0 +1,145 @@
+/**
+ * © OpenCORD
+ *
+ * Visit http://guide.xosproject.org/devguide/addview/ for more information
+ *
+ * Created by teone on 4/15/16.
+ */
+
+(function () {
+  'use strict';
+
+  angular.module('xos.uiComponents')
+
+  /**
+    * @ngdoc directive
+    * @name xos.uiComponents.directive:xosAlert
+    * @restrict E
+    * @description The xos-alert directive
+    * @param {Object} config The configuration object
+    * ```
+    * {
+    *   type: 'danger', //info, success, warning
+    *   closeBtn: true, //default false
+    *   autoHide: 3000 //delay to automatically hide the alert
+    * }
+    * ```
+    * @param {Boolean=} show Binding to show and hide the alert, default to true
+    * @element ANY
+    * @scope
+    * @example
+  <example module="sampleAlert1">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl1 as vm">
+        <xos-alert config="vm.config1">
+          A sample alert message
+        </xos-alert>
+        <xos-alert config="vm.config2">
+          A sample alert message (with close button)
+        </xos-alert>
+        <xos-alert config="vm.config3">
+          A sample info message
+        </xos-alert>
+        <xos-alert config="vm.config4">
+          A sample success message
+        </xos-alert>
+        <xos-alert config="vm.config5">
+          A sample warning message
+        </xos-alert>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('sampleAlert1', ['xos.uiComponents'])
+      .controller('SampleCtrl1', function(){
+        this.config1 = {
+          type: 'danger'
+        };
+
+        this.config2 = {
+          type: 'danger',
+          closeBtn: true
+        };
+
+        this.config3 = {
+          type: 'info'
+        };
+
+        this.config4 = {
+          type: 'success'
+        };
+
+        this.config5 = {
+          type: 'warning'
+        };
+      });
+    </file>
+  </example>
+
+  <example module="sampleAlert2">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl as vm" class="row">
+        <div class="col-sm-4">
+          <a class="btn btn-default btn-block" ng-show="!vm.show" ng-click="vm.show = true">Show Alert</a>
+          <a class="btn btn-default btn-block" ng-show="vm.show" ng-click="vm.show = false">Hide Alert</a>
+        </div>
+        <div class="col-sm-8">
+          <xos-alert config="vm.config1" show="vm.show">
+            A sample alert message, not displayed by default.
+          </xos-alert>
+        </div>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('sampleAlert2', ['xos.uiComponents'])
+      .controller('SampleCtrl', function(){
+        this.config1 = {
+          type: 'success'
+        };
+
+        this.show = false;
+      });
+    </file>
+  </example>
+  **/
+
+  .directive('xosAlert', function(){
+    return {
+      restrict: 'E',
+      scope: {
+        config: '=',
+        show: '=?'
+      },
+      template: `
+        <div class="alert alert-{{vm.config.type}}" ng-show="vm.show">
+          <button type="button" class="close" ng-if="vm.config.closeBtn" ng-click="vm.dismiss()">
+            <span aria-hidden="true">&times;</span>
+          </button>
+          <p ng-transclude></p>
+        </div>
+      `,
+      transclude: true,
+      bindToController: true,
+      controllerAs: 'vm',
+      controller: function($timeout){
+
+        if(!this.config){
+          throw new Error('[xosAlert] Please provide a configuration via the "config" attribute');
+        }
+
+        // default the value to true
+        this.show = this.show !== false;
+        
+        this.dismiss = () => {
+          this.show = false;
+        }
+
+        if(this.config.autoHide){
+          let to = $timeout(() => {
+            this.dismiss();
+            $timeout.cancel(to);
+          }, this.config.autoHide);
+        }
+      }
+    }
+  })
+})();
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
new file mode 100644
index 0000000..b7b1701
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
@@ -0,0 +1,122 @@
+/**
+ * © OpenCORD
+ *
+ * Visit http://guide.xosproject.org/devguide/addview/ for more information
+ *
+ * Created by teone on 4/15/16.
+ */
+
+(function () {
+  'use strict';
+
+  angular.module('xos.uiComponents')
+
+  /**
+    * @ngdoc directive
+    * @name xos.uiComponents.directive:xosPagination
+    * @restrict E
+    * @description The xos-table directive
+    * @param {Number} pageSize Number of elements per page
+    * @param {Number} totalElements Number of total elements in the collection
+    * @param {Function} change The callback to be triggered on page change.
+    * * @element ANY
+    * @scope
+    * @example
+  <example module="samplePagination">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl1 as vm">
+        <xos-pagination
+          page-size="vm.pageSize"
+          total-elements="vm.totalElements"
+          change="vm.change">
+        </xos-pagination>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('samplePagination', ['xos.uiComponents'])
+      .controller('SampleCtrl1', function(){
+        this.pageSize = 10;
+        this.totalElements = 35;
+        this.change = (pageNumber) => {
+          console.log(pageNumber);
+        }
+      });
+    </file>
+  </example>
+  **/
+
+  .directive('xosPagination', function(){
+    return {
+      restrict: 'E',
+      scope: {
+        pageSize: '=',
+        totalElements: '=',
+        change: '='
+      },
+      template: `
+        <div class="row" ng-if="vm.pageList.length > 1">
+          <div class="col-xs-12 text-center">
+            <ul class="pagination">
+              <li
+                ng-click="vm.goToPage(vm.currentPage - 1)"
+                ng-class="{disabled: vm.currentPage == 0}">
+                <a href="" aria-label="Previous">
+                    <span aria-hidden="true">&laquo;</span>
+                </a>
+              </li>
+              <li ng-repeat="i in vm.pageList" ng-class="{active: i === vm.currentPage}">
+                <a href="" ng-click="vm.goToPage(i)">{{i + 1}}</a>
+              </li>
+              <li
+                ng-click="vm.goToPage(vm.currentPage + 1)"
+                ng-class="{disabled: vm.currentPage == vm.pages - 1}">
+                <a href="" aria-label="Next">
+                    <span aria-hidden="true">&raquo;</span>
+                </a>
+              </li>
+            </ul>
+          </div>
+        </div>
+      `,
+      bindToController: true,
+      controllerAs: 'vm',
+      controller: function($scope){
+        
+        this.currentPage = 0;
+
+        this.goToPage = (n) => {
+          if(n < 0 || n === this.pages){
+            return;
+          }
+          this.currentPage = n;
+          this.change(n);
+        }
+
+        this.createPages = (pages) => {
+          let arr = [];
+          for(var i = 0; i < pages; i++){
+            arr.push(i);
+          }
+          return arr;
+        }
+
+        // watch for data changes
+        $scope.$watch(() => this.totalElements, () => {
+          if(this.totalElements){
+            this.pages = Math.ceil(this.totalElements / this.pageSize);
+            this.pageList = this.createPages(this.pages);
+          }
+        });
+      }
+    }
+  })
+  .filter('pagination', function(){
+    return function(input, start) {
+      if(!input || !angular.isArray(input)){
+        return input;
+      }
+      start = parseInt(start, 10);
+      return input.slice(start);
+    };
+  });
+})();
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
index faeaa26..daca484 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/table.component.js
@@ -9,33 +9,276 @@
 (function () {
   'use strict';
 
-  angular.module('xos.uiComponents.table', [])
+  angular.module('xos.uiComponents')
+
+    /**
+    * @ngdoc directive
+    * @name xos.uiComponents.directive:xosTable
+    * @restrict E
+    * @description The xos-table directive
+    * @param {Object} config The configuration for the component.
+    * ```
+    * {
+    *   columns: [
+    *     {
+    *       label: 'Human readable name',
+    *       prop: 'Property to read in the model object'
+    *     }
+    *   ],
+    *   classes: 'table table-striped table-bordered',
+    *   actions: [ // if defined add an action column
+          {
+            label: 'delete',
+            icon: 'remove', // refers to bootstraps glyphicon
+            cb: (user) => { // receive the model
+              console.log(user);
+            },
+            color: 'red'
+          }
+        ],
+        filter: 'field', // can be by `field` or `fulltext`
+        order: true // whether to show ordering arrows
+    * }
+    * ```
+    * @param {Array} data The data that should be rendered
+    * @element ANY
+    * @scope
+    * @example
+
+  <example module="sampleTable1">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl1 as vm">
+        <xos-table data="vm.data" config="vm.config"></xos-table>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('sampleTable1', ['xos.uiComponents'])
+      .controller('SampleCtrl1', function(){
+        this.config = {
+          columns: [
+            {
+              label: 'First Name', // column title
+              prop: 'name' // property to read in the data array
+            },
+            {
+              label: 'Last Name',
+              prop: 'lastname'
+            }
+          ]
+        };
+
+        this.data = [
+          {
+            name: 'John',
+            lastname: 'Doe'
+          },
+          {
+            name: 'Gili',
+            lastname: 'Fereydoun'
+          }
+        ]
+      });
+    </file>
+  </example>
+
+  <example module="sampleTable2">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl2 as vm">
+        <xos-table data="vm.data" config="vm.config"></xos-table>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('sampleTable2', ['xos.uiComponents'])
+      .controller('SampleCtrl2', function(){
+        this.config = {
+          columns: [
+            {
+              label: 'First Name', // column title
+              prop: 'name' // property to read in the data array
+            },
+            {
+              label: 'Last Name',
+              prop: 'lastname'
+            }
+          ],
+          classes: 'table table-striped table-condensed', // table classes, default to `table table-striped table-bordered`
+          actions: [ // if defined add an action column
+            {
+              label: 'delete', // label
+              icon: 'remove', // icons, refers to bootstraps glyphicon
+              cb: (user) => { // callback, get feeded with the full object
+                console.log(user);
+              },
+              color: 'red' // icon color
+            }
+          ],
+          filter: 'field', // can be by `field` or `fulltext`
+          order: true
+        };
+
+        this.data = [
+          {
+            name: 'John',
+            lastname: 'Doe'
+          },
+          {
+            name: 'Gili',
+            lastname: 'Fereydoun'
+          }
+        ]
+      });
+    </file>
+  </example>
+
+  <example module="sampleTable3">
+    <file name="index.html">
+      <div ng-controller="SampleCtrl3 as vm">
+        <xos-table data="vm.data" config="vm.config"></xos-table>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('sampleTable3', ['xos.uiComponents'])
+      .controller('SampleCtrl3', function(){
+        this.config = {
+          columns: [
+            {
+              label: 'First Name', // column title
+              prop: 'name' // property to read in the data array
+            },
+            {
+              label: 'Last Name',
+              prop: 'lastname'
+            }
+          ],
+          pagination: {
+            pageSize: 2
+          }
+        };
+
+        this.data = [
+          {
+            name: 'John',
+            lastname: 'Doe'
+          },
+          {
+            name: 'Gili',
+            lastname: 'Fereydoun'
+          },
+          {
+            name: 'Lucky',
+            lastname: 'Clarkson'
+          },
+          {
+            name: 'Tate',
+            lastname: 'Spalding'
+          }
+        ]
+      });
+    </file>
+  </example>
+    **/
+
     .directive('xosTable', function(){
       return {
         restrict: 'E',
         scope: {
           data: '=',
-          columns: '='
+          config: '='
         },
-        template: [
-          '<!--<pre>{{vm.data | json}}</pre>-->',
-          '<table class="table table-striped" ng-show="vm.data.length > 0">',
-            '<thead>',
-              '<tr>',
-                '<th ng-repeat="col in vm.columns">{{col}}</th>',
-              '</tr>',
-            '</thead>',
-            '<tbody>',
-              '<tr ng-repeat="item in vm.data">',
-                '<td ng-repeat="col in vm.columns">{{item[col]}}</td>',
-              '</tr>',
-            '</tbody>',
-          '</table>'
-        ].join(),
+        template: `
+          <div ng-show="vm.data.length > 0">
+            <div class="row" ng-if="vm.config.filter == 'fulltext'">
+              <div class="col-xs-12">
+                <input
+                  class="form-control"
+                  placeholder="Type to search.."
+                  type="text"
+                  ng-model="vm.query"/>
+              </div>
+            </div>
+            <table ng-class="vm.classes" ng-show="vm.data.length > 0">
+              <thead>
+                <tr>
+                  <th ng-repeat="col in vm.columns">
+                    {{col.label}}
+                    <span ng-if="vm.config.order">
+                      <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = false">
+                        <i class="glyphicon glyphicon-chevron-up"></i>
+                      </a>
+                      <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = true">
+                        <i class="glyphicon glyphicon-chevron-down"></i>
+                      </a>
+                    </span>
+                  </th>
+                  <th ng-if="vm.config.actions">Actions</th>
+                </tr>
+              </thead>
+              <tbody ng-if="vm.config.filter == 'field'">
+                <tr>
+                  <td ng-repeat="col in vm.columns">
+                    <input
+                      class="form-control"
+                      placeholder="Type to search by {{col.label}}"
+                      type="text"
+                      ng-model="vm.query[col.prop]"/>
+                  </td>
+                  <td ng-if="vm.config.actions"></td>
+                </tr>
+              </tbody>
+              <tbody>
+                <tr ng-repeat="item in vm.data | filter:vm.query | orderBy:vm.orderBy:vm.reverse | pagination:vm.currentPage * vm.config.pagination.pageSize | limitTo: (vm.config.pagination.pageSize || vm.data.length) track by $index">
+                  <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td>
+                  <td ng-if="vm.config.actions">
+                    <a href=""
+                      ng-repeat="action in vm.config.actions"
+                      ng-click="action.cb(item)"
+                      title="{{action.label}}">
+                      <i
+                        class="glyphicon glyphicon-{{action.icon}}"
+                        style="color: {{action.color}};"></i>
+                    </a>
+                  </td>
+                </tr>
+              </tbody>
+            </table>
+            <xos-pagination
+              ng-if="vm.config.pagination"
+              page-size="vm.config.pagination.pageSize"
+              total-elements="vm.data.length"
+              change="vm.goToPage">
+              </xos-pagination>
+          </div>
+          <div ng-show="vm.data.length == 0 || !vm.data">
+            <div class="alert alert-info">
+              No data to show.
+            </div>
+          </div>
+        `,
         bindToController: true,
         controllerAs: 'vm',
         controller: function(){
-          console.log(this.data, this.columns);
+
+          if(!this.config){
+            throw new Error('[xosTable] Please provide a configuration via the "config" attribute');
+          }
+
+          if(!this.config.columns){
+            throw new Error('[xosTable] Please provide a columns list in the configuration');
+          }
+
+          this.columns = this.config.columns;
+          this.classes = this.config.classes || 'table table-striped table-bordered';
+
+          if(this.config.actions){
+            // TODO validate action format
+          }
+          if(this.config.pagination){
+            this.currentPage = 0;
+            this.goToPage = (n) => {
+              this.currentPage = n;
+            };
+          }
+
         }
       }
     })
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/ui-components.module.js b/views/ngXosLib/xosHelpers/src/ui_components/ui-components.module.js
index 0cbe70e..bd07908 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/ui-components.module.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/ui-components.module.js
@@ -9,7 +9,12 @@
 (function () {
   'use strict';
 
+  /**
+  * @ngdoc overview
+  * @name xos.uiComponents
+  * @description A collection of UI components useful for Dashboard development
+  **/
+
   angular.module('xos.uiComponents', [
-    'xos.uiComponents.table'
   ])
 })();
diff --git a/views/ngXosLib/xosHelpers/src/xosHelpers.module.js b/views/ngXosLib/xosHelpers/src/xosHelpers.module.js
index c4b40f1..d7cd958 100644
--- a/views/ngXosLib/xosHelpers/src/xosHelpers.module.js
+++ b/views/ngXosLib/xosHelpers/src/xosHelpers.module.js
@@ -1,36 +1,39 @@
 (function() {
-    'use strict';
-    console.log('XOS Helpers Module')
-    angular.module('bugSnag', []).factory('$exceptionHandler', function () {
-      return function (exception, cause) {
-        if( window.Bugsnag ){
-          Bugsnag.notifyException(exception, {diagnostics:{cause: cause}});
-        }
-        else{
-          console.error(exception, cause, exception.stack);
-        }
-      };
-    });
+  'use strict';
+  
+  angular.module('bugSnag', []).factory('$exceptionHandler', function () {
+    return function (exception, cause) {
+      if( window.Bugsnag ){
+        Bugsnag.notifyException(exception, {diagnostics: {cause: cause}});
+      }
+      else{
+        console.error(exception, cause, exception.stack);
+      }
+    };
+  });
 
-    angular
-        .module('xos.helpers',[
-          'ngCookies',
-          'ngResource',
-          'xos.xos',
-          'xos.hpcapi',
-          'xos.xoslib',
-          'bugSnag',
-          'xos.uiComponents'
-        ])
-        .config(config);
+  /**
+  * @ngdoc overview
+  * @name xos.helpers
+  * @description this is the module that group all the helpers service and components for XOS
+  **/
 
-    function config($httpProvider, $interpolateProvider, $resourceProvider) {
-      $httpProvider.interceptors.push('SetCSRFToken');
+  angular
+      .module('xos.helpers', [
+        'ngCookies',
+        'ngResource',
+        'bugSnag',
+        'xos.uiComponents'
+      ])
+      .config(config);
 
-      $interpolateProvider.startSymbol('{$');
-      $interpolateProvider.endSymbol('$}');
+  function config($httpProvider, $interpolateProvider, $resourceProvider) {
+    $httpProvider.interceptors.push('SetCSRFToken');
 
-      // NOTE http://www.masnun.com/2013/09/18/django-rest-framework-angularjs-resource-trailing-slash-problem.html
-      $resourceProvider.defaults.stripTrailingSlashes = false;
-    }
+    $interpolateProvider.startSymbol('{$');
+    $interpolateProvider.endSymbol('$}');
+
+    // NOTE http://www.masnun.com/2013/09/18/django-rest-framework-angularjs-resource-trailing-slash-problem.html
+    $resourceProvider.defaults.stripTrailingSlashes = false;
+  }
 })();
\ No newline at end of file
diff --git a/views/ngXosViews/diagnostic/gulp/build.js b/views/ngXosViews/diagnostic/gulp/build.js
index c9cd9cb..1a1be80 100644
--- a/views/ngXosViews/diagnostic/gulp/build.js
+++ b/views/ngXosViews/diagnostic/gulp/build.js
@@ -27,6 +27,13 @@
 var mqpacker = require('css-mqpacker');
 var csswring = require('csswring');
 
+const TEMPLATE_FOOTER = `
+angular.module('xos.diagnostic')
+.run(['$location', function(a){
+  a.path('/');
+}])
+`
+
 module.exports = function(options){
   
   // delete previous builded file
@@ -69,8 +76,8 @@
     .pipe(angularFilesort())
     .pipe(concat('xosDiagnostic.js'))
     .pipe(concat.header('//Autogenerated, do not edit!!!\n'))
-    // .pipe(concat.footer(TEMPLATE_FOOTER))
-    // .pipe(uglify())
+    .pipe(concat.footer(TEMPLATE_FOOTER))
+    .pipe(uglify())
     .pipe(gulp.dest(options.static + 'js/'));
   });
 
diff --git a/views/ngXosViews/sampleView/.bowerrc b/views/ngXosViews/sampleView/.bowerrc
new file mode 100644
index 0000000..e491038
--- /dev/null
+++ b/views/ngXosViews/sampleView/.bowerrc
@@ -0,0 +1,3 @@
+{
+  "directory": "src/vendor/"
+}
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/.eslintrc b/views/ngXosViews/sampleView/.eslintrc
new file mode 100644
index 0000000..c852748
--- /dev/null
+++ b/views/ngXosViews/sampleView/.eslintrc
@@ -0,0 +1,42 @@
+{
+    "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
new file mode 100644
index 0000000..567aee4
--- /dev/null
+++ b/views/ngXosViews/sampleView/.gitignore
@@ -0,0 +1,6 @@
+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
new file mode 100644
index 0000000..cc5fc64
--- /dev/null
+++ b/views/ngXosViews/sampleView/bower.json
@@ -0,0 +1,29 @@
+{
+  "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-resource": "1.4.7",
+    "ng-lodash": "0.3.0",
+    "bootstrap-css": "3.3.6"
+  }
+}
diff --git a/views/ngXosViews/sampleView/env/default.js b/views/ngXosViews/sampleView/env/default.js
new file mode 100644
index 0000000..353973a
--- /dev/null
+++ b/views/ngXosViews/sampleView/env/default.js
@@ -0,0 +1,13 @@
+// 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: 'jkKF9NebQoyaxKFT42l1EFjGx6ESPuP4',
+  xossessionid: 'kvq9qxycbu0298wxfg8v11at94q9m819'
+};
diff --git a/views/ngXosViews/sampleView/gulp/build.js b/views/ngXosViews/sampleView/gulp/build.js
new file mode 100644
index 0000000..36534fb
--- /dev/null
+++ b/views/ngXosViews/sampleView/gulp/build.js
@@ -0,0 +1,163 @@
+'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
new file mode 100644
index 0000000..3c6a8e3
--- /dev/null
+++ b/views/ngXosViews/sampleView/gulp/server.js
@@ -0,0 +1,192 @@
+'use strict';
+
+var gulp = require('gulp');
+var browserSync = require('browser-sync').create();
+var inject = require('gulp-inject');
+var es = require('event-stream');
+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');
+var debug = require('gulp-debug');
+
+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){
+  // open in browser with sync and proxy to 0.0.0.0
+  gulp.task('browser', function() {
+    console.log(options.helpers);
+    browserSync.init({
+      // reloadDelay: 500,
+      // logLevel: 'debug',
+      // logConnections: true,
+      startPath: '#/',
+      snippetOptions: {
+        rule: {
+          match: /<!-- browserSync -->/i
+        }
+      },
+      server: {
+        baseDir: options.src,
+        routes: {
+          // '/xosHelpers/src': options.helpers,
+          '/xos/core/xoslib/static/js/vendor': options.helpers
+        },
+        middleware: function(req, res, next){
+          if(
+            // 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.helpers + 'ngXosHelpers.js', function(){
+      browserSync.reload();
+    });
+    
+    gulp.watch(`${options.sass}/**/*.scss`, ['sass'], 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 sourceMap
+  // gulp.task('injectMaps', function(){
+  //   return gulp.src(options.src + 'index.html')
+  //     .pipe(
+  //       inject(
+  //         gulp.src([
+  //           options.helpersSourceMaps + '**/*.js.map'
+  //         ], {read: false}).pipe(debug()),
+  //         {
+  //           starttag: '<!-- inject:maps -->',
+  //           // ignorePath: [options.src, '/../../ngXosLib']
+  //         }
+  //       )
+  //     )
+  //     .pipe(gulp.dest(options.src));
+  // });
+
+  // inject scripts
+  gulp.task('injectScript', ['cleanTmp', 'babel'], function(){
+
+    var appScripts = gulp.src([
+      options.tmp + '**/*.js',
+      options.helpers + 'ngXosHelpers.js'
+    ])
+    .pipe(angularFilesort()).pipe(debug());
+
+    var helpersSourceMaps = gulp.src([
+      options.helpersSourceMaps + '**/*.js.map'
+    ]).pipe(debug());
+
+    return gulp.src(options.src + 'index.html')
+      .pipe(
+        inject(
+          es.merge(appScripts, helpersSourceMaps),
+          {
+            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'),
+          {
+            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
new file mode 100644
index 0000000..8b50345
--- /dev/null
+++ b/views/ngXosViews/sampleView/gulpfile.js
@@ -0,0 +1,27 @@
+'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/',
+  helpersSourceMaps: '../../ngXosLib/xosHelpers/.tmp/maps/',
+  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
new file mode 100644
index 0000000..4123be9
--- /dev/null
+++ b/views/ngXosViews/sampleView/karma.conf.js
@@ -0,0 +1,88 @@
+// 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
new file mode 100644
index 0000000..e92f937
--- /dev/null
+++ b/views/ngXosViews/sampleView/package.json
@@ -0,0 +1,65 @@
+{
+  "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",
+    "event-stream": "^3.3.2",
+    "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-debug": "^2.1.2",
+    "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
new file mode 100644
index 0000000..6005af7
--- /dev/null
+++ b/views/ngXosViews/sampleView/spec/sample.test.js
@@ -0,0 +1,37 @@
+'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/ngXosLib/api/.gitignore b/views/ngXosViews/sampleView/src/css/main.css
similarity index 100%
rename from views/ngXosLib/api/.gitignore
rename to views/ngXosViews/sampleView/src/css/main.css
diff --git a/views/ngXosViews/sampleView/src/index.html b/views/ngXosViews/sampleView/src/index.html
new file mode 100644
index 0000000..d04fc3b
--- /dev/null
+++ b/views/ngXosViews/sampleView/src/index.html
@@ -0,0 +1,29 @@
+<!-- browserSync -->
+<!-- bower:css -->
+<link rel="stylesheet" href="vendor/bootstrap-css/css/bootstrap.min.css" />
+<!-- endbower --><!-- endcss -->
+<!-- inject:css -->
+<link rel="stylesheet" href="/css/main.css">
+<!-- endinject -->
+
+<div ng-app="xos.sampleView" id="xosSampleView" class="container-fluid">
+    <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-resource/angular-resource.js"></script>
+<script src="vendor/ng-lodash/build/ng-lodash.js"></script>
+<script src="vendor/bootstrap-css/js/bootstrap.min.js"></script>
+<!-- endbower --><!-- endjs -->
+<!-- inject:js -->
+<script src="/../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js"></script>
+<script src="/.tmp/main.js"></script>
+<!-- endinject -->
+
+<!-- inject:map -->
+<!-- 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
new file mode 100644
index 0000000..b00aa0b
--- /dev/null
+++ b/views/ngXosViews/sampleView/src/js/main.js
@@ -0,0 +1,78 @@
+'use strict';
+
+angular.module('xos.sampleView', [
+  'ngResource',
+  'ngCookies',
+  'ngLodash',
+  '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.tableConfig = {
+        columns: [
+          {
+            label: 'E-Mail',
+            prop: 'email'
+          },
+          {
+            label: 'First Name',
+            prop: 'firstname'
+          },
+          {
+            label: 'Last Name',
+            prop: 'lastname'
+          }
+        ],
+        classes: 'table table-striped table-condensed',
+        actions: [
+          {
+            label: 'delete',
+            icon: 'remove',
+            cb: (user) => {
+              console.log(user);
+            },
+            color: 'red'
+          }
+        ],
+        filter: 'field',
+        order: true,
+        // pagination: {
+        //   pageSize: 6
+        // }
+      };
+
+      this.alertConfig = {
+        type: 'danger',
+        closeBtn: true
+      }
+
+
+      // retrieving user list
+      Users.query().$promise
+      .then((users) => {
+        this.users = users;
+      })
+      .catch((e) => {
+        throw new Error(e);
+      });
+    }
+  };
+});
\ No newline at end of file
diff --git a/views/ngXosViews/sampleView/src/sass/main.scss b/views/ngXosViews/sampleView/src/sass/main.scss
new file mode 100644
index 0000000..efe6cdc
--- /dev/null
+++ b/views/ngXosViews/sampleView/src/sass/main.scss
@@ -0,0 +1,5 @@
+@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
new file mode 100644
index 0000000..c0c58cb
--- /dev/null
+++ b/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
@@ -0,0 +1,14 @@
+<div class="row">
+  <div class="col-xs-12">
+    <h1>Users List</h1>
+    <p>This is only an example view.</p>
+  </div>
+</div>
+
+  <xos-alert config="vm.alertConfig">Alert message Here</xos-alert>
+
+<div class="row">
+  <div class="col-xs-12">
+    <xos-table data="vm.users" config="vm.tableConfig"></xos-table>
+  </div>
+</div>
\ No newline at end of file
diff --git a/xos/configurations/cord-pod/README.md b/xos/configurations/cord-pod/README.md
index b47a915..b1304b7 100644
--- a/xos/configurations/cord-pod/README.md
+++ b/xos/configurations/cord-pod/README.md
@@ -105,11 +105,7 @@
 appropriate values for the fabric:
   * `addresses_vsg:properties:addresses` (IP address block of fabric)
   * `addresses_vsg:properties:gateway_ip` 
-  * `addresses_vsg:properties:gateway_mac`
-  * `service_vsg:properties:wan_container_gateway_ip` (same as `gateway_ip` above and same as `publicGateway:gatewayIp` from VTN configuration)
-  * `service_vsg:properties:wan_container_gateway_mac` (same as `gateway_mac` above and same as `publicGateway:gatewayMac` from VTN configuration)
-  * `service_vsg:properties:wan_container_netbits` (bits in fabric IP address block netmask)
-
+  * `addresses_vsg:properties:gateway_mac` 
 
 If you're not using the fabric then the default values should be OK.  
 
diff --git a/xos/configurations/cord-pod/cleanup.sh b/xos/configurations/cord-pod/cleanup.sh
index 6ca58c2..704cacb 100755
--- a/xos/configurations/cord-pod/cleanup.sh
+++ b/xos/configurations/cord-pod/cleanup.sh
@@ -47,3 +47,4 @@
 neutron net-delete ceilometer_network || true
 neutron net-delete management || true
 neutron net-delete mysite_vsg-access || true
+neutron net-delete exampleservice-public || true
diff --git a/xos/configurations/cord-pod/cord-vtn-vsg.yaml b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
index c8c6ceb..7de536a 100644
--- a/xos/configurations/cord-pod/cord-vtn-vsg.yaml
+++ b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
@@ -49,9 +49,6 @@
           backend_network_label: hpc_client
           public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
           private_key_fn: /opt/xos/synchronizers/vcpe/vcpe_private_key
-          wan_container_gateway_ip: 10.168.0.1
-          wan_container_gateway_mac: 02:42:0a:a8:00:01
-          wan_container_netbits: 24
 #          node_label: label_vsg
       artifacts:
           pubkey: /opt/xos/synchronizers/vcpe/vcpe_public_key
diff --git a/xos/configurations/cord-pod/docker-compose.yml b/xos/configurations/cord-pod/docker-compose.yml
index 234fd43..e2a5768 100644
--- a/xos/configurations/cord-pod/docker-compose.yml
+++ b/xos/configurations/cord-pod/docker-compose.yml
@@ -13,7 +13,7 @@
         - xos_db
     volumes:
         - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-        - xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
+        - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
         - .:/root/setup:ro
         - ../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
         - ./images:/opt/xos/images:ro
@@ -96,7 +96,7 @@
     volumes:
         - .:/root/setup:ro
         - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-        - xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
+        - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
         - ../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
         - ./id_rsa.pub:/opt/xos/synchronizers/onos/onos_key.pub:ro
         - ./id_rsa.pub:/opt/xos/synchronizers/vcpe/vcpe_public_key:ro
diff --git a/xos/configurations/cord-pod/vtn-external.yaml b/xos/configurations/cord-pod/vtn-external.yaml
index 74e7ef7..51cca08 100644
--- a/xos/configurations/cord-pod/vtn-external.yaml
+++ b/xos/configurations/cord-pod/vtn-external.yaml
@@ -8,7 +8,7 @@
 topology_template:
   node_templates:
 
-    service_ONOS_VTN:
+    service_ONOS_CORD:
       type: tosca.nodes.ONOSService
       requirements:
       properties:
@@ -21,8 +21,16 @@
       type: tosca.nodes.ONOSVTNApp
       requirements:
           - onos_tenant:
-              node: service_ONOS_VTN
+              node: service_ONOS_CORD
               relationship: tosca.relationships.TenantOfService
+          - vtn_service:
+              node: service_vtn
+              relationship: tosca.relationships.UsedByService
       properties:
           dependencies: org.onosproject.drivers, org.onosproject.drivers.ovsdb, org.onosproject.openflow-base, org.onosproject.ovsdb-base, org.onosproject.dhcp, org.onosproject.cordvtn, org.onosproject.olt, org.onosproject.igmp, org.onosproject.cordmcast
           autogenerate: vtn-network-cfg
+
+    service_vtn:
+      type: tosca.nodes.VTNService
+      properties:
+          view_url: /admin/vtn/vtnservice/$id$/
diff --git a/xos/core/admin.py b/xos/core/admin.py
index ee6c6bf..f14710b 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1,49 +1,49 @@
-from core.models import Site
-from core.models import *
-from openstack.manager import OpenStackManager
+import threading
+from cgi import escape as html_escape
 
-from django.contrib import admin
-from django.contrib.auth.models import Group
+from core.models import *
+from core.models import Site
 from django import forms
-from django.utils.safestring import mark_safe
+from django.contrib import admin, messages
+from django.contrib.admin.widgets import (AdminTextareaWidget,
+                                          FilteredSelectMultiple)
 from django.contrib.auth.admin import UserAdmin
-from django.contrib.admin.widgets import FilteredSelectMultiple, AdminTextareaWidget
-from django.contrib.auth.forms import ReadOnlyPasswordHashField, AdminPasswordChangeForm
+from django.contrib.auth.forms import (AdminPasswordChangeForm,
+                                       ReadOnlyPasswordHashField)
+from django.contrib.auth.models import Group
 from django.contrib.auth.signals import user_logged_in
-from django.utils import timezone
 from django.contrib.contenttypes import generic
-from suit.widgets import LinkedSelect
-from django.core.exceptions import PermissionDenied
-from django.core.urlresolvers import reverse, resolve, NoReverseMatch
+from django.core.exceptions import PermissionDenied, ValidationError
+from django.core.urlresolvers import NoReverseMatch, resolve, reverse
+from django.forms.utils import flatatt, to_current_timezone
+from django.utils import timezone
 from django.utils.encoding import force_text, python_2_unicode_compatible
 from django.utils.html import conditional_escape, format_html
+from django.utils.safestring import mark_safe
 from django.utils.text import capfirst
-from django.forms.utils import flatatt, to_current_timezone
-from django.core.exceptions import PermissionDenied, ValidationError
-from cgi import escape as html_escape
-from django.contrib import messages
-
-import threading
+from openstack.manager import OpenStackManager
+from suit.widgets import LinkedSelect
 
 # thread locals necessary to work around a django-suit issue
 _thread_locals = threading.local()
 
 ICON_URLS = {"success": "/static/admin/img/icon_success.gif",
-            "clock": "/static/admin/img/icon_clock.gif",
-            "error": "/static/admin/img/icon_error.gif"}
+             "clock": "/static/admin/img/icon_clock.gif",
+             "error": "/static/admin/img/icon_error.gif"}
+
 
 def backend_icon(obj):
     (icon, tooltip) = obj.get_backend_icon()
 
     icon_url = ICON_URLS.get(icon, "unknown")
 
-    (exponent,last_success,last_failure,failures) = obj.get_backend_details()
+    (exponent, last_success, last_failure, failures) = obj.get_backend_details()
 
     # FIXME: Need to clean this up by separating Javascript from Python
     if (obj.pk):
         script = """
         <script type="text/javascript">$(document).ready(function () {$("#show_details_%d").click(function () {$("#status%d").dialog({modal: true, height: 200, width: 200 });});});</script>
-        """%(obj.pk,obj.pk)
+        """ % (obj.pk, obj.pk)
 
         div = """
         <div style="display:none;" id="status%d" title="Details">
@@ -52,8 +52,8 @@
                 <p>Failures: %r</p>
                 <p>Last Failure: %r</p>
                     </div>
-        """%(obj.pk,exponent,last_success,failures,last_failure)
-        a = '<a id="show_details_%d" href="#">'%obj.pk
+        """ % (obj.pk, exponent, last_success, failures, last_failure)
+        a = '<a id="show_details_%d" href="#">' % obj.pk
         astop = '</a>'
     else:
         div = ''
@@ -66,24 +66,30 @@
     else:
         return '<span style="min-width:16px;"><img src="%s"></span>' % icon_url
 
+
 def backend_text(obj):
     (icon, tooltip) = obj.get_backend_icon()
     icon_url = ICON_URLS.get(icon, "unknown")
 
     return '<img src="%s"> %s' % (icon_url, tooltip)
 
+
 class UploadTextareaWidget(AdminTextareaWidget):
+
     def render(self, name, value, attrs=None):
         if value is None:
             value = ''
         final_attrs = self.build_attrs(attrs, name=name)
-        return format_html('<input type="file" style="width: 0; height: 0" id="btn_upload_%s" onChange="uploadTextarea(event,\'%s\');">' \
-                           '<button onClick="$(\'#btn_upload_%s\').click(); return false;">Upload</button>' \
-                           '<br><textarea{0}>\r\n{1}</textarea>' % (attrs["id"], attrs["id"], attrs["id"]),
+        return format_html('<input type="file" style="width: 0; height: 0" id="btn_upload_%s" onChange="uploadTextarea(event,\'%s\');">'
+                           '<button onClick="$(\'#btn_upload_%s\').click(); return false;">Upload</button>'
+                           '<br><textarea{0}>\r\n{1}</textarea>' % (
+                               attrs["id"], attrs["id"], attrs["id"]),
                            flatatt(final_attrs),
                            force_text(value))
 
+
 class SliderWidget(forms.HiddenInput):
+
     def render(self, name, value,  attrs=None):
         if value is None:
             value = '0'
@@ -102,7 +108,7 @@
                               </script>
                               <input type="hidden" id="%(id)s" name="%(name)s" value="%(value)s"></input>
                            """ % attrs
-        html = html.replace("{","{{").replace("}","}}")
+        html = html.replace("{", "{{").replace("}", "}}")
         return format_html(html,
                            flatatt(final_attrs),
                            force_text(value))
@@ -116,6 +122,7 @@
             value = ''
         return mark_safe(str(value) + super(PlainTextWidget, self).render(name, value, attrs))
 
+
 class XOSAdminMixin(object):
     # call save_by_user and delete_by_user instead of save and delete
 
@@ -166,8 +173,8 @@
 
         formset.save_m2m()
 
-    def get_actions(self,request):
-        actions = super(XOSAdminMixin,self).get_actions(request)
+    def get_actions(self, request):
+        actions = super(XOSAdminMixin, self).get_actions(request)
 
         if self.__user_is_readonly(request):
             if 'delete_selected' in actions:
@@ -181,13 +188,16 @@
 
     def add_extra_context(self, request, extra_context):
         # allow custom application breadcrumb url and name
-        extra_context["custom_app_breadcrumb_url"] = getattr(self, "custom_app_breadcrumb_url", None)
-        extra_context["custom_app_breadcrumb_name"] = getattr(self, "custom_app_breadcrumb_name", None)
-        extra_context["custom_changelist_breadcrumb_url"] = getattr(self, "custom_changelist_breadcrumb_url", None)
+        extra_context["custom_app_breadcrumb_url"] = getattr(
+            self, "custom_app_breadcrumb_url", None)
+        extra_context["custom_app_breadcrumb_name"] = getattr(
+            self, "custom_app_breadcrumb_name", None)
+        extra_context["custom_changelist_breadcrumb_url"] = getattr(
+            self, "custom_changelist_breadcrumb_url", None)
 
         # for Service admins to render their Administration page
         if getattr(self, "extracontext_registered_admins", False):
-            admins=[]
+            admins = []
             for model, model_admin in admin.site._registry.items():
                 if model == self.model:
                     continue
@@ -195,11 +205,11 @@
                     info = {"app": model._meta.app_label,
                             "model": model._meta.model_name,
                             "name": capfirst(model._meta.verbose_name_plural),
-                            "url": self.url_for_model_changelist(request,model) }
+                            "url": self.url_for_model_changelist(request, model)}
                     admins.append(info)
             extra_context["registered_admins"] = admins
 
-    def change_view(self,request,object_id, extra_context=None):
+    def change_view(self, request, object_id, extra_context=None):
         extra_context = extra_context or {}
 
         if self.__user_is_readonly(request):
@@ -208,7 +218,7 @@
                 self.readonly_save = self.readonly_fields
                 self.inlines_save = self.inlines
             if hasattr(self, "user_readonly_fields"):
-                self.readonly_fields=self.user_readonly_fields
+                self.readonly_fields = self.user_readonly_fields
             if hasattr(self, "user_readonly_inlines"):
                 self.inlines = self.user_readonly_inlines
         else:
@@ -244,14 +254,14 @@
         request.readonly = True
         return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context)
 
-    def changelist_view(self, request, extra_context = None):
+    def changelist_view(self, request, extra_context=None):
         extra_context = extra_context or {}
 
         self.add_extra_context(request, extra_context)
 
         return super(XOSAdminMixin, self).changelist_view(request, extra_context=extra_context)
 
-    def add_view(self, request, form_url='', extra_context = None):
+    def add_view(self, request, form_url='', extra_context=None):
         extra_context = extra_context or {}
 
         self.add_extra_context(request, extra_context)
@@ -286,16 +296,20 @@
 
         return inlines
 
+
 class ReadOnlyAwareAdmin(XOSAdminMixin, admin.ModelAdmin):
     # Note: Make sure XOSAdminMixin is listed before
     # admin.ModelAdmin in the class declaration.
 
     pass
 
+
 class XOSBaseAdmin(ReadOnlyAwareAdmin):
     save_on_top = False
 
+
 class SingletonAdmin (ReadOnlyAwareAdmin):
+
     def has_add_permission(self, request):
         if not super(SingletonAdmin, self).has_add_permission(request):
             return False
@@ -306,10 +320,13 @@
         else:
             return True
 
+
 class ServiceAppAdmin (SingletonAdmin):
     extracontext_registered_admins = True
 
+
 class XOSTabularInline(admin.TabularInline):
+
     def __init__(self, *args, **kwargs):
         super(XOSTabularInline, self).__init__(*args, **kwargs)
 
@@ -328,7 +345,7 @@
                 object instead of trying to bring up a change view of the
                 SliceNetwork object.
             """
-            return getattr(self.model,self.selflink_fieldname).field.rel.to
+            return getattr(self.model, self.selflink_fieldname).field.rel.to
         else:
             return self.model
 
@@ -338,7 +355,7 @@
 
     def get_change_url(self, id):
         """ Get the URL to a change form in the admin for this model """
-        reverse_path = self.selflink_reverse_path # "admin:%s_change" % (self.selflink_model._meta.db_table)
+        reverse_path = self.selflink_reverse_path  # "admin:%s_change" % (self.selflink_model._meta.db_table)
         try:
             url = reverse(reverse_path, args=(id,))
         except NoReverseMatch:
@@ -397,7 +414,9 @@
         return mark_safe(backend_icon(obj))
     backend_status_icon.short_description = ""
 
+
 class PlStackGenericTabularInline(generic.GenericTabularInline):
+
     def has_add_permission(self, request):
         return not request.user.isReadOnlyUser()
 
@@ -413,6 +432,7 @@
         return mark_safe(backend_icon(obj))
     backend_status_icon.short_description = ""
 
+
 class ReservationInline(XOSTabularInline):
     model = Reservation
     extra = 0
@@ -421,6 +441,7 @@
     def queryset(self, request):
         return Reservation.select_by_user(request.user)
 
+
 class TagInline(PlStackGenericTabularInline):
     model = Tag
     extra = 0
@@ -430,12 +451,15 @@
     def queryset(self, request):
         return Tag.select_by_user(request.user)
 
+
 class InstanceInline(XOSTabularInline):
     model = Instance
-    fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node']
+    fields = ['backend_status_icon', 'all_ips_string', 'instance_id',
+              'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node']
     extra = 0
     max_num = 0
-    readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node']
+    readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id',
+                       'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node']
     suit_classes = 'suit-tab suit-tab-instances'
 
     def queryset(self, request):
@@ -443,20 +467,27 @@
 
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
         if db_field.name == 'deployment':
-           kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct()
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"})
+            kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(
+                sitedeployments__nodes__isnull=False).distinct()
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_deployment_changed(this);"})
         if db_field.name == 'flavor':
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"})
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_flavor_changed(this);"})
 
-        field = super(InstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        field = super(InstanceInline, self).formfield_for_foreignkey(
+            db_field, request, **kwargs)
 
         return field
 
+
 class CordInstanceInline(XOSTabularInline):
     model = Instance
-    fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'flavor', 'image', 'node']
+    fields = ['backend_status_icon', 'all_ips_string', 'instance_id',
+              'instance_name', 'slice', 'flavor', 'image', 'node']
     extra = 0
-    readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name']
+    readonly_fields = ['backend_status_icon',
+                       'all_ips_string', 'instance_id', 'instance_name']
     suit_classes = 'suit-tab suit-tab-instances'
 
     def queryset(self, request):
@@ -465,15 +496,20 @@
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
         if db_field.name == 'deployment':
 
-           kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct()
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"})
+            kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(
+                sitedeployments__nodes__isnull=False).distinct()
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_deployment_changed(this);"})
         if db_field.name == 'flavor':
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"})
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_flavor_changed(this);"})
 
-        field = super(CordInstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        field = super(CordInstanceInline, self).formfield_for_foreignkey(
+            db_field, request, **kwargs)
 
         return field
 
+
 class SiteInline(XOSTabularInline):
     model = Site
     extra = 0
@@ -482,13 +518,18 @@
     def queryset(self, request):
         return Site.select_by_user(request.user)
 
+
 class SiteHostsNodesInline(SiteInline):
+
     def queryset(self, request):
         return Site.select_by_user(request.user).filter(hosts_nodes=True)
 
+
 class SiteHostsUsersInline(SiteInline):
+
     def queryset(self, request):
-        return Site.select_by_user(request.user).filter(hosts_users=True)        
+        return Site.select_by_user(request.user).filter(hosts_users=True)
+
 
 class UserInline(XOSTabularInline):
     model = User
@@ -500,6 +541,7 @@
     def queryset(self, request):
         return User.select_by_user(request.user)
 
+
 class SliceInline(XOSTabularInline):
     model = Slice
     fields = ['backend_status_icon', 'name', 'site', 'serviceClass', 'service']
@@ -510,6 +552,7 @@
     def queryset(self, request):
         return Slice.select_by_user(request.user)
 
+
 class NodeInline(XOSTabularInline):
     model = Node
     extra = 0
@@ -517,16 +560,18 @@
     fields = ['backend_status_icon', 'name', 'site_deployment']
     readonly_fields = ('backend_status_icon', )
 
+
 class DeploymentPrivilegeInline(XOSTabularInline):
     model = DeploymentPrivilege
     extra = 0
     suit_classes = 'suit-tab suit-tab-deploymentprivileges'
-    fields = ['backend_status_icon', 'user','role','deployment']
+    fields = ['backend_status_icon', 'user', 'role', 'deployment']
     readonly_fields = ('backend_status_icon', )
 
     def queryset(self, request):
         return DeploymentPrivilege.select_by_user(request.user)
 
+
 class ControllerSiteInline(XOSTabularInline):
     model = ControllerSite
     extra = 0
@@ -538,7 +583,7 @@
     model = SitePrivilege
     extra = 0
     suit_classes = 'suit-tab suit-tab-siteprivileges'
-    fields = ['backend_status_icon', 'user','site', 'role']
+    fields = ['backend_status_icon', 'user', 'site', 'role']
     readonly_fields = ('backend_status_icon', )
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
@@ -557,7 +602,7 @@
     model = ServicePrivilege
     extra = 0
     suit_classes = 'suit-tab suit-tab-serviceprivileges'
-    fields = ['backend_status_icon', 'user','service', 'role']
+    fields = ['backend_status_icon', 'user', 'service', 'role']
     readonly_fields = ('backend_status_icon', )
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
@@ -565,16 +610,17 @@
             kwargs['queryset'] = Service.select_by_user(request.user)
         if db_field.name == 'user':
             kwargs['queryset'] = User.select_by_user(request.user)
-        return super(ServicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)         
+        return super(ServicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
     def queryset(self, request):
         return ServicePrivilege.select_by_user(request.user)
 
+
 class SiteDeploymentInline(XOSTabularInline):
     model = SiteDeployment
     extra = 0
     suit_classes = 'suit-tab suit-tab-sitedeployments'
-    fields = ['backend_status_icon', 'deployment','site', 'controller']
+    fields = ['backend_status_icon', 'deployment', 'site', 'controller']
     readonly_fields = ('backend_status_icon', )
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
@@ -586,7 +632,8 @@
 
         if db_field.name == 'controller':
             if len(resolve(request.path).args) > 0:
-                kwargs['queryset'] = Controller.select_by_user(request.user).filter(deployment__id=int(resolve(request.path).args[0]))
+                kwargs['queryset'] = Controller.select_by_user(request.user).filter(
+                    deployment__id=int(resolve(request.path).args[0]))
 
         return super(SiteDeploymentInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
@@ -603,16 +650,17 @@
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'slice':
-           kwargs['queryset'] = Slice.select_by_user(request.user)
+            kwargs['queryset'] = Slice.select_by_user(request.user)
         if db_field.name == 'user':
-           # all users are available to be granted SlicePrivilege
-           kwargs['queryset'] = User.objects.all()
+            # all users are available to be granted SlicePrivilege
+            kwargs['queryset'] = User.objects.all()
 
         return super(SlicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
     def queryset(self, request):
         return SlicePrivilege.select_by_user(request.user)
 
+
 class SliceNetworkInline(XOSTabularInline):
     model = Network.slices.through
     selflink_fieldname = "network"
@@ -623,6 +671,7 @@
     fields = ['backend_status_icon', 'network']
     readonly_fields = ('backend_status_icon', )
 
+
 class ImageDeploymentsInline(XOSTabularInline):
     model = ImageDeployments
     extra = 0
@@ -632,6 +681,7 @@
     fields = ['backend_status_icon', 'image', 'deployment']
     readonly_fields = ['backend_status_icon']
 
+
 class ControllerImagesInline(XOSTabularInline):
     model = ControllerImages
     extra = 0
@@ -641,14 +691,17 @@
     fields = ['backend_status_icon', 'image', 'controller', 'glance_image_id']
     readonly_fields = ['backend_status_icon', 'glance_image_id']
 
+
 class SliceRoleAdmin(XOSBaseAdmin):
     model = SliceRole
     pass
 
+
 class SiteRoleAdmin(XOSBaseAdmin):
     model = SiteRole
     pass
 
+
 class DeploymentAdminForm(forms.ModelForm):
     images = forms.ModelMultipleChoiceField(
         queryset=Image.objects.all(),
@@ -666,19 +719,22 @@
             verbose_name=('Flavors'), is_stacked=False
         )
     )
+
     class Meta:
         model = Deployment
-        many_to_many = ["flavors",]
+        many_to_many = ["flavors", ]
 
     def __init__(self, *args, **kwargs):
-      request = kwargs.pop('request', None)
-      super(DeploymentAdminForm, self).__init__(*args, **kwargs)
+        request = kwargs.pop('request', None)
+        super(DeploymentAdminForm, self).__init__(*args, **kwargs)
 
-      self.fields['accessControl'].initial = "allow site " + request.user.site.name
+        self.fields['accessControl'].initial = "allow site " + \
+            request.user.site.name
 
-      if self.instance and self.instance.pk:
-        self.fields['images'].initial = [x.image for x in self.instance.imagedeployments.all()]
-        self.fields['flavors'].initial = self.instance.flavors.all()
+        if self.instance and self.instance.pk:
+            self.fields['images'].initial = [
+                x.image for x in self.instance.imagedeployments.all()]
+            self.fields['flavors'].initial = self.instance.flavors.all()
 
     def manipulate_m2m_objs(self, this_obj, selected_objs, all_relations, relation_class, local_attrname, foreign_attrname):
         """ helper function for handling m2m relations from the MultipleChoiceField
@@ -703,61 +759,70 @@
         existing_dest_objs = []
         for relation in list(all_relations):
             if getattr(relation, foreign_attrname) not in selected_objs:
-                #print "deleting site", sdp.site
+                # print "deleting site", sdp.site
                 relation.delete()
             else:
                 existing_dest_objs.append(getattr(relation, foreign_attrname))
 
         for dest_obj in selected_objs:
             if dest_obj not in existing_dest_objs:
-                #print "adding site", site
+                # print "adding site", site
                 kwargs = {foreign_attrname: dest_obj, local_attrname: this_obj}
                 relation = relation_class(**kwargs)
                 relation.save()
 
     def save(self, commit=True):
-      deployment = super(DeploymentAdminForm, self).save(commit=False)
+        deployment = super(DeploymentAdminForm, self).save(commit=False)
 
-      if commit:
-        deployment.save()
-        # this has to be done after save() if/when a deployment is first created
-        deployment.flavors = self.cleaned_data['flavors']
+        if commit:
+            deployment.save()
+            # this has to be done after save() if/when a deployment is first
+            # created
+            deployment.flavors = self.cleaned_data['flavors']
 
-      if deployment.pk:
-        # save_m2m() doesn't seem to work with 'through' relations. So we
-        #    create/destroy the through models ourselves. There has to be
-        #    a better way...
+        if deployment.pk:
+            # save_m2m() doesn't seem to work with 'through' relations. So we
+            #    create/destroy the through models ourselves. There has to be
+            #    a better way...
 
-        self.manipulate_m2m_objs(deployment, self.cleaned_data['images'], deployment.imagedeployments.all(), ImageDeployments, "deployment", "image")
-        # manipulate_m2m_objs doesn't work for Flavor/Deployment relationship
-        # so well handle that manually here
-        for flavor in deployment.flavors.all():
-            if getattr(flavor, 'name') not in self.cleaned_data['flavors']:
-                deployment.flavors.remove(flavor)
-        for flavor in self.cleaned_data['flavors']:
-            if flavor not in deployment.flavors.all():
-                flavor.deployments.add(deployment)
+            self.manipulate_m2m_objs(deployment, self.cleaned_data[
+                                     'images'], deployment.imagedeployments.all(), ImageDeployments, "deployment", "image")
+            # manipulate_m2m_objs doesn't work for Flavor/Deployment relationship
+            # so well handle that manually here
+            for flavor in deployment.flavors.all():
+                if getattr(flavor, 'name') not in self.cleaned_data['flavors']:
+                    deployment.flavors.remove(flavor)
+            for flavor in self.cleaned_data['flavors']:
+                if flavor not in deployment.flavors.all():
+                    flavor.deployments.add(deployment)
 
-      self.save_m2m()
+        self.save_m2m()
 
-      return deployment
+        return deployment
+
 
 class DeploymentAdminROForm(DeploymentAdminForm):
+
     def save(self, commit=True):
         raise PermissionDenied
 
+
 class SiteAssocInline(XOSTabularInline):
     model = Site.deployments.through
     extra = 0
     suit_classes = 'suit-tab suit-tab-sites'
 
+
 class DeploymentAdmin(XOSBaseAdmin):
     model = Deployment
-    fieldList = ['backend_status_text', 'name', 'images', 'flavors', 'accessControl']
-    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
+    fieldList = ['backend_status_text', 'name',
+                 'images', 'flavors', 'accessControl']
+    fieldsets = [
+        (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     # node no longer directly connected to deployment
     #inlines = [DeploymentPrivilegeInline,NodeInline,TagInline,ImageDeploymentsInline]
-    inlines = [DeploymentPrivilegeInline,TagInline,ImageDeploymentsInline,SiteDeploymentInline]
+    inlines = [DeploymentPrivilegeInline, TagInline,
+               ImageDeploymentsInline, SiteDeploymentInline]
     list_display = ['backend_status_icon', 'name']
     list_display_links = ('backend_status_icon', 'name', )
     readonly_fields = ('backend_status_text', )
@@ -765,48 +830,58 @@
     user_readonly_fields = ['name']
 
     # nodes no longer direclty connected to deployments
-    suit_form_tabs =(('general','Deployment Details'),('deploymentprivileges','Privileges'), ('sitedeployments', 'Sites'))
+    suit_form_tabs = (('general', 'Deployment Details'),
+                      ('deploymentprivileges', 'Privileges'), ('sitedeployments', 'Sites'))
 
     def get_form(self, request, obj=None, **kwargs):
         if request.user.isReadOnlyUser() or not request.user.is_admin:
             kwargs["form"] = DeploymentAdminROForm
         else:
             kwargs["form"] = DeploymentAdminForm
-        adminForm = super(DeploymentAdmin,self).get_form(request, obj, **kwargs)
+        adminForm = super(DeploymentAdmin, self).get_form(
+            request, obj, **kwargs)
 
         # from stackexchange: pass the request object into the form
 
         class AdminFormMetaClass(adminForm):
-           def __new__(cls, *args, **kwargs):
-               kwargs['request'] = request
-               return adminForm(*args, **kwargs)
+
+            def __new__(cls, *args, **kwargs):
+                kwargs['request'] = request
+                return adminForm(*args, **kwargs)
 
         return AdminFormMetaClass
 
+
 class ControllerAdminForm(forms.ModelForm):
     backend_disabled = forms.BooleanField(required=False)
+
     class Meta:
         model = Controller
 
     def __init__(self, *args, **kwargs):
-      request = kwargs.pop('request', None)
-      super(ControllerAdminForm, self).__init__(*args, **kwargs)
+        request = kwargs.pop('request', None)
+        super(ControllerAdminForm, self).__init__(*args, **kwargs)
 
-      if self.instance and self.instance.pk:
-        self.fields['backend_disabled'].initial = self.instance.get_backend_register('disabled', False)
-      else:
-        # defaults when adding new controller
-        self.fields['backend_disabled'].initial = False
+        if self.instance and self.instance.pk:
+            self.fields['backend_disabled'].initial = self.instance.get_backend_register(
+                'disabled', False)
+        else:
+            # defaults when adding new controller
+            self.fields['backend_disabled'].initial = False
 
     def save(self, commit=True):
-      self.instance.set_backend_register("disabled", self.cleaned_data["backend_disabled"])
-      return super(ControllerAdminForm, self).save(commit=commit)
+        self.instance.set_backend_register(
+            "disabled", self.cleaned_data["backend_disabled"])
+        return super(ControllerAdminForm, self).save(commit=commit)
+
 
 class ControllerAdmin(XOSBaseAdmin):
     model = Controller
-    fieldList = ['deployment', 'name', 'backend_type', 'backend_disabled', 'version', 'auth_url', 'admin_user', 'admin_tenant','admin_password', 'domain', 'rabbit_host', 'rabbit_user', 'rabbit_password']
-    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
-    inlines = [ControllerSiteInline] # ,ControllerImagesInline]
+    fieldList = ['deployment', 'name', 'backend_type', 'backend_disabled', 'version', 'auth_url', 'admin_user',
+                 'admin_tenant', 'admin_password', 'domain', 'rabbit_host', 'rabbit_user', 'rabbit_password']
+    fieldsets = [
+        (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
+    inlines = [ControllerSiteInline]  # ,ControllerImagesInline]
     list_display = ['backend_status_icon', 'name', 'version', 'backend_type']
     list_display_links = ('backend_status_icon', 'name', )
     readonly_fields = ('backend_status_text',)
@@ -815,47 +890,52 @@
     user_readonly_fields = []
 
     def save_model(self, request, obj, form, change):
-        # update openstack connection to use this site/tenant
+            # update openstack connection to use this site/tenant
         obj.save_by_user(request.user)
-                    
+
     def delete_model(self, request, obj):
         obj.delete_by_user(request.user)
 
     def queryset(self, request):
-        return Controller.select_by_user(request.user)    
+        return Controller.select_by_user(request.user)
 
     @property
     def suit_form_tabs(self):
         tabs = [('general', 'Controller Details'),
-        ]
+                ]
 
-        request=getattr(_thread_locals, "request", None)
+        request = getattr(_thread_locals, "request", None)
         if request and request.user.is_admin:
-            tabs.append( ('admin-only', 'Admin-Only') )
+            tabs.append(('admin-only', 'Admin-Only'))
 
         return tabs
 
+
 class TenantAttributeAdmin(XOSBaseAdmin):
     model = TenantAttribute
     list_display = ('backend_status_icon', 'tenant', 'name', 'value')
     list_display_links = ('backend_status_icon', 'name')
     fieldList = ('backend_status_text', 'tenant', 'name', 'value', )
-    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
+    fieldsets = [
+        (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', )
 
-    suit_form_tabs =(('general', 'Tenant Root Details'),
-    )
+    suit_form_tabs = (('general', 'Tenant Root Details'),
+                      )
+
 
 class TenantAttrAsTabInline(XOSTabularInline):
     model = TenantAttribute
-    fields = ['name','value']
+    fields = ['name', 'value']
     extra = 0
     suit_classes = 'suit-tab suit-tab-tenantattrs'
 
+
 class TenantRootRoleAdmin(XOSBaseAdmin):
     model = TenantRootRole
     fields = ('role',)
 
+
 class TenantRootTenantInline(XOSTabularInline):
     model = Tenant
     fields = ['provider_service', 'subscriber_root']
@@ -865,10 +945,11 @@
     verbose_name = 'subscribed tenant'
     verbose_name_plural = 'subscribed tenants'
 
-    #def queryset(self, request):
+    # def queryset(self, request):
     #    qs = super(TenantRootTenantInline, self).queryset(request)
     #    return qs.filter(kind="coarse")
 
+
 class TenantRootPrivilegeInline(XOSTabularInline):
     model = TenantRootPrivilege
     extra = 0
@@ -879,19 +960,22 @@
     def queryset(self, request):
         return TenantRootPrivilege.select_by_user(request.user)
 
+
 class TenantRootAdmin(XOSBaseAdmin):
     model = TenantRoot
     list_display = ('backend_status_icon', 'name', 'kind')
     list_display_links = ('backend_status_icon', 'name')
     fieldList = ('backend_status_text', 'name', 'kind', )
-    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
+    fieldsets = [
+        (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     inlines = (TenantRootTenantInline, TenantRootPrivilegeInline)
     readonly_fields = ('backend_status_text', )
 
-    suit_form_tabs =(('general', 'Tenant Root Details'),
-        ('tenantroots','Tenancy'),
-        ('tenantrootprivileges','Privileges')
-    )
+    suit_form_tabs = (('general', 'Tenant Root Details'),
+                      ('tenantroots', 'Tenancy'),
+                      ('tenantrootprivileges', 'Privileges')
+                      )
+
 
 class ProviderTenantInline(XOSTabularInline):
     model = CoarseTenant
@@ -906,6 +990,7 @@
         qs = super(ProviderTenantInline, self).queryset(request)
         return qs.filter(kind="coarse")
 
+
 class SubscriberTenantInline(XOSTabularInline):
     model = CoarseTenant
     fields = ['provider_service', 'subscriber_service', 'connect_method']
@@ -919,28 +1004,35 @@
         qs = super(SubscriberTenantInline, self).queryset(request)
         return qs.filter(kind="coarse")
 
+
 class ServiceAttrAsTabInline(XOSTabularInline):
     model = ServiceAttribute
-    fields = ['name','value']
+    fields = ['name', 'value']
     extra = 0
     suit_classes = 'suit-tab suit-tab-serviceattrs'
 
+
 class ServiceAdmin(XOSBaseAdmin):
-    list_display = ("backend_status_icon","name","kind","versionNumber","enabled","published")
+    list_display = ("backend_status_icon", "name", "kind",
+                    "versionNumber", "enabled", "published")
     list_display_links = ('backend_status_icon', 'name', )
-    fieldList = ["backend_status_text","name","kind","description","versionNumber","enabled","published","view_url","icon_url","public_key","private_key_fn","service_specific_attribute","service_specific_id"]
-    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
-    inlines = [ServiceAttrAsTabInline,SliceInline,ProviderTenantInline,SubscriberTenantInline,ServicePrivilegeInline]
+    fieldList = ["backend_status_text", "name", "kind", "description", "versionNumber", "enabled", "published",
+                 "view_url", "icon_url", "public_key", "private_key_fn", "service_specific_attribute", "service_specific_id"]
+    fieldsets = [
+        (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
+    inlines = [ServiceAttrAsTabInline, SliceInline, ProviderTenantInline,
+               SubscriberTenantInline, ServicePrivilegeInline]
     readonly_fields = ('backend_status_text', )
 
     user_readonly_fields = fieldList
 
-    suit_form_tabs =(('general', 'Service Details'),
-        ('slices','Slices'),
-        ('serviceattrs','Additional Attributes'),
-        ('servicetenants','Tenancy'),
-        ('serviceprivileges','Privileges')
-    )
+    suit_form_tabs = (('general', 'Service Details'),
+                      ('slices', 'Slices'),
+                      ('serviceattrs', 'Additional Attributes'),
+                      ('servicetenants', 'Tenancy'),
+                      ('serviceprivileges', 'Privileges')
+                      )
+
 
 class SiteNodeInline(XOSTabularInline):
     model = Node
@@ -950,43 +1042,50 @@
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         # only display site deployments associated with this site
-        if db_field.name ==  'site_deployment':
-            kwargs['queryset'] = SiteDeployment.objects.filter(site__id=int(request.path.split('/')[-2]))
+        if db_field.name == 'site_deployment':
+            kwargs['queryset'] = SiteDeployment.objects.filter(
+                site__id=int(request.path.split('/')[-2]))
 
         return super(SiteNodeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
+
 class SiteAdmin(XOSBaseAdmin):
     #fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'is_public', 'login_base', 'accountLink','location']
-    fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'login_base', 'location', 'is_public', 'hosts_nodes', 'hosts_users']
+    fieldList = ['backend_status_text', 'name', 'site_url', 'enabled',
+                 'login_base', 'location', 'is_public', 'hosts_nodes', 'hosts_users']
     fieldsets = [
-        (None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),
+        (None, {'fields': fieldList, 'classes': [
+         'suit-tab suit-tab-general']}),
         #('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}),
     ]
     #readonly_fields = ['backend_status_text', 'accountLink']
     readonly_fields = ['backend_status_text']
 
     #user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink']
-    user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'hosts_nodes', 'hosts_users']
+    user_readonly_fields = ['name', 'deployments', 'site_url',
+                            'enabled', 'is_public', 'login_base', 'hosts_nodes', 'hosts_users']
 
-    list_display = ('backend_status_icon', 'name', 'login_base','site_url', 'enabled')
+    list_display = ('backend_status_icon', 'name',
+                    'login_base', 'site_url', 'enabled')
     list_display_links = ('backend_status_icon', 'name', )
     filter_horizontal = ('deployments',)
-    inlines = [SliceInline,UserInline,TagInline, SitePrivilegeInline, SiteNodeInline]
+    inlines = [SliceInline, UserInline, TagInline,
+               SitePrivilegeInline, SiteNodeInline]
     admin_inlines = [ControllerSiteInline]
     search_fields = ['name']
 
     @property
     def suit_form_tabs(self):
         tabs = [('general', 'Site Details'),
-            ('users','Users'),
-            ('siteprivileges','Privileges'),
-            ('slices','Slices'),
-            ('nodes','Nodes'),
-        ]
+                ('users', 'Users'),
+                ('siteprivileges', 'Privileges'),
+                ('slices', 'Slices'),
+                ('nodes', 'Nodes'),
+                ]
 
-        request=getattr(_thread_locals, "request", None)
+        request = getattr(_thread_locals, "request", None)
         if request and request.user.is_admin:
-            tabs.append( ('admin-only', 'Admin-Only') )
+            tabs.append(('admin-only', 'Admin-Only'))
 
         return tabs
 
@@ -1006,7 +1105,7 @@
         link_obj = obj.accounts.all()
         if link_obj:
             reverse_path = "admin:core_account_change"
-            url = reverse(reverse_path, args =(link_obj[0].id,))
+            url = reverse(reverse_path, args=(link_obj[0].id,))
             return "<a href='%s'>%s</a>" % (url, "view billing details")
         else:
             return "no billing data for this site"
@@ -1015,16 +1114,16 @@
 
     def save_model(self, request, obj, form, change):
         # update openstack connection to use this site/tenant
-        obj.save_by_user(request.user) 
+        obj.save_by_user(request.user)
 
     def delete_model(self, request, obj):
         obj.delete_by_user(request.user)
-        
+
 
 class SitePrivilegeAdmin(XOSBaseAdmin):
     fieldList = ['backend_status_text', 'user', 'site', 'role']
     fieldsets = [
-        (None, {'fields': fieldList, 'classes':['collapse']})
+        (None, {'fields': fieldList, 'classes': ['collapse']})
     ]
     readonly_fields = ('backend_status_text', )
     list_display = ('backend_status_icon', 'user', 'site', 'role')
@@ -1046,10 +1145,12 @@
             if not request.user.is_admin:
                 # only show users from sites where caller has admin or pi role
                 roles = Role.objects.filter(role_type__in=['admin', 'pi'])
-                site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles)
+                site_privileges = SitePrivilege.objects.filter(
+                    user=request.user).filter(role__in=roles)
                 sites = [site_privilege.site for site_privilege in site_privileges]
                 site_privileges = SitePrivilege.objects.filter(site__in=sites)
-                emails = [site_privilege.user.email for site_privilege in site_privileges]
+                emails = [
+                    site_privilege.user.email for site_privilege in site_privileges]
                 users = User.objects.filter(email__in=emails)
                 kwargs['queryset'] = users
 
@@ -1059,7 +1160,7 @@
         # admins can see all privileges. Users can only see privileges at sites
         # where they have the admin role or pi role.
         qs = super(SitePrivilegeAdmin, self).queryset(request)
-        #if not request.user.is_admin:
+        # if not request.user.is_admin:
         #    roles = Role.objects.filter(role_type__in=['admin', 'pi'])
         #    site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles)
         #    login_bases = [site_privilege.site.login_base for site_privilege in site_privileges]
@@ -1067,7 +1168,9 @@
         #    qs = qs.filter(site__in=sites)
         return qs
 
+
 class SliceForm(forms.ModelForm):
+
     class Meta:
         model = Slice
         widgets = {
@@ -1081,13 +1184,15 @@
         slice_id = self.instance.id
         if not site and slice_id:
             site = Slice.objects.get(id=slice_id).site
-        if (not isinstance(site,Site)):
+        if (not isinstance(site, Site)):
             # previous code indicates 'site' could be a site_id and not a site?
             site = Slice.objects.get(id=site.id)
         if not name.startswith(site.login_base):
-            raise forms.ValidationError('slice name must begin with %s' % site.login_base)
+            raise forms.ValidationError(
+                'slice name must begin with %s' % site.login_base)
         return cleaned_data
 
+
 class ControllerSliceInline(XOSTabularInline):
     model = ControllerSlice
     extra = 0
@@ -1095,16 +1200,21 @@
     verbose_name_plural = "Controller Slices"
     suit_classes = 'suit-tab suit-tab-admin-only'
     fields = ['backend_status_icon', 'controller', 'tenant_id']
-    readonly_fields = ('backend_status_icon', 'controller' )
+    readonly_fields = ('backend_status_icon', 'controller')
+
 
 class SliceAdmin(XOSBaseAdmin):
     form = SliceForm
-    fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_instances', "default_isolation", "network"]
-    fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),]
+    fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled',
+                 'description', 'service', 'slice_url', 'max_instances', "default_isolation", "network"]
+    fieldsets = [('Slice Details', {'fields': fieldList, 'classes': [
+                  'suit-tab suit-tab-general']}), ]
     readonly_fields = ('backend_status_text', )
-    list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_instances')
+    list_display = ('backend_status_icon', 'name', 'site',
+                    'serviceClass', 'slice_url', 'max_instances')
     list_display_links = ('backend_status_icon', 'name', )
-    normal_inlines = [SlicePrivilegeInline, InstanceInline, TagInline, ReservationInline, SliceNetworkInline]
+    normal_inlines = [SlicePrivilegeInline, InstanceInline,
+                      TagInline, ReservationInline, SliceNetworkInline]
     inlines = normal_inlines
     admin_inlines = [ControllerSliceInline]
     suit_form_includes = (('slice_instance_tab.html', 'bottom', 'instances'),)
@@ -1113,20 +1223,20 @@
 
     @property
     def suit_form_tabs(self):
-        tabs =[('general', 'Slice Details'),
-          ('slicenetworks','Networks'),
-          ('sliceprivileges','Privileges'),
-          ('instances','Instances'),
-          #('reservations','Reservations'), 
-          ('tags','Tags'),
-          ]
+        tabs = [('general', 'Slice Details'),
+                ('slicenetworks', 'Networks'),
+                ('sliceprivileges', 'Privileges'),
+                ('instances', 'Instances'),
+                #('reservations','Reservations'),
+                ('tags', 'Tags'),
+                ]
 
-        request=getattr(_thread_locals, "request", None)
+        request = getattr(_thread_locals, "request", None)
         if request and request.user.is_admin:
-            tabs.append( ('admin-only', 'Admin-Only') )
+            tabs.append(('admin-only', 'Admin-Only'))
 
         return tabs
-    
+
     def add_view(self, request, form_url='', extra_context=None):
         # Ugly hack for CORD
         self.inlines = self.normal_inlines
@@ -1135,26 +1245,30 @@
         return super(SliceAdmin, self).add_view(request, form_url, extra_context=extra_context)
 
     def change_view(self, request, object_id, form_url='', extra_context=None):
-        # cannot change the site of an existing slice so make the site field read only
+        # cannot change the site of an existing slice so make the site field
+        # read only
         if object_id:
-            self.readonly_fields = ('backend_status_text','site')
+            self.readonly_fields = ('backend_status_text', 'site')
 
         return super(SliceAdmin, self).change_view(request, object_id, form_url)
 
     def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
         deployment_nodes = []
         for node in Node.objects.all():
-            deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) )
+            deployment_nodes.append(
+                (node.site_deployment.deployment.id, node.id, node.name))
 
         deployment_flavors = []
         for flavor in Flavor.objects.all():
             for deployment in flavor.deployments.all():
-                deployment_flavors.append( (deployment.id, flavor.id, flavor.name) )
+                deployment_flavors.append(
+                    (deployment.id, flavor.id, flavor.name))
 
         deployment_images = []
         for image in Image.objects.all():
             for deployment_image in image.imagedeployments.all():
-                deployment_images.append( (deployment_image.deployment.id, image.id, image.name) )
+                deployment_images.append(
+                    (deployment_image.deployment.id, image.id, image.name))
 
         site_login_bases = []
         for site in Site.objects.all():
@@ -1168,8 +1282,10 @@
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'site':
-            kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True)
-            kwargs['widget'] = forms.Select(attrs={'onChange': "update_slice_prefix(this, $($(this).closest('fieldset')[0]).find('.field-name input')[0].id)"})
+            kwargs['queryset'] = Site.select_by_user(
+                request.user).filter(hosts_users=True)
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "update_slice_prefix(this, $($(this).closest('fieldset')[0]).find('.field-name input')[0].id)"})
 
         return super(SliceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
@@ -1189,7 +1305,7 @@
     def add_extra_context(self, request, extra_context):
         super(SliceAdmin, self).add_extra_context(request, extra_context)
         # set context["slice_id"] to the PK passed in the URL to this view
-        if len(request.resolver_match.args)>0:
+        if len(request.resolver_match.args) > 0:
             extra_context["slice_id"] = request.resolver_match.args[0]
 
     def UNUSED_get_inline_instances(self, request, obj=None):
@@ -1199,16 +1315,19 @@
         #    XXX this approach is better than clobbering self.inlines, so
         #    try to make this work post-demo.
         if (obj is not None) and (obj.name == "mysite_vcpe"):
-            cord_vcpe_inlines = [ SlicePrivilegeInline, CordInstanceInline, TagInline, ReservationInline,SliceNetworkInline]
+            cord_vcpe_inlines = [SlicePrivilegeInline, CordInstanceInline,
+                                 TagInline, ReservationInline, SliceNetworkInline]
 
-            inlines=[]
+            inlines = []
             for inline_class in cord_vcpe_inlines:
                 inlines.append(inline_class(self.model, self.admin_site))
         else:
-            inlines = super(SliceAdmin, self).get_inline_instances(request, obj)
+            inlines = super(SliceAdmin, self).get_inline_instances(
+                request, obj)
 
         return inlines
 
+
 class SlicePrivilegeAdmin(XOSBaseAdmin):
     fieldsets = [
         (None, {'fields': ['backend_status_text', 'user', 'slice', 'role']})
@@ -1223,7 +1342,7 @@
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'slice':
             kwargs['queryset'] = Slice.select_by_user(request.user)
-        
+
         if db_field.name == 'user':
             kwargs['queryset'] = User.select_by_user(request.user)
 
@@ -1248,23 +1367,27 @@
         obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
         obj.delete()
 
+
 class ImageAdmin(XOSBaseAdmin):
 
     fieldsets = [('Image Details',
-                   {'fields': ['backend_status_text', 'name', 'kind', 'disk_format', 'container_format', 'tag', 'path'],
-                    'classes': ['suit-tab suit-tab-general']})
-               ]
+                  {'fields': ['backend_status_text', 'name', 'kind', 'disk_format', 'container_format', 'tag', 'path'],
+                   'classes': ['suit-tab suit-tab-general']})
+                 ]
     readonly_fields = ('backend_status_text', )
 
-    suit_form_tabs =(('general','Image Details'),('instances','Instances'),('imagedeployments','Deployments'), ('admin-only', 'Admin-Only'))
+    suit_form_tabs = (('general', 'Image Details'), ('instances', 'Instances'),
+                      ('imagedeployments', 'Deployments'), ('admin-only', 'Admin-Only'))
 
     inlines = [InstanceInline, ControllerImagesInline]
 
-    user_readonly_fields = ['name', 'disk_format', 'container_format', 'tag', 'path']
+    user_readonly_fields = ['name', 'disk_format',
+                            'container_format', 'tag', 'path']
 
     list_display = ['backend_status_icon', 'name', 'kind']
     list_display_links = ('backend_status_icon', 'name', )
 
+
 class NodeForm(forms.ModelForm):
     nodelabels = forms.ModelMultipleChoiceField(
         queryset=NodeLabel.objects.all(),
@@ -1274,6 +1397,7 @@
             verbose_name=('Labels'), is_stacked=False
         )
     )
+
     class Meta:
         model = Node
         widgets = {
@@ -1282,21 +1406,21 @@
         }
 
     def __init__(self, *args, **kwargs):
-      request = kwargs.pop('request', None)
-      super(NodeForm, self).__init__(*args, **kwargs)
+        request = kwargs.pop('request', None)
+        super(NodeForm, self).__init__(*args, **kwargs)
 
-      if self.instance and self.instance.pk:
-        self.fields['nodelabels'].initial = self.instance.nodelabels.all()
+        if self.instance and self.instance.pk:
+            self.fields['nodelabels'].initial = self.instance.nodelabels.all()
 
     def save(self, commit=True):
-      node = super(NodeForm, self).save(commit=False)
+        node = super(NodeForm, self).save(commit=False)
 
-      node.nodelabels = self.cleaned_data['nodelabels']
+        node.nodelabels = self.cleaned_data['nodelabels']
 
-      if commit:
-        node.save()
+        if commit:
+            node.save()
 
-      return node
+        return node
 
 
 class NodeLabelAdmin(XOSBaseAdmin):
@@ -1312,25 +1436,30 @@
     list_display_links = ('backend_status_icon', 'name', )
     list_filter = ('site_deployment',)
 
-    inlines = [TagInline,InstanceInline]
+    inlines = [TagInline, InstanceInline]
     fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name', 'site_deployment'], 'classes':['suit-tab suit-tab-details']}),
                  ('Labels', {'fields': ['nodelabels'], 'classes':['suit-tab suit-tab-labels']})]
     readonly_fields = ('backend_status_text', )
 
-    user_readonly_fields = ['name','site_deployment']
-    user_readonly_inlines = [TagInline,InstanceInline]
+    user_readonly_fields = ['name', 'site_deployment']
+    user_readonly_inlines = [TagInline, InstanceInline]
 
-    suit_form_tabs =(('details','Node Details'),('instances','Instances'), ('labels', 'Labels'), ('tags','Tags'))
+    suit_form_tabs = (('details', 'Node Details'), ('instances',
+                                                    'Instances'), ('labels', 'Labels'), ('tags', 'Tags'))
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'site':
-            kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_nodes=True)
+            kwargs['queryset'] = Site.select_by_user(
+                request.user).filter(hosts_nodes=True)
 
-        field = super(NodeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        field = super(NodeAdmin, self).formfield_for_foreignkey(
+            db_field, request, **kwargs)
 
         return field
 
+
 class InstanceForm(forms.ModelForm):
+
     class Meta:
         model = Instance
         ip = forms.CharField(widget=PlainTextWidget)
@@ -1345,12 +1474,16 @@
             'image': LinkedSelect
         }
 
+
 class TagAdmin(XOSBaseAdmin):
-    list_display = ['backend_status_icon', 'service', 'name', 'value', 'content_type', 'content_object',]
+    list_display = ['backend_status_icon', 'service',
+                    'name', 'value', 'content_type', 'content_object', ]
     list_display_links = list_display
-    user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',]
+    user_readonly_fields = ['service', 'name',
+                            'value', 'content_type', 'content_object', ]
     user_readonly_inlines = []
 
+
 class InstancePortInline(XOSTabularInline):
     fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac']
     readonly_fields = ("backend_status_icon", "ip", "mac")
@@ -1361,21 +1494,28 @@
     verbose_name = "Port"
     suit_classes = 'suit-tab suit-tab-ports'
 
+
 class InstanceAdmin(XOSBaseAdmin):
     form = InstanceForm
     fieldsets = [
-        ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'isolation', 'flavor', 'image', 'node', 'parent', 'all_ips_string', 'instance_id', 'instance_name', 'ssh_command', ], 'classes': ['suit-tab suit-tab-general'], }),
-        ('Container Settings', {'fields': ['volumes'], 'classes': ['suit-tab suit-tab-container'], }),
+        ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'isolation', 'flavor', 'image', 'node',
+                                         'parent', 'all_ips_string', 'instance_id', 'instance_name', 'ssh_command', ], 'classes': ['suit-tab suit-tab-general'], }),
+        ('Container Settings', {'fields': ['volumes'], 'classes': [
+         'suit-tab suit-tab-container'], }),
     ]
     readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string')
-    list_display = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'isolation', 'slice', 'flavor', 'image', 'node', 'deployment']
-    list_display_links = ('backend_status_icon', 'all_ips_string', 'instance_id', )
+    list_display = ['backend_status_icon', 'all_ips_string', 'instance_id',
+                    'instance_name', 'isolation', 'slice', 'flavor', 'image', 'node', 'deployment']
+    list_display_links = ('backend_status_icon',
+                          'all_ips_string', 'instance_id', )
 
-    suit_form_tabs =(('general', 'Instance Details'), ('ports', 'Ports'), ('container', 'Container Settings'), ('tags', 'Tags'))
+    suit_form_tabs = (('general', 'Instance Details'), ('ports', 'Ports'),
+                      ('container', 'Container Settings'), ('tags', 'Tags'))
 
     inlines = [TagInline, InstancePortInline]
 
-    user_readonly_fields = ['slice', 'deployment', 'node', 'ip', 'instance_name', 'flavor', 'image']
+    user_readonly_fields = ['slice', 'deployment',
+                            'node', 'ip', 'instance_name', 'flavor', 'image']
 
     def ssh_command(self, obj):
         ssh_command = obj.get_ssh_command()
@@ -1395,30 +1535,36 @@
         # the slices they belong to.
         return Instance.select_by_user(request.user)
 
-    def add_view(self, request, form_url='', extra_context = None):
-        self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string')
-        return super(InstanceAdmin,self).add_view(request, form_url, extra_context)
+    def add_view(self, request, form_url='', extra_context=None):
+        self.readonly_fields = ('backend_status_text',
+                                'ssh_command', 'all_ips_string')
+        return super(InstanceAdmin, self).add_view(request, form_url, extra_context)
 
     def change_view(self, request, object_id, extra_context=None):
-        self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string', 'deployment', 'slice', 'flavor', 'image', 'node')
-        self.readonly_save = self.readonly_fields # for XOSAdminMixin.change_view's user_readonly_fields switching code
-        return super(InstanceAdmin,self).change_view(request, object_id, extra_context)
+        self.readonly_fields = ('backend_status_text', 'ssh_command',
+                                'all_ips_string', 'deployment', 'slice', 'flavor', 'image', 'node')
+        # for XOSAdminMixin.change_view's user_readonly_fields switching code
+        self.readonly_save = self.readonly_fields
+        return super(InstanceAdmin, self).change_view(request, object_id, extra_context)
 
     def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
         deployment_nodes = []
 #        for node in Node.objects.all():
         for node in Node.objects.order_by("name"):
-            deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) )
+            deployment_nodes.append(
+                (node.site_deployment.deployment.id, node.id, node.name))
 
         deployment_flavors = []
         for flavor in Flavor.objects.all():
             for deployment in flavor.deployments.all():
-                deployment_flavors.append( (deployment.id, flavor.id, flavor.name) )
+                deployment_flavors.append(
+                    (deployment.id, flavor.id, flavor.name))
 
         deployment_images = []
         for image in Image.objects.all():
             for deployment_image in image.imagedeployments.all():
-                deployment_images.append( (deployment_image.deployment.id, image.id, image.name) )
+                deployment_images.append(
+                    (deployment_image.deployment.id, image.id, image.name))
 
         site_login_bases = []
         for site in Site.objects.all():
@@ -1432,16 +1578,20 @@
 
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
         if db_field.name == 'deployment':
-           kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct()
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"})
+            kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(
+                sitedeployments__nodes__isnull=False).distinct()
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_deployment_changed(this);"})
         if db_field.name == 'flavor':
-           kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"})
+            kwargs['widget'] = forms.Select(
+                attrs={'onChange': "instance_flavor_changed(this);"})
 
-        field = super(InstanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        field = super(InstanceAdmin, self).formfield_for_foreignkey(
+            db_field, request, **kwargs)
 
         return field
 
-    #def save_model(self, request, obj, form, change):
+    # def save_model(self, request, obj, form, change):
     #    # update openstack connection to use this site/tenant
     #    auth = request.session.get('auth', {})
     #    auth['tenant'] = obj.slice.name
@@ -1449,14 +1599,14 @@
     #    obj.creator = request.user
     #    obj.save()
 
-    #def delete_model(self, request, obj):
+    # def delete_model(self, request, obj):
     #    # update openstack connection to use this site/tenant
     #    auth = request.session.get('auth', {})
     #    auth['tenant'] = obj.slice.name
     #    obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
     #    obj.delete()
 
-#class ContainerPortInline(XOSTabularInline):
+# class ContainerPortInline(XOSTabularInline):
 #    fields = ['backend_status_icon', 'network', 'container', 'ip', 'mac', 'segmentation_id']
 #    readonly_fields = ("backend_status_icon", "ip", "mac", "segmentation_id")
 #    model = Port
@@ -1466,7 +1616,7 @@
 #    verbose_name = "Port"
 #    suit_classes = 'suit-tab suit-tab-ports'
 
-#class ContainerAdmin(XOSBaseAdmin):
+# class ContainerAdmin(XOSBaseAdmin):
 #    fieldsets = [
 #        ('Container Details', {'fields': ['backend_status_text', 'slice', 'node', 'docker_image', 'volumes', 'no_sync'], 'classes': ['suit-tab suit-tab-general'], })
 #    ]
@@ -1489,11 +1639,13 @@
 #        # the slices they belong to.
 #        return Container.select_by_user(request.user)
 
+
 class UserCreationForm(forms.ModelForm):
     """A form for creating new users. Includes all the required
     fields, plus a repeated password."""
     password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
-    password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
+    password2 = forms.CharField(
+        label='Password confirmation', widget=forms.PasswordInput)
 
     class Meta:
         model = User
@@ -1511,7 +1663,7 @@
         # Save the provided password in hashed format
         user = super(UserCreationForm, self).save(commit=False)
         user.password = self.cleaned_data["password1"]
-        #user.set_password(self.cleaned_data["password1"])
+        # user.set_password(self.cleaned_data["password1"])
         if commit:
             user.save()
         return user
@@ -1523,14 +1675,16 @@
     password hash display field.
     """
     password = ReadOnlyPasswordHashField(label='Password',
-                   help_text= '<a href=\"password/\">Change Password</a>.')
+                                         help_text='<a href=\"password/\">Change Password</a>.')
 
-    PROFILE_CHOICES = ((None, '------'), ('regular', 'Regular user'), ('cp', 'Content Provider'))
-    profile = forms.ChoiceField(choices=PROFILE_CHOICES, required=False, label="Quick Profile")
+    PROFILE_CHOICES = ((None, '------'), ('regular',
+                                          'Regular user'), ('cp', 'Content Provider'))
+    profile = forms.ChoiceField(
+        choices=PROFILE_CHOICES, required=False, label="Quick Profile")
 
     class Meta:
         model = User
-        widgets = { 'public_key': UploadTextareaWidget, }
+        widgets = {'public_key': UploadTextareaWidget, }
 
     def clean_password(self):
         # Regardless of what the user provides, return the initial value.
@@ -1540,16 +1694,18 @@
 
     def save(self, *args, **kwargs):
         if self.cleaned_data['profile']:
-             self.instance.apply_profile(self.cleaned_data['profile'])
+            self.instance.apply_profile(self.cleaned_data['profile'])
 
         return super(UserChangeForm, self).save(*args, **kwargs)
 
+
 class UserDashboardViewInline(XOSTabularInline):
     model = UserDashboardView
     extra = 0
     suit_classes = 'suit-tab suit-tab-dashboards'
     fields = ['user', 'dashboardView', 'order']
 
+
 class ControllerUserInline(XOSTabularInline):
     model = ControllerUser
     extra = 0
@@ -1571,24 +1727,28 @@
     # The fields to be used in displaying the User model.
     # These override the definitions on the base UserAdmin
     # that reference specific fields on auth.User.
-    list_display = ('backend_status_icon', 'email', 'firstname', 'lastname', 'site', 'last_login')
+    list_display = ('backend_status_icon', 'email',
+                    'firstname', 'lastname', 'site', 'last_login')
     list_display_links = ("email",)
     list_filter = ('site',)
-    inlines = [SlicePrivilegeInline,SitePrivilegeInline]
+    inlines = [SlicePrivilegeInline, SitePrivilegeInline]
     admin_inlines = [ControllerUserInline]
-    fieldListLoginDetails = ['backend_status_text', 'email', 'site','password','is_active','is_readonly','is_admin','is_appuser', 'public_key', 'login_page', 'profile']
-    fieldListContactInfo = ['firstname','lastname','phone','timezone']
+    fieldListLoginDetails = ['backend_status_text', 'email', 'site', 'password', 'is_active',
+                             'is_readonly', 'is_admin', 'is_appuser', 'public_key', 'login_page', 'profile']
+    fieldListContactInfo = ['firstname', 'lastname', 'phone', 'timezone']
 
     fieldsets = (
-        ('Login Details', {'fields': ['backend_status_text', 'email', 'site','password', 'is_active', 'is_readonly', 'is_admin', 'is_appuser', 'public_key'], 'classes':['suit-tab suit-tab-general']}),
-        ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}),
+        ('Login Details', {'fields': ['backend_status_text', 'email', 'site', 'password', 'is_active',
+                                      'is_readonly', 'is_admin', 'is_appuser', 'public_key'], 'classes': ['suit-tab suit-tab-general']}),
+        ('Contact Information', {'fields': (
+            'firstname', 'lastname', 'phone', 'timezone'), 'classes': ['suit-tab suit-tab-contact']}),
         #('Important dates', {'fields': ('last_login',)}),
     )
     add_fieldsets = (
         (None, {
             'classes': ('wide',),
-            'fields': ('site', 'email', 'firstname', 'lastname', 'is_admin', 'is_readonly', 'is_appuser', 'phone', 'public_key','password1', 'password2')},
-        ),
+            'fields': ('site', 'email', 'firstname', 'lastname', 'is_admin', 'is_readonly', 'is_appuser', 'phone', 'public_key', 'password1', 'password2')},
+         ),
     )
     readonly_fields = ('backend_status_text', )
     search_fields = ('email',)
@@ -1602,20 +1762,21 @@
         if getattr(_thread_locals, "obj", None) is None:
             return []
         else:
-            tabs = [('general','Login Details'),
-                         ('contact','Contact Information'),
-                         ('sliceprivileges','Slice Privileges'),
-                         ('siteprivileges','Site Privileges')]
+            tabs = [('general', 'Login Details'),
+                    ('contact', 'Contact Information'),
+                    ('sliceprivileges', 'Slice Privileges'),
+                    ('siteprivileges', 'Site Privileges')]
 
-            request=getattr(_thread_locals, "request", None)
+            request = getattr(_thread_locals, "request", None)
             if request and request.user.is_admin:
-                tabs.append( ('admin-only', 'Admin-Only') )
+                tabs.append(('admin-only', 'Admin-Only'))
 
             return tabs
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'site':
-            kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True)
+            kwargs['queryset'] = Site.select_by_user(
+                request.user).filter(hosts_users=True)
 
         return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
@@ -1635,14 +1796,17 @@
                 login_details_fields.remove('is_admin')
             if 'profile' in login_details_fields:
                 login_details_fields.remove('profile')
-            #if len(request.user.siteprivileges.filter(role__role = 'pi')) > 0:
+            # if len(request.user.siteprivileges.filter(role__role = 'pi')) > 0:
                 # only admins and pis can change a user's site
-            #    self.readonly_fields = ('backend_status_text', 'site') 
+            #    self.readonly_fields = ('backend_status_text', 'site')
         self.fieldsets = (
-            ('Login Details', {'fields': login_details_fields, 'classes':['suit-tab suit-tab-general']}),
-            ('Contact Information', {'fields': self.fieldListContactInfo, 'classes':['suit-tab suit-tab-contact']}),
+            ('Login Details', {'fields': login_details_fields,
+                               'classes': ['suit-tab suit-tab-general']}),
+            ('Contact Information', {
+             'fields': self.fieldListContactInfo, 'classes': ['suit-tab suit-tab-contact']}),
         )
-        return super(UserAdmin, self).get_form(request, obj, **kwargs)     
+        return super(UserAdmin, self).get_form(request, obj, **kwargs)
+
 
 class ControllerDashboardViewInline(XOSTabularInline):
     model = ControllerDashboardView
@@ -1650,42 +1814,49 @@
     fields = ["controller", "url"]
     suit_classes = 'suit-tab suit-tab-controllers'
 
+
 class DashboardViewAdmin(XOSBaseAdmin):
     fieldsets = [('Dashboard View Details',
-                   {'fields': ['backend_status_text', 'name', 'url', 'enabled', 'deployments'],
-                    'classes': ['suit-tab suit-tab-general']})
-               ]
+                  {'fields': ['backend_status_text', 'name', 'url', 'enabled', 'deployments'],
+                   'classes': ['suit-tab suit-tab-general']})
+                 ]
     list_display = ["name", "enabled", "url"]
     readonly_fields = ('backend_status_text', )
     inlines = [ControllerDashboardViewInline]
 
-    suit_form_tabs =(('general','Dashboard View Details'),
-                     ('controllers', 'Per-controller Dashboard Details'))
+    suit_form_tabs = (('general', 'Dashboard View Details'),
+                      ('controllers', 'Per-controller Dashboard Details'))
+
 
 class ServiceResourceInline(XOSTabularInline):
     model = ServiceResource
     extra = 0
 
+
 class ServiceClassAdmin(XOSBaseAdmin):
-    list_display = ('backend_status_icon', 'name', 'commitment', 'membershipFee')
+    list_display = ('backend_status_icon', 'name',
+                    'commitment', 'membershipFee')
     list_display_links = ('backend_status_icon', 'name', )
     inlines = [ServiceResourceInline]
 
     user_readonly_fields = ['name', 'commitment', 'membershipFee']
     user_readonly_inlines = []
 
+
 class ReservedResourceInline(XOSTabularInline):
     model = ReservedResource
     extra = 0
     suit_classes = 'suit-tab suit-tab-reservedresources'
 
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
-        field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        field = super(ReservedResourceInline, self).formfield_for_foreignkey(
+            db_field, request, **kwargs)
 
         if db_field.name == 'resource':
             # restrict resources to those that the slice's service class allows
             if request._slice is not None:
-                field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True)
+                field.queryset = field.queryset.filter(
+                    serviceClass=request._slice.serviceClass, calendarReservable=True)
                 if len(field.queryset) > 0:
                     field.initial = field.queryset.all()[0]
             else:
@@ -1693,7 +1864,7 @@
         elif db_field.name == 'instance':
             # restrict instances to those that belong to the slice
             if request._slice is not None:
-                field.queryset = field.queryset.filter(slice = request._slice)
+                field.queryset = field.queryset.filter(slice=request._slice)
             else:
                 field.queryset = field.queryset.none()
 
@@ -1702,31 +1873,37 @@
     def queryset(self, request):
         return ReservedResource.select_by_user(request.user)
 
+
 class ReservationChangeForm(forms.ModelForm):
+
     class Meta:
         model = Reservation
         widgets = {
-            'slice' : LinkedSelect
+            'slice': LinkedSelect
         }
 
+
 class ReservationAddForm(forms.ModelForm):
-    slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"}))
+    slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(
+        attrs={"onChange": "document.getElementById('id_refresh').value=1; submit()"}))
     refresh = forms.CharField(widget=forms.HiddenInput())
 
     class Media:
-       css = {'all': ('xos.css',)}   # .field-refresh { display: none; }
+        css = {'all': ('xos.css',)}   # .field-refresh { display: none; }
 
     def clean_slice(self):
         slice = self.cleaned_data.get("slice")
-        x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True)
+        x = ServiceResource.objects.filter(
+            serviceClass=slice.serviceClass, calendarReservable=True)
         if len(x) == 0:
-            raise forms.ValidationError("The slice you selected does not have a service class that allows reservations")
+            raise forms.ValidationError(
+                "The slice you selected does not have a service class that allows reservations")
         return slice
 
     class Meta:
         model = Reservation
         widgets = {
-            'slice' : LinkedSelect
+            'slice': LinkedSelect
         }
 
 
@@ -1750,17 +1927,21 @@
         return result
 
     """ don't save anything """
+
     def is_valid(self):
         return False
 
+
 class ReservationAdmin(XOSBaseAdmin):
     fieldList = ['backend_status_text', 'slice', 'startTime', 'duration']
-    fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
+    fieldsets = [('Reservation Details', {
+                  'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', )
     list_display = ('startTime', 'duration')
     form = ReservationAddForm
 
-    suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources'))
+    suit_form_tabs = (('general', 'Reservation Details'),
+                      ('reservedresources', 'Reserved Resources'))
 
     inlines = [ReservedResourceInline]
     user_readonly_fields = fieldList
@@ -1772,20 +1953,21 @@
         if request.method == 'POST':
             # "refresh" will be set to "1" if the form was submitted due to
             # a change in the Slice dropdown.
-            if request.POST.get("refresh","1") == "1":
+            if request.POST.get("refresh", "1") == "1":
                 request._refresh = True
                 request.POST["refresh"] = "0"
 
             # Keep track of the slice that was selected, so the
             # reservedResource inline can filter items for the slice.
-            request._slice = request.POST.get("slice",None)
+            request._slice = request.POST.get("slice", None)
             if (request._slice is not None):
                 request._slice = Slice.objects.get(id=request._slice)
 
-        result =  super(ReservationAdmin, self).add_view(request, form_url, extra_context)
+        result = super(ReservationAdmin, self).add_view(
+            request, form_url, extra_context)
         return result
 
-    def changelist_view(self, request, extra_context = None):
+    def changelist_view(self, request, extra_context=None):
         timezone.activate(request.user.timezone)
         return super(ReservationAdmin, self).changelist_view(request, extra_context)
 
@@ -1814,18 +1996,21 @@
     def queryset(self, request):
         return Reservation.select_by_user(request.user)
 
+
 class NetworkParameterTypeAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "name", )
     list_display_links = ('backend_status_icon', 'name', )
     user_readonly_fields = ['name']
     user_readonly_inlines = []
 
+
 class RouterAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "name", )
     list_display_links = ('backend_status_icon', 'name', )
     user_readonly_fields = ['name']
     user_readonly_inlines = []
 
+
 class RouterInline(XOSTabularInline):
     model = Router.networks.through
     extra = 0
@@ -1833,6 +2018,7 @@
     verbose_name = "Router"
     suit_classes = 'suit-tab suit-tab-routers'
 
+
 class NetworkParameterInline(PlStackGenericTabularInline):
     model = NetworkParameter
     extra = 0
@@ -1842,6 +2028,7 @@
     fields = ['backend_status_icon', 'parameter', 'value']
     readonly_fields = ('backend_status_icon', )
 
+
 class NetworkPortInline(XOSTabularInline):
     fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac']
     readonly_fields = ("backend_status_icon", "ip", "mac")
@@ -1852,6 +2039,7 @@
     verbose_name = "Port"
     suit_classes = 'suit-tab suit-tab-ports'
 
+
 class NetworkSlicesInline(XOSTabularInline):
     model = NetworkSlice
     selflink_fieldname = "slice"
@@ -1859,19 +2047,23 @@
     verbose_name_plural = "Slices"
     verbose_name = "Slice"
     suit_classes = 'suit-tab suit-tab-networkslices'
-    fields = ['backend_status_icon', 'network','slice']
+    fields = ['backend_status_icon', 'network', 'slice']
     readonly_fields = ('backend_status_icon', )
 
+
 class ControllerNetworkInline(XOSTabularInline):
     model = ControllerNetwork
     extra = 0
     verbose_name_plural = "Controller Networks"
     verbose_name = "Controller Network"
     suit_classes = 'suit-tab suit-tab-admin-only'
-    fields = ['backend_status_icon', 'controller','net_id','subnet_id','subnet']
+    fields = ['backend_status_icon', 'controller',
+              'net_id', 'subnet_id', 'subnet']
     readonly_fields = ('backend_status_icon', )
 
+
 class NetworkForm(forms.ModelForm):
+
     class Meta:
         model = Network
         widgets = {
@@ -1879,57 +2071,62 @@
             'controllerParameters': UploadTextareaWidget,
         }
 
+
 class NetworkAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "name", "subnet", "ports", "labels")
     list_display_links = ('backend_status_icon', 'name', )
     readonly_fields = ("subnet", )
-    inlines = [NetworkParameterInline, NetworkPortInline, NetworkSlicesInline, RouterInline]
+    inlines = [NetworkParameterInline, NetworkPortInline,
+               NetworkSlicesInline, RouterInline]
     admin_inlines = [ControllerNetworkInline]
 
-    form=NetworkForm
+    form = NetworkForm
 
     fieldsets = [
-        (None, {'fields': ['backend_status_text', 'name','template','ports','labels',
-                           'owner','guaranteed_bandwidth', 'permit_all_slices',
-                           'permitted_slices','network_id','router_id','subnet_id',
+        (None, {'fields': ['backend_status_text', 'name', 'template', 'ports', 'labels',
+                           'owner', 'guaranteed_bandwidth', 'permit_all_slices',
+                           'permitted_slices', 'network_id', 'router_id', 'subnet_id',
                            'subnet', 'autoconnect'],
                 'classes':['suit-tab suit-tab-general']}),
         (None, {'fields': ['topology_parameters', 'controller_url', 'controller_parameters'],
                 'classes':['suit-tab suit-tab-sdn']}),
-                ]
+    ]
 
     readonly_fields = ('backend_status_text', )
-    user_readonly_fields = ['name','template','ports','labels','owner','guaranteed_bandwidth',
-                            'permit_all_slices','permitted_slices','network_id','router_id',
-                            'subnet_id','subnet','autoconnect']
+    user_readonly_fields = ['name', 'template', 'ports', 'labels', 'owner', 'guaranteed_bandwidth',
+                            'permit_all_slices', 'permitted_slices', 'network_id', 'router_id',
+                            'subnet_id', 'subnet', 'autoconnect']
 
     @property
     def suit_form_tabs(self):
-        tabs=[('general','Network Details'),
-            ('sdn', 'SDN Configuration'),
-            ('netparams', 'Parameters'),
-            ('ports','Ports'),
-            ('networkslices','Slices'),
-            ('routers','Routers'),
-        ]
+        tabs = [('general', 'Network Details'),
+                ('sdn', 'SDN Configuration'),
+                ('netparams', 'Parameters'),
+                ('ports', 'Ports'),
+                ('networkslices', 'Slices'),
+                ('routers', 'Routers'),
+                ]
 
-        request=getattr(_thread_locals, "request", None)
+        request = getattr(_thread_locals, "request", None)
         if request and request.user.is_admin:
-            tabs.append( ('admin-only', 'Admin-Only') )
+            tabs.append(('admin-only', 'Admin-Only'))
 
         return tabs
 
 
 class NetworkTemplateAdmin(XOSBaseAdmin):
-    list_display = ("backend_status_icon", "name", "guaranteed_bandwidth", "visibility")
+    list_display = ("backend_status_icon", "name",
+                    "guaranteed_bandwidth", "visibility")
     list_display_links = ('backend_status_icon', 'name', )
     user_readonly_fields = ["name", "guaranteed_bandwidth", "visibility"]
     user_readonly_inlines = []
-    inlines = [NetworkParameterInline,]
+    inlines = [NetworkParameterInline, ]
     fieldsets = [
         (None, {'fields': ['name', 'description', 'guaranteed_bandwidth', 'visibility', 'translation', 'access', 'shared_network_name', 'shared_network_id', 'topology_kind', 'controller_kind'],
-                'classes':['suit-tab suit-tab-general']}),]
-    suit_form_tabs = (('general','Network Template Details'), ('netparams', 'Parameters') )
+                'classes':['suit-tab suit-tab-general']}), ]
+    suit_form_tabs = (('general', 'Network Template Details'),
+                      ('netparams', 'Parameters'))
+
 
 class PortAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "id", "ip")
@@ -1940,59 +2137,70 @@
     fieldsets = [
         (None, {'fields': ['backend_status_text', 'network', 'instance', 'ip', 'port_id', 'mac'],
                 'classes':['suit-tab suit-tab-general']}),
-                ]
+    ]
 
     readonly_fields = ('backend_status_text', )
     suit_form_tabs = (('general', 'Port Details'), ('netparams', 'Parameters'))
 
+
 class FlavorAdmin(XOSBaseAdmin):
-    list_display = ("backend_status_icon", "name", "flavor", "order", "default")
+    list_display = ("backend_status_icon", "name",
+                    "flavor", "order", "default")
     list_display_links = ("backend_status_icon", "name")
     user_readonly_fields = ("name", "flavor")
     fields = ("name", "description", "flavor", "order", "default")
 
 # register a signal that caches the user's credentials when they log in
+
+
 def cache_credentials(sender, user, request, **kwds):
     auth = {'username': request.POST['username'],
             'password': request.POST['password']}
     request.session['auth'] = auth
 user_logged_in.connect(cache_credentials)
 
+
 def dollar_field(fieldName, short_description):
     def newFunc(self, obj):
         try:
-            x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0))
+            x = "$ %0.2f" % float(getattr(obj, fieldName, 0.0))
         except:
-            x=getattr(obj, fieldName, 0.0)
+            x = getattr(obj, fieldName, 0.0)
         return x
     newFunc.short_description = short_description
     return newFunc
 
+
 def right_dollar_field(fieldName, short_description):
     def newFunc(self, obj):
         try:
             #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
-            x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
+            x = '<div align=right>$ %0.2f</div>' % float(
+                getattr(obj, fieldName, 0.0))
         except:
-            x=getattr(obj, fieldName, 0.0)
+            x = getattr(obj, fieldName, 0.0)
         return x
     newFunc.short_description = short_description
     newFunc.allow_tags = True
     return newFunc
 
+
 class InvoiceChargeInline(XOSTabularInline):
     model = Charge
     extra = 0
     verbose_name_plural = "Charges"
     verbose_name = "Charge"
     exclude = ['account']
-    fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
-    readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
+    fields = ["date", "kind", "state", "object",
+              "coreHours", "dollar_amount", "slice"]
+    readonly_fields = ["date", "kind", "state",
+                       "object", "coreHours", "dollar_amount", "slice"]
     can_delete = False
     max_num = 0
 
     dollar_amount = right_dollar_field("amount", "Amount")
 
+
 class InvoiceAdmin(admin.ModelAdmin):
     list_display = ("date", "account")
 
@@ -2003,6 +2211,7 @@
 
     dollar_amount = dollar_field("amount", "Amount")
 
+
 class InvoiceInline(XOSTabularInline):
     model = Invoice
     extra = 0
@@ -2011,22 +2220,25 @@
     fields = ["date", "dollar_amount"]
     readonly_fields = ["date", "dollar_amount"]
     suit_classes = 'suit-tab suit-tab-accountinvoice'
-    can_delete=False
-    max_num=0
+    can_delete = False
+    max_num = 0
 
     dollar_amount = right_dollar_field("amount", "Amount")
 
+
 class PendingChargeInline(XOSTabularInline):
     model = Charge
     extra = 0
     verbose_name_plural = "Charges"
     verbose_name = "Charge"
     exclude = ["invoice"]
-    fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
-    readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
+    fields = ["date", "kind", "state", "object",
+              "coreHours", "dollar_amount", "slice"]
+    readonly_fields = ["date", "kind", "state",
+                       "object", "coreHours", "dollar_amount", "slice"]
     suit_classes = 'suit-tab suit-tab-accountpendingcharges'
-    can_delete=False
-    max_num=0
+    can_delete = False
+    max_num = 0
 
     def queryset(self, request):
         qs = super(PendingChargeInline, self).queryset(request)
@@ -2035,41 +2247,46 @@
 
     dollar_amount = right_dollar_field("amount", "Amount")
 
+
 class PaymentInline(XOSTabularInline):
-    model=Payment
+    model = Payment
     extra = 1
     verbose_name_plural = "Payments"
     verbose_name = "Payment"
     fields = ["date", "dollar_amount"]
     readonly_fields = ["date", "dollar_amount"]
     suit_classes = 'suit-tab suit-tab-accountpayments'
-    can_delete=False
-    max_num=0
+    can_delete = False
+    max_num = 0
 
     dollar_amount = right_dollar_field("amount", "Amount")
 
+
 class AccountAdmin(admin.ModelAdmin):
     list_display = ("site", "balance_due")
 
     inlines = [InvoiceInline, PaymentInline, PendingChargeInline]
 
     fieldsets = [
-        (None, {'fields': ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'],'classes':['suit-tab suit-tab-general']}),]
+        (None, {'fields': ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'], 'classes':['suit-tab suit-tab-general']}), ]
 
-    readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments']
+    readonly_fields = ['site', 'dollar_balance_due',
+                       'dollar_total_invoices', 'dollar_total_payments']
 
-    suit_form_tabs =(
-        ('general','Account Details'),
+    suit_form_tabs = (
+        ('general', 'Account Details'),
         ('accountinvoice', 'Invoices'),
         ('accountpayments', 'Payments'),
-        ('accountpendingcharges','Pending Charges'),
+        ('accountpendingcharges', 'Pending Charges'),
     )
 
     dollar_balance_due = dollar_field("balance_due", "Balance Due")
     dollar_total_invoices = dollar_field("total_invoices", "Total Invoices")
     dollar_total_payments = dollar_field("total_payments", "Total Payments")
 
+
 class ProgramForm(forms.ModelForm):
+
     class Meta:
         model = Program
         widgets = {
@@ -2079,11 +2296,12 @@
             'output': forms.Textarea(attrs={'rows': 3, 'cols': 80, 'class': 'input-xxlarge'})
         }
 
+
 class ProgramAdmin(XOSBaseAdmin):
     list_display = ("name", "status")
     list_display_links = ('name', "status")
 
-    form=ProgramForm
+    form = ProgramForm
 
     fieldsets = [
         (None, {'fields': ['name', 'command', 'kind', 'description', 'output', 'status'],
@@ -2092,49 +2310,52 @@
                 'classes':['suit-tab suit-tab-contents']}),
         (None, {'fields': ['messages'],
                 'classes':['suit-tab suit-tab-messages']}),
-                ]
+    ]
 
     readonly_fields = ("status",)
 
     @property
     def suit_form_tabs(self):
-        tabs=[('general','Program Details'),
-              ('contents','Program Source'),
-              ('messages','Messages'),
-        ]
+        tabs = [('general', 'Program Details'),
+                ('contents', 'Program Source'),
+                ('messages', 'Messages'),
+                ]
 
-        request=getattr(_thread_locals, "request", None)
+        request = getattr(_thread_locals, "request", None)
         if request and request.user.is_admin:
-            tabs.append( ('admin-only', 'Admin-Only') )
+            tabs.append(('admin-only', 'Admin-Only'))
 
         return tabs
 
+
 class AddressPoolForm(forms.ModelForm):
+
     class Meta:
         model = Program
         widgets = {
             'addresses': UploadTextareaWidget(attrs={'rows': 20, 'cols': 80, 'class': "input-xxlarge"}),
         }
 
+
 class AddressPoolAdmin(XOSBaseAdmin):
     list_display = ("name", "cidr")
     list_display_links = ('name',)
 
-    form=AddressPoolForm
+    form = AddressPoolForm
 
     fieldsets = [
         (None, {'fields': ['name', 'cidr', 'gateway_ip', 'gateway_mac', 'addresses', 'inuse', 'service'],
                 'classes':['suit-tab suit-tab-general']}),
-                ]
+    ]
 
     readonly_fields = ("status",)
 
     @property
     def suit_form_tabs(self):
-        tabs=[('general','Program Details'),
-              ('contents','Program Source'),
-              ('messages','Messages'),
-        ]
+        tabs = [('general', 'Program Details'),
+                ('contents', 'Program Source'),
+                ('messages', 'Messages'),
+                ]
 
 #        request=getattr(_thread_locals, "request", None)
 #        if request and request.user.is_admin:
@@ -2146,9 +2367,9 @@
 admin.site.register(User, UserAdmin)
 # ... and, since we're not using Django's builtin permissions,
 # unregister the Group model from admin.
-#admin.site.unregister(Group)
+# admin.site.unregister(Group)
 
-# When debugging it is often easier to see all the classes, but for regular use 
+# When debugging it is often easier to see all the classes, but for regular use
 # only the top-levels should be displayed
 showAll = False
 
@@ -2185,4 +2406,3 @@
     admin.site.register(TenantRootRole, TenantRootRoleAdmin)
     admin.site.register(TenantAttribute, TenantAttributeAdmin)
     admin.site.register(AddressPool, AddressPoolAdmin)
-
diff --git a/xos/core/migrations/0001_initial.py b/xos/core/migrations/0001_initial.py
index db7dad0..b2e5d00 100644
--- a/xos/core/migrations/0001_initial.py
+++ b/xos/core/migrations/0001_initial.py
@@ -1,15 +1,15 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
-from django.db import models, migrations
-import timezones.fields
 import core.models.instance
 import core.models.network
-import geoposition.fields
-import encrypted_fields.fields
 import core.models.serviceclass
 import django.utils.timezone
+import encrypted_fields.fields
+import geoposition.fields
+import timezones.fields
 from django.conf import settings
+from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
@@ -22,16 +22,24 @@
         migrations.CreateModel(
             name='User',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('password', models.CharField(max_length=128, verbose_name='password')),
-                ('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
-                ('email', models.EmailField(unique=True, max_length=255, verbose_name=b'email address', db_index=True)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('password', models.CharField(
+                    max_length=128, verbose_name='password')),
+                ('last_login', models.DateTimeField(
+                    default=django.utils.timezone.now, verbose_name='last login')),
+                ('email', models.EmailField(unique=True, max_length=255,
+                                            verbose_name=b'email address', db_index=True)),
                 ('username', models.CharField(default=b'Something', max_length=255)),
-                ('firstname', models.CharField(help_text=b"person's given name", max_length=200)),
-                ('lastname', models.CharField(help_text=b"person's surname", max_length=200)),
-                ('phone', models.CharField(help_text=b'phone number contact', max_length=100, null=True, blank=True)),
+                ('firstname', models.CharField(
+                    help_text=b"person's given name", max_length=200)),
+                ('lastname', models.CharField(
+                    help_text=b"person's surname", max_length=200)),
+                ('phone', models.CharField(help_text=b'phone number contact',
+                                           max_length=100, null=True, blank=True)),
                 ('user_url', models.URLField(null=True, blank=True)),
-                ('public_key', models.TextField(help_text=b'Public key string', max_length=1024, null=True, blank=True)),
+                ('public_key', models.TextField(
+                    help_text=b'Public key string', max_length=1024, null=True, blank=True)),
                 ('is_active', models.BooleanField(default=True)),
                 ('is_admin', models.BooleanField(default=True)),
                 ('is_staff', models.BooleanField(default=True)),
@@ -40,9 +48,11 @@
                 ('updated', models.DateTimeField(auto_now=True)),
                 ('enacted', models.DateTimeField(default=None, null=True)),
                 ('policed', models.DateTimeField(default=None, null=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('timezone', timezones.fields.TimeZoneField(default=b'America/New_York', max_length=100, choices=[(b'Pacific/Midway', b'(GMT-1100) Pacific/Midway'), (b'Pacific/Niue', b'(GMT-1100) Pacific/Niue'), (b'Pacific/Pago_Pago', b'(GMT-1100) Pacific/Pago_Pago'), (b'America/Adak', b'(GMT-1000) America/Adak'), (b'Pacific/Honolulu', b'(GMT-1000) Pacific/Honolulu'), (b'Pacific/Johnston', b'(GMT-1000) Pacific/Johnston'), (b'Pacific/Rarotonga', b'(GMT-1000) Pacific/Rarotonga'), (b'Pacific/Tahiti', b'(GMT-1000) Pacific/Tahiti'), (b'US/Hawaii', b'(GMT-1000) US/Hawaii'), (b'Pacific/Marquesas', b'(GMT-0930) Pacific/Marquesas'), (b'America/Anchorage', b'(GMT-0900) America/Anchorage'), (b'America/Juneau', b'(GMT-0900) America/Juneau'), (b'America/Nome', b'(GMT-0900) America/Nome'), (b'America/Sitka', b'(GMT-0900) America/Sitka'), (b'America/Yakutat', b'(GMT-0900) America/Yakutat'), (b'Pacific/Gambier', b'(GMT-0900) Pacific/Gambier'), (b'US/Alaska', b'(GMT-0900) US/Alaska'), (b'America/Dawson', b'(GMT-0800) America/Dawson'), (b'America/Los_Angeles', b'(GMT-0800) America/Los_Angeles'), (b'America/Metlakatla', b'(GMT-0800) America/Metlakatla'), (b'America/Santa_Isabel', b'(GMT-0800) America/Santa_Isabel'), (b'America/Tijuana', b'(GMT-0800) America/Tijuana'), (b'America/Vancouver', b'(GMT-0800) America/Vancouver'), (b'America/Whitehorse', b'(GMT-0800) America/Whitehorse'), (b'Canada/Pacific', b'(GMT-0800) Canada/Pacific'), (b'Pacific/Pitcairn', b'(GMT-0800) Pacific/Pitcairn'), (b'US/Pacific', b'(GMT-0800) US/Pacific'), (b'America/Boise', b'(GMT-0700) America/Boise'), (b'America/Cambridge_Bay', b'(GMT-0700) America/Cambridge_Bay'), (b'America/Chihuahua', b'(GMT-0700) America/Chihuahua'), (b'America/Creston', b'(GMT-0700) America/Creston'), (b'America/Dawson_Creek', b'(GMT-0700) America/Dawson_Creek'), (b'America/Denver', b'(GMT-0700) America/Denver'), (b'America/Edmonton', b'(GMT-0700) America/Edmonton'), (b'America/Hermosillo', b'(GMT-0700) America/Hermosillo'), (b'America/Inuvik', b'(GMT-0700) America/Inuvik'), (b'America/Mazatlan', b'(GMT-0700) America/Mazatlan'), (b'America/Ojinaga', b'(GMT-0700) America/Ojinaga'), (b'America/Phoenix', b'(GMT-0700) America/Phoenix'), (b'America/Shiprock', b'(GMT-0700) America/Shiprock'), (b'America/Yellowknife', b'(GMT-0700) America/Yellowknife'), (b'Canada/Mountain', b'(GMT-0700) Canada/Mountain'), (b'US/Arizona', b'(GMT-0700) US/Arizona'), (b'US/Mountain', b'(GMT-0700) US/Mountain'), (b'America/Bahia_Banderas', b'(GMT-0600) America/Bahia_Banderas'), (b'America/Belize', b'(GMT-0600) America/Belize'), (b'America/Cancun', b'(GMT-0600) America/Cancun'), (b'America/Chicago', b'(GMT-0600) America/Chicago'), (b'America/Costa_Rica', b'(GMT-0600) America/Costa_Rica'), (b'America/El_Salvador', b'(GMT-0600) America/El_Salvador'), (b'America/Guatemala', b'(GMT-0600) America/Guatemala'), (b'America/Indiana/Knox', b'(GMT-0600) America/Indiana/Knox'), (b'America/Indiana/Tell_City', b'(GMT-0600) America/Indiana/Tell_City'), (b'America/Managua', b'(GMT-0600) America/Managua'), (b'America/Matamoros', b'(GMT-0600) America/Matamoros'), (b'America/Menominee', b'(GMT-0600) America/Menominee'), (b'America/Merida', b'(GMT-0600) America/Merida'), (b'America/Mexico_City', b'(GMT-0600) America/Mexico_City'), (b'America/Monterrey', b'(GMT-0600) America/Monterrey'), (b'America/North_Dakota/Beulah', b'(GMT-0600) America/North_Dakota/Beulah'), (b'America/North_Dakota/Center', b'(GMT-0600) America/North_Dakota/Center'), (b'America/North_Dakota/New_Salem', b'(GMT-0600) America/North_Dakota/New_Salem'), (b'America/Rainy_River', b'(GMT-0600) America/Rainy_River'), (b'America/Rankin_Inlet', b'(GMT-0600) America/Rankin_Inlet'), (b'America/Regina', b'(GMT-0600) America/Regina'), (b'America/Resolute', b'(GMT-0600) America/Resolute'), (b'America/Swift_Current', b'(GMT-0600) America/Swift_Current'), (b'America/Tegucigalpa', b'(GMT-0600) America/Tegucigalpa'), (b'America/Winnipeg', b'(GMT-0600) America/Winnipeg'), (b'Canada/Central', b'(GMT-0600) Canada/Central'), (b'Pacific/Galapagos', b'(GMT-0600) Pacific/Galapagos'), (b'US/Central', b'(GMT-0600) US/Central'), (b'America/Atikokan', b'(GMT-0500) America/Atikokan'), (b'America/Bogota', b'(GMT-0500) America/Bogota'), (b'America/Cayman', b'(GMT-0500) America/Cayman'), (b'America/Detroit', b'(GMT-0500) America/Detroit'), (b'America/Eirunepe', b'(GMT-0500) America/Eirunepe'), (b'America/Grand_Turk', b'(GMT-0500) America/Grand_Turk'), (b'America/Guayaquil', b'(GMT-0500) America/Guayaquil'), (b'America/Havana', b'(GMT-0500) America/Havana'), (b'America/Indiana/Indianapolis', b'(GMT-0500) America/Indiana/Indianapolis'), (b'America/Indiana/Marengo', b'(GMT-0500) America/Indiana/Marengo'), (b'America/Indiana/Petersburg', b'(GMT-0500) America/Indiana/Petersburg'), (b'America/Indiana/Vevay', b'(GMT-0500) America/Indiana/Vevay'), (b'America/Indiana/Vincennes', b'(GMT-0500) America/Indiana/Vincennes'), (b'America/Indiana/Winamac', b'(GMT-0500) America/Indiana/Winamac'), (b'America/Iqaluit', b'(GMT-0500) America/Iqaluit'), (b'America/Jamaica', b'(GMT-0500) America/Jamaica'), (b'America/Kentucky/Louisville', b'(GMT-0500) America/Kentucky/Louisville'), (b'America/Kentucky/Monticello', b'(GMT-0500) America/Kentucky/Monticello'), (b'America/Lima', b'(GMT-0500) America/Lima'), (b'America/Montreal', b'(GMT-0500) America/Montreal'), (b'America/Nassau', b'(GMT-0500) America/Nassau'), (b'America/New_York', b'(GMT-0500) America/New_York'), (b'America/Nipigon', b'(GMT-0500) America/Nipigon'), (b'America/Panama', b'(GMT-0500) America/Panama'), (b'America/Pangnirtung', b'(GMT-0500) America/Pangnirtung'), (b'America/Port-au-Prince', b'(GMT-0500) America/Port-au-Prince'), (b'America/Rio_Branco', b'(GMT-0500) America/Rio_Branco'), (b'America/Thunder_Bay', b'(GMT-0500) America/Thunder_Bay'), (b'America/Toronto', b'(GMT-0500) America/Toronto'), (b'Canada/Eastern', b'(GMT-0500) Canada/Eastern'), (b'Pacific/Easter', b'(GMT-0500) Pacific/Easter'), (b'US/Eastern', b'(GMT-0500) US/Eastern'), (b'America/Caracas', b'(GMT-0430) America/Caracas'), (b'America/Anguilla', b'(GMT-0400) America/Anguilla'), (b'America/Antigua', b'(GMT-0400) America/Antigua'), (b'America/Aruba', b'(GMT-0400) America/Aruba'), (b'America/Barbados', b'(GMT-0400) America/Barbados'), (b'America/Blanc-Sablon', b'(GMT-0400) America/Blanc-Sablon'), (b'America/Boa_Vista', b'(GMT-0400) America/Boa_Vista'), (b'America/Curacao', b'(GMT-0400) America/Curacao'), (b'America/Dominica', b'(GMT-0400) America/Dominica'), (b'America/Glace_Bay', b'(GMT-0400) America/Glace_Bay'), (b'America/Goose_Bay', b'(GMT-0400) America/Goose_Bay'), (b'America/Grenada', b'(GMT-0400) America/Grenada'), (b'America/Guadeloupe', b'(GMT-0400) America/Guadeloupe'), (b'America/Guyana', b'(GMT-0400) America/Guyana'), (b'America/Halifax', b'(GMT-0400) America/Halifax'), (b'America/Kralendijk', b'(GMT-0400) America/Kralendijk'), (b'America/La_Paz', b'(GMT-0400) America/La_Paz'), (b'America/Lower_Princes', b'(GMT-0400) America/Lower_Princes'), (b'America/Manaus', b'(GMT-0400) America/Manaus'), (b'America/Marigot', b'(GMT-0400) America/Marigot'), (b'America/Martinique', b'(GMT-0400) America/Martinique'), (b'America/Moncton', b'(GMT-0400) America/Moncton'), (b'America/Montserrat', b'(GMT-0400) America/Montserrat'), (b'America/Port_of_Spain', b'(GMT-0400) America/Port_of_Spain'), (b'America/Porto_Velho', b'(GMT-0400) America/Porto_Velho'), (b'America/Puerto_Rico', b'(GMT-0400) America/Puerto_Rico'), (b'America/Santo_Domingo', b'(GMT-0400) America/Santo_Domingo'), (b'America/St_Barthelemy', b'(GMT-0400) America/St_Barthelemy'), (b'America/St_Kitts', b'(GMT-0400) America/St_Kitts'), (b'America/St_Lucia', b'(GMT-0400) America/St_Lucia'), (b'America/St_Thomas', b'(GMT-0400) America/St_Thomas'), (b'America/St_Vincent', b'(GMT-0400) America/St_Vincent'), (b'America/Thule', b'(GMT-0400) America/Thule'), (b'America/Tortola', b'(GMT-0400) America/Tortola'), (b'Atlantic/Bermuda', b'(GMT-0400) Atlantic/Bermuda'), (b'Canada/Atlantic', b'(GMT-0400) Canada/Atlantic'), (b'America/St_Johns', b'(GMT-0330) America/St_Johns'), (b'Canada/Newfoundland', b'(GMT-0330) Canada/Newfoundland'), (b'America/Araguaina', b'(GMT-0300) America/Araguaina'), (b'America/Argentina/Buenos_Aires', b'(GMT-0300) America/Argentina/Buenos_Aires'), (b'America/Argentina/Catamarca', b'(GMT-0300) America/Argentina/Catamarca'), (b'America/Argentina/Cordoba', b'(GMT-0300) America/Argentina/Cordoba'), (b'America/Argentina/Jujuy', b'(GMT-0300) America/Argentina/Jujuy'), (b'America/Argentina/La_Rioja', b'(GMT-0300) America/Argentina/La_Rioja'), (b'America/Argentina/Mendoza', b'(GMT-0300) America/Argentina/Mendoza'), (b'America/Argentina/Rio_Gallegos', b'(GMT-0300) America/Argentina/Rio_Gallegos'), (b'America/Argentina/Salta', b'(GMT-0300) America/Argentina/Salta'), (b'America/Argentina/San_Juan', b'(GMT-0300) America/Argentina/San_Juan'), (b'America/Argentina/San_Luis', b'(GMT-0300) America/Argentina/San_Luis'), (b'America/Argentina/Tucuman', b'(GMT-0300) America/Argentina/Tucuman'), (b'America/Argentina/Ushuaia', b'(GMT-0300) America/Argentina/Ushuaia'), (b'America/Asuncion', b'(GMT-0300) America/Asuncion'), (b'America/Bahia', b'(GMT-0300) America/Bahia'), (b'America/Belem', b'(GMT-0300) America/Belem'), (b'America/Campo_Grande', b'(GMT-0300) America/Campo_Grande'), (b'America/Cayenne', b'(GMT-0300) America/Cayenne'), (b'America/Cuiaba', b'(GMT-0300) America/Cuiaba'), (b'America/Fortaleza', b'(GMT-0300) America/Fortaleza'), (b'America/Godthab', b'(GMT-0300) America/Godthab'), (b'America/Maceio', b'(GMT-0300) America/Maceio'), (b'America/Miquelon', b'(GMT-0300) America/Miquelon'), (b'America/Paramaribo', b'(GMT-0300) America/Paramaribo'), (b'America/Recife', b'(GMT-0300) America/Recife'), (b'America/Santarem', b'(GMT-0300) America/Santarem'), (b'America/Santiago', b'(GMT-0300) America/Santiago'), (b'Antarctica/Palmer', b'(GMT-0300) Antarctica/Palmer'), (b'Antarctica/Rothera', b'(GMT-0300) Antarctica/Rothera'), (b'Atlantic/Stanley', b'(GMT-0300) Atlantic/Stanley'), (b'America/Montevideo', b'(GMT-0200) America/Montevideo'), (b'America/Noronha', b'(GMT-0200) America/Noronha'), (b'America/Sao_Paulo', b'(GMT-0200) America/Sao_Paulo'), (b'Atlantic/South_Georgia', b'(GMT-0200) Atlantic/South_Georgia'), (b'America/Scoresbysund', b'(GMT-0100) America/Scoresbysund'), (b'Atlantic/Azores', b'(GMT-0100) Atlantic/Azores'), (b'Atlantic/Cape_Verde', b'(GMT-0100) Atlantic/Cape_Verde'), (b'Africa/Abidjan', b'(GMT+0000) Africa/Abidjan'), (b'Africa/Accra', b'(GMT+0000) Africa/Accra'), (b'Africa/Bamako', b'(GMT+0000) Africa/Bamako'), (b'Africa/Banjul', b'(GMT+0000) Africa/Banjul'), (b'Africa/Bissau', b'(GMT+0000) Africa/Bissau'), (b'Africa/Casablanca', b'(GMT+0000) Africa/Casablanca'), (b'Africa/Conakry', b'(GMT+0000) Africa/Conakry'), (b'Africa/Dakar', b'(GMT+0000) Africa/Dakar'), (b'Africa/El_Aaiun', b'(GMT+0000) Africa/El_Aaiun'), (b'Africa/Freetown', b'(GMT+0000) Africa/Freetown'), (b'Africa/Lome', b'(GMT+0000) Africa/Lome'), (b'Africa/Monrovia', b'(GMT+0000) Africa/Monrovia'), (b'Africa/Nouakchott', b'(GMT+0000) Africa/Nouakchott'), (b'Africa/Ouagadougou', b'(GMT+0000) Africa/Ouagadougou'), (b'Africa/Sao_Tome', b'(GMT+0000) Africa/Sao_Tome'), (b'America/Danmarkshavn', b'(GMT+0000) America/Danmarkshavn'), (b'Atlantic/Canary', b'(GMT+0000) Atlantic/Canary'), (b'Atlantic/Faroe', b'(GMT+0000) Atlantic/Faroe'), (b'Atlantic/Madeira', b'(GMT+0000) Atlantic/Madeira'), (b'Atlantic/Reykjavik', b'(GMT+0000) Atlantic/Reykjavik'), (b'Atlantic/St_Helena', b'(GMT+0000) Atlantic/St_Helena'), (b'Europe/Dublin', b'(GMT+0000) Europe/Dublin'), (b'Europe/Guernsey', b'(GMT+0000) Europe/Guernsey'), (b'Europe/Isle_of_Man', b'(GMT+0000) Europe/Isle_of_Man'), (b'Europe/Jersey', b'(GMT+0000) Europe/Jersey'), (b'Europe/Lisbon', b'(GMT+0000) Europe/Lisbon'), (b'Europe/London', b'(GMT+0000) Europe/London'), (b'GMT', b'(GMT+0000) GMT'), (b'UTC', b'(GMT+0000) UTC'), (b'Africa/Algiers', b'(GMT+0100) Africa/Algiers'), (b'Africa/Bangui', b'(GMT+0100) Africa/Bangui'), (b'Africa/Brazzaville', b'(GMT+0100) Africa/Brazzaville'), (b'Africa/Ceuta', b'(GMT+0100) Africa/Ceuta'), (b'Africa/Douala', b'(GMT+0100) Africa/Douala'), (b'Africa/Kinshasa', b'(GMT+0100) Africa/Kinshasa'), (b'Africa/Lagos', b'(GMT+0100) Africa/Lagos'), (b'Africa/Libreville', b'(GMT+0100) Africa/Libreville'), (b'Africa/Luanda', b'(GMT+0100) Africa/Luanda'), (b'Africa/Malabo', b'(GMT+0100) Africa/Malabo'), (b'Africa/Ndjamena', b'(GMT+0100) Africa/Ndjamena'), (b'Africa/Niamey', b'(GMT+0100) Africa/Niamey'), (b'Africa/Porto-Novo', b'(GMT+0100) Africa/Porto-Novo'), (b'Africa/Tunis', b'(GMT+0100) Africa/Tunis'), (b'Arctic/Longyearbyen', b'(GMT+0100) Arctic/Longyearbyen'), (b'Europe/Amsterdam', b'(GMT+0100) Europe/Amsterdam'), (b'Europe/Andorra', b'(GMT+0100) Europe/Andorra'), (b'Europe/Belgrade', b'(GMT+0100) Europe/Belgrade'), (b'Europe/Berlin', b'(GMT+0100) Europe/Berlin'), (b'Europe/Bratislava', b'(GMT+0100) Europe/Bratislava'), (b'Europe/Brussels', b'(GMT+0100) Europe/Brussels'), (b'Europe/Budapest', b'(GMT+0100) Europe/Budapest'), (b'Europe/Copenhagen', b'(GMT+0100) Europe/Copenhagen'), (b'Europe/Gibraltar', b'(GMT+0100) Europe/Gibraltar'), (b'Europe/Ljubljana', b'(GMT+0100) Europe/Ljubljana'), (b'Europe/Luxembourg', b'(GMT+0100) Europe/Luxembourg'), (b'Europe/Madrid', b'(GMT+0100) Europe/Madrid'), (b'Europe/Malta', b'(GMT+0100) Europe/Malta'), (b'Europe/Monaco', b'(GMT+0100) Europe/Monaco'), (b'Europe/Oslo', b'(GMT+0100) Europe/Oslo'), (b'Europe/Paris', b'(GMT+0100) Europe/Paris'), (b'Europe/Podgorica', b'(GMT+0100) Europe/Podgorica'), (b'Europe/Prague', b'(GMT+0100) Europe/Prague'), (b'Europe/Rome', b'(GMT+0100) Europe/Rome'), (b'Europe/San_Marino', b'(GMT+0100) Europe/San_Marino'), (b'Europe/Sarajevo', b'(GMT+0100) Europe/Sarajevo'), (b'Europe/Skopje', b'(GMT+0100) Europe/Skopje'), (b'Europe/Stockholm', b'(GMT+0100) Europe/Stockholm'), (b'Europe/Tirane', b'(GMT+0100) Europe/Tirane'), (b'Europe/Vaduz', b'(GMT+0100) Europe/Vaduz'), (b'Europe/Vatican', b'(GMT+0100) Europe/Vatican'), (b'Europe/Vienna', b'(GMT+0100) Europe/Vienna'), (b'Europe/Warsaw', b'(GMT+0100) Europe/Warsaw'), (b'Europe/Zagreb', b'(GMT+0100) Europe/Zagreb'), (b'Europe/Zurich', b'(GMT+0100) Europe/Zurich'), (b'Africa/Blantyre', b'(GMT+0200) Africa/Blantyre'), (b'Africa/Bujumbura', b'(GMT+0200) Africa/Bujumbura'), (b'Africa/Cairo', b'(GMT+0200) Africa/Cairo'), (b'Africa/Gaborone', b'(GMT+0200) Africa/Gaborone'), (b'Africa/Harare', b'(GMT+0200) Africa/Harare'), (b'Africa/Johannesburg', b'(GMT+0200) Africa/Johannesburg'), (b'Africa/Kigali', b'(GMT+0200) Africa/Kigali'), (b'Africa/Lubumbashi', b'(GMT+0200) Africa/Lubumbashi'), (b'Africa/Lusaka', b'(GMT+0200) Africa/Lusaka'), (b'Africa/Maputo', b'(GMT+0200) Africa/Maputo'), (b'Africa/Maseru', b'(GMT+0200) Africa/Maseru'), (b'Africa/Mbabane', b'(GMT+0200) Africa/Mbabane'), (b'Africa/Tripoli', b'(GMT+0200) Africa/Tripoli'), (b'Africa/Windhoek', b'(GMT+0200) Africa/Windhoek'), (b'Asia/Amman', b'(GMT+0200) Asia/Amman'), (b'Asia/Beirut', b'(GMT+0200) Asia/Beirut'), (b'Asia/Damascus', b'(GMT+0200) Asia/Damascus'), (b'Asia/Gaza', b'(GMT+0200) Asia/Gaza'), (b'Asia/Hebron', b'(GMT+0200) Asia/Hebron'), (b'Asia/Jerusalem', b'(GMT+0200) Asia/Jerusalem'), (b'Asia/Nicosia', b'(GMT+0200) Asia/Nicosia'), (b'Europe/Athens', b'(GMT+0200) Europe/Athens'), (b'Europe/Bucharest', b'(GMT+0200) Europe/Bucharest'), (b'Europe/Chisinau', b'(GMT+0200) Europe/Chisinau'), (b'Europe/Helsinki', b'(GMT+0200) Europe/Helsinki'), (b'Europe/Istanbul', b'(GMT+0200) Europe/Istanbul'), (b'Europe/Kiev', b'(GMT+0200) Europe/Kiev'), (b'Europe/Mariehamn', b'(GMT+0200) Europe/Mariehamn'), (b'Europe/Riga', b'(GMT+0200) Europe/Riga'), (b'Europe/Sofia', b'(GMT+0200) Europe/Sofia'), (b'Europe/Tallinn', b'(GMT+0200) Europe/Tallinn'), (b'Europe/Uzhgorod', b'(GMT+0200) Europe/Uzhgorod'), (b'Europe/Vilnius', b'(GMT+0200) Europe/Vilnius'), (b'Europe/Zaporozhye', b'(GMT+0200) Europe/Zaporozhye'), (b'Africa/Addis_Ababa', b'(GMT+0300) Africa/Addis_Ababa'), (b'Africa/Asmara', b'(GMT+0300) Africa/Asmara'), (b'Africa/Dar_es_Salaam', b'(GMT+0300) Africa/Dar_es_Salaam'), (b'Africa/Djibouti', b'(GMT+0300) Africa/Djibouti'), (b'Africa/Juba', b'(GMT+0300) Africa/Juba'), (b'Africa/Kampala', b'(GMT+0300) Africa/Kampala'), (b'Africa/Khartoum', b'(GMT+0300) Africa/Khartoum'), (b'Africa/Mogadishu', b'(GMT+0300) Africa/Mogadishu'), (b'Africa/Nairobi', b'(GMT+0300) Africa/Nairobi'), (b'Antarctica/Syowa', b'(GMT+0300) Antarctica/Syowa'), (b'Asia/Aden', b'(GMT+0300) Asia/Aden'), (b'Asia/Baghdad', b'(GMT+0300) Asia/Baghdad'), (b'Asia/Bahrain', b'(GMT+0300) Asia/Bahrain'), (b'Asia/Kuwait', b'(GMT+0300) Asia/Kuwait'), (b'Asia/Qatar', b'(GMT+0300) Asia/Qatar'), (b'Asia/Riyadh', b'(GMT+0300) Asia/Riyadh'), (b'Europe/Kaliningrad', b'(GMT+0300) Europe/Kaliningrad'), (b'Europe/Minsk', b'(GMT+0300) Europe/Minsk'), (b'Indian/Antananarivo', b'(GMT+0300) Indian/Antananarivo'), (b'Indian/Comoro', b'(GMT+0300) Indian/Comoro'), (b'Indian/Mayotte', b'(GMT+0300) Indian/Mayotte'), (b'Asia/Tehran', b'(GMT+0330) Asia/Tehran'), (b'Asia/Baku', b'(GMT+0400) Asia/Baku'), (b'Asia/Dubai', b'(GMT+0400) Asia/Dubai'), (b'Asia/Muscat', b'(GMT+0400) Asia/Muscat'), (b'Asia/Tbilisi', b'(GMT+0400) Asia/Tbilisi'), (b'Asia/Yerevan', b'(GMT+0400) Asia/Yerevan'), (b'Europe/Moscow', b'(GMT+0400) Europe/Moscow'), (b'Europe/Samara', b'(GMT+0400) Europe/Samara'), (b'Europe/Simferopol', b'(GMT+0400) Europe/Simferopol'), (b'Europe/Volgograd', b'(GMT+0400) Europe/Volgograd'), (b'Indian/Mahe', b'(GMT+0400) Indian/Mahe'), (b'Indian/Mauritius', b'(GMT+0400) Indian/Mauritius'), (b'Indian/Reunion', b'(GMT+0400) Indian/Reunion'), (b'Asia/Kabul', b'(GMT+0430) Asia/Kabul'), (b'Antarctica/Mawson', b'(GMT+0500) Antarctica/Mawson'), (b'Asia/Aqtau', b'(GMT+0500) Asia/Aqtau'), (b'Asia/Aqtobe', b'(GMT+0500) Asia/Aqtobe'), (b'Asia/Ashgabat', b'(GMT+0500) Asia/Ashgabat'), (b'Asia/Dushanbe', b'(GMT+0500) Asia/Dushanbe'), (b'Asia/Karachi', b'(GMT+0500) Asia/Karachi'), (b'Asia/Oral', b'(GMT+0500) Asia/Oral'), (b'Asia/Samarkand', b'(GMT+0500) Asia/Samarkand'), (b'Asia/Tashkent', b'(GMT+0500) Asia/Tashkent'), (b'Indian/Kerguelen', b'(GMT+0500) Indian/Kerguelen'), (b'Indian/Maldives', b'(GMT+0500) Indian/Maldives'), (b'Asia/Colombo', b'(GMT+0530) Asia/Colombo'), (b'Asia/Kolkata', b'(GMT+0530) Asia/Kolkata'), (b'Asia/Kathmandu', b'(GMT+0545) Asia/Kathmandu'), (b'Antarctica/Vostok', b'(GMT+0600) Antarctica/Vostok'), (b'Asia/Almaty', b'(GMT+0600) Asia/Almaty'), (b'Asia/Bishkek', b'(GMT+0600) Asia/Bishkek'), (b'Asia/Dhaka', b'(GMT+0600) Asia/Dhaka'), (b'Asia/Qyzylorda', b'(GMT+0600) Asia/Qyzylorda'), (b'Asia/Thimphu', b'(GMT+0600) Asia/Thimphu'), (b'Asia/Yekaterinburg', b'(GMT+0600) Asia/Yekaterinburg'), (b'Indian/Chagos', b'(GMT+0600) Indian/Chagos'), (b'Asia/Rangoon', b'(GMT+0630) Asia/Rangoon'), (b'Indian/Cocos', b'(GMT+0630) Indian/Cocos'), (b'Antarctica/Davis', b'(GMT+0700) Antarctica/Davis'), (b'Asia/Bangkok', b'(GMT+0700) Asia/Bangkok'), (b'Asia/Ho_Chi_Minh', b'(GMT+0700) Asia/Ho_Chi_Minh'), (b'Asia/Hovd', b'(GMT+0700) Asia/Hovd'), (b'Asia/Jakarta', b'(GMT+0700) Asia/Jakarta'), (b'Asia/Novokuznetsk', b'(GMT+0700) Asia/Novokuznetsk'), (b'Asia/Novosibirsk', b'(GMT+0700) Asia/Novosibirsk'), (b'Asia/Omsk', b'(GMT+0700) Asia/Omsk'), (b'Asia/Phnom_Penh', b'(GMT+0700) Asia/Phnom_Penh'), (b'Asia/Pontianak', b'(GMT+0700) Asia/Pontianak'), (b'Asia/Vientiane', b'(GMT+0700) Asia/Vientiane'), (b'Indian/Christmas', b'(GMT+0700) Indian/Christmas'), (b'Antarctica/Casey', b'(GMT+0800) Antarctica/Casey'), (b'Asia/Brunei', b'(GMT+0800) Asia/Brunei'), (b'Asia/Choibalsan', b'(GMT+0800) Asia/Choibalsan'), (b'Asia/Chongqing', b'(GMT+0800) Asia/Chongqing'), (b'Asia/Harbin', b'(GMT+0800) Asia/Harbin'), (b'Asia/Hong_Kong', b'(GMT+0800) Asia/Hong_Kong'), (b'Asia/Kashgar', b'(GMT+0800) Asia/Kashgar'), (b'Asia/Krasnoyarsk', b'(GMT+0800) Asia/Krasnoyarsk'), (b'Asia/Kuala_Lumpur', b'(GMT+0800) Asia/Kuala_Lumpur'), (b'Asia/Kuching', b'(GMT+0800) Asia/Kuching'), (b'Asia/Macau', b'(GMT+0800) Asia/Macau'), (b'Asia/Makassar', b'(GMT+0800) Asia/Makassar'), (b'Asia/Manila', b'(GMT+0800) Asia/Manila'), (b'Asia/Shanghai', b'(GMT+0800) Asia/Shanghai'), (b'Asia/Singapore', b'(GMT+0800) Asia/Singapore'), (b'Asia/Taipei', b'(GMT+0800) Asia/Taipei'), (b'Asia/Ulaanbaatar', b'(GMT+0800) Asia/Ulaanbaatar'), (b'Asia/Urumqi', b'(GMT+0800) Asia/Urumqi'), (b'Australia/Perth', b'(GMT+0800) Australia/Perth'), (b'Australia/Eucla', b'(GMT+0845) Australia/Eucla'), (b'Asia/Dili', b'(GMT+0900) Asia/Dili'), (b'Asia/Irkutsk', b'(GMT+0900) Asia/Irkutsk'), (b'Asia/Jayapura', b'(GMT+0900) Asia/Jayapura'), (b'Asia/Pyongyang', b'(GMT+0900) Asia/Pyongyang'), (b'Asia/Seoul', b'(GMT+0900) Asia/Seoul'), (b'Asia/Tokyo', b'(GMT+0900) Asia/Tokyo'), (b'Pacific/Palau', b'(GMT+0900) Pacific/Palau'), (b'Australia/Darwin', b'(GMT+0930) Australia/Darwin'), (b'Antarctica/DumontDUrville', b'(GMT+1000) Antarctica/DumontDUrville'), (b'Asia/Yakutsk', b'(GMT+1000) Asia/Yakutsk'), (b'Australia/Brisbane', b'(GMT+1000) Australia/Brisbane'), (b'Australia/Lindeman', b'(GMT+1000) Australia/Lindeman'), (b'Pacific/Chuuk', b'(GMT+1000) Pacific/Chuuk'), (b'Pacific/Guam', b'(GMT+1000) Pacific/Guam'), (b'Pacific/Port_Moresby', b'(GMT+1000) Pacific/Port_Moresby'), (b'Pacific/Saipan', b'(GMT+1000) Pacific/Saipan'), (b'Australia/Adelaide', b'(GMT+1030) Australia/Adelaide'), (b'Australia/Broken_Hill', b'(GMT+1030) Australia/Broken_Hill'), (b'Antarctica/Macquarie', b'(GMT+1100) Antarctica/Macquarie'), (b'Asia/Sakhalin', b'(GMT+1100) Asia/Sakhalin'), (b'Asia/Vladivostok', b'(GMT+1100) Asia/Vladivostok'), (b'Australia/Currie', b'(GMT+1100) Australia/Currie'), (b'Australia/Hobart', b'(GMT+1100) Australia/Hobart'), (b'Australia/Lord_Howe', b'(GMT+1100) Australia/Lord_Howe'), (b'Australia/Melbourne', b'(GMT+1100) Australia/Melbourne'), (b'Australia/Sydney', b'(GMT+1100) Australia/Sydney'), (b'Pacific/Efate', b'(GMT+1100) Pacific/Efate'), (b'Pacific/Guadalcanal', b'(GMT+1100) Pacific/Guadalcanal'), (b'Pacific/Kosrae', b'(GMT+1100) Pacific/Kosrae'), (b'Pacific/Noumea', b'(GMT+1100) Pacific/Noumea'), (b'Pacific/Pohnpei', b'(GMT+1100) Pacific/Pohnpei'), (b'Pacific/Norfolk', b'(GMT+1130) Pacific/Norfolk'), (b'Asia/Anadyr', b'(GMT+1200) Asia/Anadyr'), (b'Asia/Kamchatka', b'(GMT+1200) Asia/Kamchatka'), (b'Asia/Magadan', b'(GMT+1200) Asia/Magadan'), (b'Pacific/Fiji', b'(GMT+1200) Pacific/Fiji'), (b'Pacific/Funafuti', b'(GMT+1200) Pacific/Funafuti'), (b'Pacific/Kwajalein', b'(GMT+1200) Pacific/Kwajalein'), (b'Pacific/Majuro', b'(GMT+1200) Pacific/Majuro'), (b'Pacific/Nauru', b'(GMT+1200) Pacific/Nauru'), (b'Pacific/Tarawa', b'(GMT+1200) Pacific/Tarawa'), (b'Pacific/Wake', b'(GMT+1200) Pacific/Wake'), (b'Pacific/Wallis', b'(GMT+1200) Pacific/Wallis'), (b'Antarctica/McMurdo', b'(GMT+1300) Antarctica/McMurdo'), (b'Antarctica/South_Pole', b'(GMT+1300) Antarctica/South_Pole'), (b'Pacific/Auckland', b'(GMT+1300) Pacific/Auckland'), (b'Pacific/Enderbury', b'(GMT+1300) Pacific/Enderbury'), (b'Pacific/Fakaofo', b'(GMT+1300) Pacific/Fakaofo'), (b'Pacific/Tongatapu', b'(GMT+1300) Pacific/Tongatapu'), (b'Pacific/Chatham', b'(GMT+1345) Pacific/Chatham'), (b'Pacific/Apia', b'(GMT+1400) Pacific/Apia'), (b'Pacific/Kiritimati', b'(GMT+1400) Pacific/Kiritimati')])),
+                ('timezone', timezones.fields.TimeZoneField(default=b'America/New_York', max_length=100, choices=[(b'Pacific/Midway', b'(GMT-1100) Pacific/Midway'), (b'Pacific/Niue', b'(GMT-1100) Pacific/Niue'), (b'Pacific/Pago_Pago', b'(GMT-1100) Pacific/Pago_Pago'), (b'America/Adak', b'(GMT-1000) America/Adak'), (b'Pacific/Honolulu', b'(GMT-1000) Pacific/Honolulu'), (b'Pacific/Johnston', b'(GMT-1000) Pacific/Johnston'), (b'Pacific/Rarotonga', b'(GMT-1000) Pacific/Rarotonga'), (b'Pacific/Tahiti', b'(GMT-1000) Pacific/Tahiti'), (b'US/Hawaii', b'(GMT-1000) US/Hawaii'), (b'Pacific/Marquesas', b'(GMT-0930) Pacific/Marquesas'), (b'America/Anchorage', b'(GMT-0900) America/Anchorage'), (b'America/Juneau', b'(GMT-0900) America/Juneau'), (b'America/Nome', b'(GMT-0900) America/Nome'), (b'America/Sitka', b'(GMT-0900) America/Sitka'), (b'America/Yakutat', b'(GMT-0900) America/Yakutat'), (b'Pacific/Gambier', b'(GMT-0900) Pacific/Gambier'), (b'US/Alaska', b'(GMT-0900) US/Alaska'), (b'America/Dawson', b'(GMT-0800) America/Dawson'), (b'America/Los_Angeles', b'(GMT-0800) America/Los_Angeles'), (b'America/Metlakatla', b'(GMT-0800) America/Metlakatla'), (b'America/Santa_Isabel', b'(GMT-0800) America/Santa_Isabel'), (b'America/Tijuana', b'(GMT-0800) America/Tijuana'), (b'America/Vancouver', b'(GMT-0800) America/Vancouver'), (b'America/Whitehorse', b'(GMT-0800) America/Whitehorse'), (b'Canada/Pacific', b'(GMT-0800) Canada/Pacific'), (b'Pacific/Pitcairn', b'(GMT-0800) Pacific/Pitcairn'), (b'US/Pacific', b'(GMT-0800) US/Pacific'), (b'America/Boise', b'(GMT-0700) America/Boise'), (b'America/Cambridge_Bay', b'(GMT-0700) America/Cambridge_Bay'), (b'America/Chihuahua', b'(GMT-0700) America/Chihuahua'), (b'America/Creston', b'(GMT-0700) America/Creston'), (b'America/Dawson_Creek', b'(GMT-0700) America/Dawson_Creek'), (b'America/Denver', b'(GMT-0700) America/Denver'), (b'America/Edmonton', b'(GMT-0700) America/Edmonton'), (b'America/Hermosillo', b'(GMT-0700) America/Hermosillo'), (b'America/Inuvik', b'(GMT-0700) America/Inuvik'), (b'America/Mazatlan', b'(GMT-0700) America/Mazatlan'), (b'America/Ojinaga', b'(GMT-0700) America/Ojinaga'), (b'America/Phoenix', b'(GMT-0700) America/Phoenix'), (b'America/Shiprock', b'(GMT-0700) America/Shiprock'), (b'America/Yellowknife', b'(GMT-0700) America/Yellowknife'), (b'Canada/Mountain', b'(GMT-0700) Canada/Mountain'), (b'US/Arizona', b'(GMT-0700) US/Arizona'), (b'US/Mountain', b'(GMT-0700) US/Mountain'), (b'America/Bahia_Banderas', b'(GMT-0600) America/Bahia_Banderas'), (b'America/Belize', b'(GMT-0600) America/Belize'), (b'America/Cancun', b'(GMT-0600) America/Cancun'), (b'America/Chicago', b'(GMT-0600) America/Chicago'), (b'America/Costa_Rica', b'(GMT-0600) America/Costa_Rica'), (b'America/El_Salvador', b'(GMT-0600) America/El_Salvador'), (b'America/Guatemala', b'(GMT-0600) America/Guatemala'), (b'America/Indiana/Knox', b'(GMT-0600) America/Indiana/Knox'), (b'America/Indiana/Tell_City', b'(GMT-0600) America/Indiana/Tell_City'), (b'America/Managua', b'(GMT-0600) America/Managua'), (b'America/Matamoros', b'(GMT-0600) America/Matamoros'), (b'America/Menominee', b'(GMT-0600) America/Menominee'), (b'America/Merida', b'(GMT-0600) America/Merida'), (b'America/Mexico_City', b'(GMT-0600) America/Mexico_City'), (b'America/Monterrey', b'(GMT-0600) America/Monterrey'), (b'America/North_Dakota/Beulah', b'(GMT-0600) America/North_Dakota/Beulah'), (b'America/North_Dakota/Center', b'(GMT-0600) America/North_Dakota/Center'), (b'America/North_Dakota/New_Salem', b'(GMT-0600) America/North_Dakota/New_Salem'), (b'America/Rainy_River', b'(GMT-0600) America/Rainy_River'), (b'America/Rankin_Inlet', b'(GMT-0600) America/Rankin_Inlet'), (b'America/Regina', b'(GMT-0600) America/Regina'), (b'America/Resolute', b'(GMT-0600) America/Resolute'), (b'America/Swift_Current', b'(GMT-0600) America/Swift_Current'), (b'America/Tegucigalpa', b'(GMT-0600) America/Tegucigalpa'), (b'America/Winnipeg', b'(GMT-0600) America/Winnipeg'), (b'Canada/Central', b'(GMT-0600) Canada/Central'), (b'Pacific/Galapagos', b'(GMT-0600) Pacific/Galapagos'), (b'US/Central', b'(GMT-0600) US/Central'), (b'America/Atikokan', b'(GMT-0500) America/Atikokan'), (b'America/Bogota', b'(GMT-0500) America/Bogota'), (b'America/Cayman', b'(GMT-0500) America/Cayman'), (b'America/Detroit', b'(GMT-0500) America/Detroit'), (b'America/Eirunepe', b'(GMT-0500) America/Eirunepe'), (b'America/Grand_Turk', b'(GMT-0500) America/Grand_Turk'), (b'America/Guayaquil', b'(GMT-0500) America/Guayaquil'), (b'America/Havana', b'(GMT-0500) America/Havana'), (b'America/Indiana/Indianapolis', b'(GMT-0500) America/Indiana/Indianapolis'), (b'America/Indiana/Marengo', b'(GMT-0500) America/Indiana/Marengo'), (b'America/Indiana/Petersburg', b'(GMT-0500) America/Indiana/Petersburg'), (b'America/Indiana/Vevay', b'(GMT-0500) America/Indiana/Vevay'), (b'America/Indiana/Vincennes', b'(GMT-0500) America/Indiana/Vincennes'), (b'America/Indiana/Winamac', b'(GMT-0500) America/Indiana/Winamac'), (b'America/Iqaluit', b'(GMT-0500) America/Iqaluit'), (b'America/Jamaica', b'(GMT-0500) America/Jamaica'), (b'America/Kentucky/Louisville', b'(GMT-0500) America/Kentucky/Louisville'), (b'America/Kentucky/Monticello', b'(GMT-0500) America/Kentucky/Monticello'), (b'America/Lima', b'(GMT-0500) America/Lima'), (b'America/Montreal', b'(GMT-0500) America/Montreal'), (b'America/Nassau', b'(GMT-0500) America/Nassau'), (b'America/New_York', b'(GMT-0500) America/New_York'), (b'America/Nipigon', b'(GMT-0500) America/Nipigon'), (b'America/Panama', b'(GMT-0500) America/Panama'), (b'America/Pangnirtung', b'(GMT-0500) America/Pangnirtung'), (b'America/Port-au-Prince', b'(GMT-0500) America/Port-au-Prince'), (b'America/Rio_Branco', b'(GMT-0500) America/Rio_Branco'), (b'America/Thunder_Bay', b'(GMT-0500) America/Thunder_Bay'), (b'America/Toronto', b'(GMT-0500) America/Toronto'), (b'Canada/Eastern', b'(GMT-0500) Canada/Eastern'), (b'Pacific/Easter', b'(GMT-0500) Pacific/Easter'), (b'US/Eastern', b'(GMT-0500) US/Eastern'), (b'America/Caracas', b'(GMT-0430) America/Caracas'), (b'America/Anguilla', b'(GMT-0400) America/Anguilla'), (b'America/Antigua', b'(GMT-0400) America/Antigua'), (b'America/Aruba', b'(GMT-0400) America/Aruba'), (b'America/Barbados', b'(GMT-0400) America/Barbados'), (b'America/Blanc-Sablon', b'(GMT-0400) America/Blanc-Sablon'), (b'America/Boa_Vista', b'(GMT-0400) America/Boa_Vista'), (b'America/Curacao', b'(GMT-0400) America/Curacao'), (b'America/Dominica', b'(GMT-0400) America/Dominica'), (b'America/Glace_Bay', b'(GMT-0400) America/Glace_Bay'), (b'America/Goose_Bay', b'(GMT-0400) America/Goose_Bay'), (b'America/Grenada', b'(GMT-0400) America/Grenada'), (b'America/Guadeloupe', b'(GMT-0400) America/Guadeloupe'), (b'America/Guyana', b'(GMT-0400) America/Guyana'), (b'America/Halifax', b'(GMT-0400) America/Halifax'), (b'America/Kralendijk', b'(GMT-0400) America/Kralendijk'), (b'America/La_Paz', b'(GMT-0400) America/La_Paz'), (b'America/Lower_Princes', b'(GMT-0400) America/Lower_Princes'), (b'America/Manaus', b'(GMT-0400) America/Manaus'), (b'America/Marigot', b'(GMT-0400) America/Marigot'), (b'America/Martinique', b'(GMT-0400) America/Martinique'), (b'America/Moncton', b'(GMT-0400) America/Moncton'), (b'America/Montserrat', b'(GMT-0400) America/Montserrat'), (b'America/Port_of_Spain', b'(GMT-0400) America/Port_of_Spain'), (b'America/Porto_Velho', b'(GMT-0400) America/Porto_Velho'), (b'America/Puerto_Rico', b'(GMT-0400) America/Puerto_Rico'), (b'America/Santo_Domingo', b'(GMT-0400) America/Santo_Domingo'), (b'America/St_Barthelemy', b'(GMT-0400) America/St_Barthelemy'), (b'America/St_Kitts', b'(GMT-0400) America/St_Kitts'), (b'America/St_Lucia', b'(GMT-0400) America/St_Lucia'), (b'America/St_Thomas', b'(GMT-0400) America/St_Thomas'), (b'America/St_Vincent', b'(GMT-0400) America/St_Vincent'), (b'America/Thule', b'(GMT-0400) America/Thule'), (b'America/Tortola', b'(GMT-0400) America/Tortola'), (b'Atlantic/Bermuda', b'(GMT-0400) Atlantic/Bermuda'), (b'Canada/Atlantic', b'(GMT-0400) Canada/Atlantic'), (b'America/St_Johns', b'(GMT-0330) America/St_Johns'), (b'Canada/Newfoundland', b'(GMT-0330) Canada/Newfoundland'), (b'America/Araguaina', b'(GMT-0300) America/Araguaina'), (b'America/Argentina/Buenos_Aires', b'(GMT-0300) America/Argentina/Buenos_Aires'), (b'America/Argentina/Catamarca', b'(GMT-0300) America/Argentina/Catamarca'), (b'America/Argentina/Cordoba', b'(GMT-0300) America/Argentina/Cordoba'), (b'America/Argentina/Jujuy', b'(GMT-0300) America/Argentina/Jujuy'), (b'America/Argentina/La_Rioja', b'(GMT-0300) America/Argentina/La_Rioja'), (b'America/Argentina/Mendoza', b'(GMT-0300) America/Argentina/Mendoza'), (b'America/Argentina/Rio_Gallegos', b'(GMT-0300) America/Argentina/Rio_Gallegos'), (b'America/Argentina/Salta', b'(GMT-0300) America/Argentina/Salta'), (b'America/Argentina/San_Juan', b'(GMT-0300) America/Argentina/San_Juan'), (b'America/Argentina/San_Luis', b'(GMT-0300) America/Argentina/San_Luis'), (b'America/Argentina/Tucuman', b'(GMT-0300) America/Argentina/Tucuman'), (b'America/Argentina/Ushuaia', b'(GMT-0300) America/Argentina/Ushuaia'), (b'America/Asuncion', b'(GMT-0300) America/Asuncion'), (b'America/Bahia', b'(GMT-0300) America/Bahia'), (b'America/Belem', b'(GMT-0300) America/Belem'), (b'America/Campo_Grande', b'(GMT-0300) America/Campo_Grande'), (b'America/Cayenne', b'(GMT-0300) America/Cayenne'), (b'America/Cuiaba', b'(GMT-0300) America/Cuiaba'), (b'America/Fortaleza', b'(GMT-0300) America/Fortaleza'), (b'America/Godthab', b'(GMT-0300) America/Godthab'), (b'America/Maceio', b'(GMT-0300) America/Maceio'), (b'America/Miquelon', b'(GMT-0300) America/Miquelon'), (b'America/Paramaribo', b'(GMT-0300) America/Paramaribo'), (b'America/Recife', b'(GMT-0300) America/Recife'), (b'America/Santarem', b'(GMT-0300) America/Santarem'), (b'America/Santiago', b'(GMT-0300) America/Santiago'), (b'Antarctica/Palmer', b'(GMT-0300) Antarctica/Palmer'), (b'Antarctica/Rothera', b'(GMT-0300) Antarctica/Rothera'), (b'Atlantic/Stanley', b'(GMT-0300) Atlantic/Stanley'), (b'America/Montevideo', b'(GMT-0200) America/Montevideo'), (b'America/Noronha', b'(GMT-0200) America/Noronha'), (b'America/Sao_Paulo', b'(GMT-0200) America/Sao_Paulo'), (b'Atlantic/South_Georgia', b'(GMT-0200) Atlantic/South_Georgia'), (b'America/Scoresbysund', b'(GMT-0100) America/Scoresbysund'), (b'Atlantic/Azores', b'(GMT-0100) Atlantic/Azores'), (b'Atlantic/Cape_Verde', b'(GMT-0100) Atlantic/Cape_Verde'), (b'Africa/Abidjan', b'(GMT+0000) Africa/Abidjan'), (b'Africa/Accra', b'(GMT+0000) Africa/Accra'), (b'Africa/Bamako', b'(GMT+0000) Africa/Bamako'), (b'Africa/Banjul', b'(GMT+0000) Africa/Banjul'), (b'Africa/Bissau', b'(GMT+0000) Africa/Bissau'), (b'Africa/Casablanca', b'(GMT+0000) Africa/Casablanca'), (b'Africa/Conakry', b'(GMT+0000) Africa/Conakry'), (b'Africa/Dakar', b'(GMT+0000) Africa/Dakar'), (b'Africa/El_Aaiun', b'(GMT+0000) Africa/El_Aaiun'), (b'Africa/Freetown', b'(GMT+0000) Africa/Freetown'), (b'Africa/Lome', b'(GMT+0000) Africa/Lome'), (b'Africa/Monrovia', b'(GMT+0000) Africa/Monrovia'), (b'Africa/Nouakchott', b'(GMT+0000) Africa/Nouakchott'), (b'Africa/Ouagadougou', b'(GMT+0000) Africa/Ouagadougou'), (b'Africa/Sao_Tome', b'(GMT+0000) Africa/Sao_Tome'), (b'America/Danmarkshavn', b'(GMT+0000) America/Danmarkshavn'), (b'Atlantic/Canary', b'(GMT+0000) Atlantic/Canary'), (b'Atlantic/Faroe', b'(GMT+0000) Atlantic/Faroe'), (b'Atlantic/Madeira', b'(GMT+0000) Atlantic/Madeira'), (b'Atlantic/Reykjavik', b'(GMT+0000) Atlantic/Reykjavik'), (b'Atlantic/St_Helena', b'(GMT+0000) Atlantic/St_Helena'), (b'Europe/Dublin', b'(GMT+0000) Europe/Dublin'), (b'Europe/Guernsey', b'(GMT+0000) Europe/Guernsey'), (
+                    b'Europe/Isle_of_Man', b'(GMT+0000) Europe/Isle_of_Man'), (b'Europe/Jersey', b'(GMT+0000) Europe/Jersey'), (b'Europe/Lisbon', b'(GMT+0000) Europe/Lisbon'), (b'Europe/London', b'(GMT+0000) Europe/London'), (b'GMT', b'(GMT+0000) GMT'), (b'UTC', b'(GMT+0000) UTC'), (b'Africa/Algiers', b'(GMT+0100) Africa/Algiers'), (b'Africa/Bangui', b'(GMT+0100) Africa/Bangui'), (b'Africa/Brazzaville', b'(GMT+0100) Africa/Brazzaville'), (b'Africa/Ceuta', b'(GMT+0100) Africa/Ceuta'), (b'Africa/Douala', b'(GMT+0100) Africa/Douala'), (b'Africa/Kinshasa', b'(GMT+0100) Africa/Kinshasa'), (b'Africa/Lagos', b'(GMT+0100) Africa/Lagos'), (b'Africa/Libreville', b'(GMT+0100) Africa/Libreville'), (b'Africa/Luanda', b'(GMT+0100) Africa/Luanda'), (b'Africa/Malabo', b'(GMT+0100) Africa/Malabo'), (b'Africa/Ndjamena', b'(GMT+0100) Africa/Ndjamena'), (b'Africa/Niamey', b'(GMT+0100) Africa/Niamey'), (b'Africa/Porto-Novo', b'(GMT+0100) Africa/Porto-Novo'), (b'Africa/Tunis', b'(GMT+0100) Africa/Tunis'), (b'Arctic/Longyearbyen', b'(GMT+0100) Arctic/Longyearbyen'), (b'Europe/Amsterdam', b'(GMT+0100) Europe/Amsterdam'), (b'Europe/Andorra', b'(GMT+0100) Europe/Andorra'), (b'Europe/Belgrade', b'(GMT+0100) Europe/Belgrade'), (b'Europe/Berlin', b'(GMT+0100) Europe/Berlin'), (b'Europe/Bratislava', b'(GMT+0100) Europe/Bratislava'), (b'Europe/Brussels', b'(GMT+0100) Europe/Brussels'), (b'Europe/Budapest', b'(GMT+0100) Europe/Budapest'), (b'Europe/Copenhagen', b'(GMT+0100) Europe/Copenhagen'), (b'Europe/Gibraltar', b'(GMT+0100) Europe/Gibraltar'), (b'Europe/Ljubljana', b'(GMT+0100) Europe/Ljubljana'), (b'Europe/Luxembourg', b'(GMT+0100) Europe/Luxembourg'), (b'Europe/Madrid', b'(GMT+0100) Europe/Madrid'), (b'Europe/Malta', b'(GMT+0100) Europe/Malta'), (b'Europe/Monaco', b'(GMT+0100) Europe/Monaco'), (b'Europe/Oslo', b'(GMT+0100) Europe/Oslo'), (b'Europe/Paris', b'(GMT+0100) Europe/Paris'), (b'Europe/Podgorica', b'(GMT+0100) Europe/Podgorica'), (b'Europe/Prague', b'(GMT+0100) Europe/Prague'), (b'Europe/Rome', b'(GMT+0100) Europe/Rome'), (b'Europe/San_Marino', b'(GMT+0100) Europe/San_Marino'), (b'Europe/Sarajevo', b'(GMT+0100) Europe/Sarajevo'), (b'Europe/Skopje', b'(GMT+0100) Europe/Skopje'), (b'Europe/Stockholm', b'(GMT+0100) Europe/Stockholm'), (b'Europe/Tirane', b'(GMT+0100) Europe/Tirane'), (b'Europe/Vaduz', b'(GMT+0100) Europe/Vaduz'), (b'Europe/Vatican', b'(GMT+0100) Europe/Vatican'), (b'Europe/Vienna', b'(GMT+0100) Europe/Vienna'), (b'Europe/Warsaw', b'(GMT+0100) Europe/Warsaw'), (b'Europe/Zagreb', b'(GMT+0100) Europe/Zagreb'), (b'Europe/Zurich', b'(GMT+0100) Europe/Zurich'), (b'Africa/Blantyre', b'(GMT+0200) Africa/Blantyre'), (b'Africa/Bujumbura', b'(GMT+0200) Africa/Bujumbura'), (b'Africa/Cairo', b'(GMT+0200) Africa/Cairo'), (b'Africa/Gaborone', b'(GMT+0200) Africa/Gaborone'), (b'Africa/Harare', b'(GMT+0200) Africa/Harare'), (b'Africa/Johannesburg', b'(GMT+0200) Africa/Johannesburg'), (b'Africa/Kigali', b'(GMT+0200) Africa/Kigali'), (b'Africa/Lubumbashi', b'(GMT+0200) Africa/Lubumbashi'), (b'Africa/Lusaka', b'(GMT+0200) Africa/Lusaka'), (b'Africa/Maputo', b'(GMT+0200) Africa/Maputo'), (b'Africa/Maseru', b'(GMT+0200) Africa/Maseru'), (b'Africa/Mbabane', b'(GMT+0200) Africa/Mbabane'), (b'Africa/Tripoli', b'(GMT+0200) Africa/Tripoli'), (b'Africa/Windhoek', b'(GMT+0200) Africa/Windhoek'), (b'Asia/Amman', b'(GMT+0200) Asia/Amman'), (b'Asia/Beirut', b'(GMT+0200) Asia/Beirut'), (b'Asia/Damascus', b'(GMT+0200) Asia/Damascus'), (b'Asia/Gaza', b'(GMT+0200) Asia/Gaza'), (b'Asia/Hebron', b'(GMT+0200) Asia/Hebron'), (b'Asia/Jerusalem', b'(GMT+0200) Asia/Jerusalem'), (b'Asia/Nicosia', b'(GMT+0200) Asia/Nicosia'), (b'Europe/Athens', b'(GMT+0200) Europe/Athens'), (b'Europe/Bucharest', b'(GMT+0200) Europe/Bucharest'), (b'Europe/Chisinau', b'(GMT+0200) Europe/Chisinau'), (b'Europe/Helsinki', b'(GMT+0200) Europe/Helsinki'), (b'Europe/Istanbul', b'(GMT+0200) Europe/Istanbul'), (b'Europe/Kiev', b'(GMT+0200) Europe/Kiev'), (b'Europe/Mariehamn', b'(GMT+0200) Europe/Mariehamn'), (b'Europe/Riga', b'(GMT+0200) Europe/Riga'), (b'Europe/Sofia', b'(GMT+0200) Europe/Sofia'), (b'Europe/Tallinn', b'(GMT+0200) Europe/Tallinn'), (b'Europe/Uzhgorod', b'(GMT+0200) Europe/Uzhgorod'), (b'Europe/Vilnius', b'(GMT+0200) Europe/Vilnius'), (b'Europe/Zaporozhye', b'(GMT+0200) Europe/Zaporozhye'), (b'Africa/Addis_Ababa', b'(GMT+0300) Africa/Addis_Ababa'), (b'Africa/Asmara', b'(GMT+0300) Africa/Asmara'), (b'Africa/Dar_es_Salaam', b'(GMT+0300) Africa/Dar_es_Salaam'), (b'Africa/Djibouti', b'(GMT+0300) Africa/Djibouti'), (b'Africa/Juba', b'(GMT+0300) Africa/Juba'), (b'Africa/Kampala', b'(GMT+0300) Africa/Kampala'), (b'Africa/Khartoum', b'(GMT+0300) Africa/Khartoum'), (b'Africa/Mogadishu', b'(GMT+0300) Africa/Mogadishu'), (b'Africa/Nairobi', b'(GMT+0300) Africa/Nairobi'), (b'Antarctica/Syowa', b'(GMT+0300) Antarctica/Syowa'), (b'Asia/Aden', b'(GMT+0300) Asia/Aden'), (b'Asia/Baghdad', b'(GMT+0300) Asia/Baghdad'), (b'Asia/Bahrain', b'(GMT+0300) Asia/Bahrain'), (b'Asia/Kuwait', b'(GMT+0300) Asia/Kuwait'), (b'Asia/Qatar', b'(GMT+0300) Asia/Qatar'), (b'Asia/Riyadh', b'(GMT+0300) Asia/Riyadh'), (b'Europe/Kaliningrad', b'(GMT+0300) Europe/Kaliningrad'), (b'Europe/Minsk', b'(GMT+0300) Europe/Minsk'), (b'Indian/Antananarivo', b'(GMT+0300) Indian/Antananarivo'), (b'Indian/Comoro', b'(GMT+0300) Indian/Comoro'), (b'Indian/Mayotte', b'(GMT+0300) Indian/Mayotte'), (b'Asia/Tehran', b'(GMT+0330) Asia/Tehran'), (b'Asia/Baku', b'(GMT+0400) Asia/Baku'), (b'Asia/Dubai', b'(GMT+0400) Asia/Dubai'), (b'Asia/Muscat', b'(GMT+0400) Asia/Muscat'), (b'Asia/Tbilisi', b'(GMT+0400) Asia/Tbilisi'), (b'Asia/Yerevan', b'(GMT+0400) Asia/Yerevan'), (b'Europe/Moscow', b'(GMT+0400) Europe/Moscow'), (b'Europe/Samara', b'(GMT+0400) Europe/Samara'), (b'Europe/Simferopol', b'(GMT+0400) Europe/Simferopol'), (b'Europe/Volgograd', b'(GMT+0400) Europe/Volgograd'), (b'Indian/Mahe', b'(GMT+0400) Indian/Mahe'), (b'Indian/Mauritius', b'(GMT+0400) Indian/Mauritius'), (b'Indian/Reunion', b'(GMT+0400) Indian/Reunion'), (b'Asia/Kabul', b'(GMT+0430) Asia/Kabul'), (b'Antarctica/Mawson', b'(GMT+0500) Antarctica/Mawson'), (b'Asia/Aqtau', b'(GMT+0500) Asia/Aqtau'), (b'Asia/Aqtobe', b'(GMT+0500) Asia/Aqtobe'), (b'Asia/Ashgabat', b'(GMT+0500) Asia/Ashgabat'), (b'Asia/Dushanbe', b'(GMT+0500) Asia/Dushanbe'), (b'Asia/Karachi', b'(GMT+0500) Asia/Karachi'), (b'Asia/Oral', b'(GMT+0500) Asia/Oral'), (b'Asia/Samarkand', b'(GMT+0500) Asia/Samarkand'), (b'Asia/Tashkent', b'(GMT+0500) Asia/Tashkent'), (b'Indian/Kerguelen', b'(GMT+0500) Indian/Kerguelen'), (b'Indian/Maldives', b'(GMT+0500) Indian/Maldives'), (b'Asia/Colombo', b'(GMT+0530) Asia/Colombo'), (b'Asia/Kolkata', b'(GMT+0530) Asia/Kolkata'), (b'Asia/Kathmandu', b'(GMT+0545) Asia/Kathmandu'), (b'Antarctica/Vostok', b'(GMT+0600) Antarctica/Vostok'), (b'Asia/Almaty', b'(GMT+0600) Asia/Almaty'), (b'Asia/Bishkek', b'(GMT+0600) Asia/Bishkek'), (b'Asia/Dhaka', b'(GMT+0600) Asia/Dhaka'), (b'Asia/Qyzylorda', b'(GMT+0600) Asia/Qyzylorda'), (b'Asia/Thimphu', b'(GMT+0600) Asia/Thimphu'), (b'Asia/Yekaterinburg', b'(GMT+0600) Asia/Yekaterinburg'), (b'Indian/Chagos', b'(GMT+0600) Indian/Chagos'), (b'Asia/Rangoon', b'(GMT+0630) Asia/Rangoon'), (b'Indian/Cocos', b'(GMT+0630) Indian/Cocos'), (b'Antarctica/Davis', b'(GMT+0700) Antarctica/Davis'), (b'Asia/Bangkok', b'(GMT+0700) Asia/Bangkok'), (b'Asia/Ho_Chi_Minh', b'(GMT+0700) Asia/Ho_Chi_Minh'), (b'Asia/Hovd', b'(GMT+0700) Asia/Hovd'), (b'Asia/Jakarta', b'(GMT+0700) Asia/Jakarta'), (b'Asia/Novokuznetsk', b'(GMT+0700) Asia/Novokuznetsk'), (b'Asia/Novosibirsk', b'(GMT+0700) Asia/Novosibirsk'), (b'Asia/Omsk', b'(GMT+0700) Asia/Omsk'), (b'Asia/Phnom_Penh', b'(GMT+0700) Asia/Phnom_Penh'), (b'Asia/Pontianak', b'(GMT+0700) Asia/Pontianak'), (b'Asia/Vientiane', b'(GMT+0700) Asia/Vientiane'), (b'Indian/Christmas', b'(GMT+0700) Indian/Christmas'), (b'Antarctica/Casey', b'(GMT+0800) Antarctica/Casey'), (b'Asia/Brunei', b'(GMT+0800) Asia/Brunei'), (b'Asia/Choibalsan', b'(GMT+0800) Asia/Choibalsan'), (b'Asia/Chongqing', b'(GMT+0800) Asia/Chongqing'), (b'Asia/Harbin', b'(GMT+0800) Asia/Harbin'), (b'Asia/Hong_Kong', b'(GMT+0800) Asia/Hong_Kong'), (b'Asia/Kashgar', b'(GMT+0800) Asia/Kashgar'), (b'Asia/Krasnoyarsk', b'(GMT+0800) Asia/Krasnoyarsk'), (b'Asia/Kuala_Lumpur', b'(GMT+0800) Asia/Kuala_Lumpur'), (b'Asia/Kuching', b'(GMT+0800) Asia/Kuching'), (b'Asia/Macau', b'(GMT+0800) Asia/Macau'), (b'Asia/Makassar', b'(GMT+0800) Asia/Makassar'), (b'Asia/Manila', b'(GMT+0800) Asia/Manila'), (b'Asia/Shanghai', b'(GMT+0800) Asia/Shanghai'), (b'Asia/Singapore', b'(GMT+0800) Asia/Singapore'), (b'Asia/Taipei', b'(GMT+0800) Asia/Taipei'), (b'Asia/Ulaanbaatar', b'(GMT+0800) Asia/Ulaanbaatar'), (b'Asia/Urumqi', b'(GMT+0800) Asia/Urumqi'), (b'Australia/Perth', b'(GMT+0800) Australia/Perth'), (b'Australia/Eucla', b'(GMT+0845) Australia/Eucla'), (b'Asia/Dili', b'(GMT+0900) Asia/Dili'), (b'Asia/Irkutsk', b'(GMT+0900) Asia/Irkutsk'), (b'Asia/Jayapura', b'(GMT+0900) Asia/Jayapura'), (b'Asia/Pyongyang', b'(GMT+0900) Asia/Pyongyang'), (b'Asia/Seoul', b'(GMT+0900) Asia/Seoul'), (b'Asia/Tokyo', b'(GMT+0900) Asia/Tokyo'), (b'Pacific/Palau', b'(GMT+0900) Pacific/Palau'), (b'Australia/Darwin', b'(GMT+0930) Australia/Darwin'), (b'Antarctica/DumontDUrville', b'(GMT+1000) Antarctica/DumontDUrville'), (b'Asia/Yakutsk', b'(GMT+1000) Asia/Yakutsk'), (b'Australia/Brisbane', b'(GMT+1000) Australia/Brisbane'), (b'Australia/Lindeman', b'(GMT+1000) Australia/Lindeman'), (b'Pacific/Chuuk', b'(GMT+1000) Pacific/Chuuk'), (b'Pacific/Guam', b'(GMT+1000) Pacific/Guam'), (b'Pacific/Port_Moresby', b'(GMT+1000) Pacific/Port_Moresby'), (b'Pacific/Saipan', b'(GMT+1000) Pacific/Saipan'), (b'Australia/Adelaide', b'(GMT+1030) Australia/Adelaide'), (b'Australia/Broken_Hill', b'(GMT+1030) Australia/Broken_Hill'), (b'Antarctica/Macquarie', b'(GMT+1100) Antarctica/Macquarie'), (b'Asia/Sakhalin', b'(GMT+1100) Asia/Sakhalin'), (b'Asia/Vladivostok', b'(GMT+1100) Asia/Vladivostok'), (b'Australia/Currie', b'(GMT+1100) Australia/Currie'), (b'Australia/Hobart', b'(GMT+1100) Australia/Hobart'), (b'Australia/Lord_Howe', b'(GMT+1100) Australia/Lord_Howe'), (b'Australia/Melbourne', b'(GMT+1100) Australia/Melbourne'), (b'Australia/Sydney', b'(GMT+1100) Australia/Sydney'), (b'Pacific/Efate', b'(GMT+1100) Pacific/Efate'), (b'Pacific/Guadalcanal', b'(GMT+1100) Pacific/Guadalcanal'), (b'Pacific/Kosrae', b'(GMT+1100) Pacific/Kosrae'), (b'Pacific/Noumea', b'(GMT+1100) Pacific/Noumea'), (b'Pacific/Pohnpei', b'(GMT+1100) Pacific/Pohnpei'), (b'Pacific/Norfolk', b'(GMT+1130) Pacific/Norfolk'), (b'Asia/Anadyr', b'(GMT+1200) Asia/Anadyr'), (b'Asia/Kamchatka', b'(GMT+1200) Asia/Kamchatka'), (b'Asia/Magadan', b'(GMT+1200) Asia/Magadan'), (b'Pacific/Fiji', b'(GMT+1200) Pacific/Fiji'), (b'Pacific/Funafuti', b'(GMT+1200) Pacific/Funafuti'), (b'Pacific/Kwajalein', b'(GMT+1200) Pacific/Kwajalein'), (b'Pacific/Majuro', b'(GMT+1200) Pacific/Majuro'), (b'Pacific/Nauru', b'(GMT+1200) Pacific/Nauru'), (b'Pacific/Tarawa', b'(GMT+1200) Pacific/Tarawa'), (b'Pacific/Wake', b'(GMT+1200) Pacific/Wake'), (b'Pacific/Wallis', b'(GMT+1200) Pacific/Wallis'), (b'Antarctica/McMurdo', b'(GMT+1300) Antarctica/McMurdo'), (b'Antarctica/South_Pole', b'(GMT+1300) Antarctica/South_Pole'), (b'Pacific/Auckland', b'(GMT+1300) Pacific/Auckland'), (b'Pacific/Enderbury', b'(GMT+1300) Pacific/Enderbury'), (b'Pacific/Fakaofo', b'(GMT+1300) Pacific/Fakaofo'), (b'Pacific/Tongatapu', b'(GMT+1300) Pacific/Tongatapu'), (b'Pacific/Chatham', b'(GMT+1345) Pacific/Chatham'), (b'Pacific/Apia', b'(GMT+1400) Pacific/Apia'), (b'Pacific/Kiritimati', b'(GMT+1400) Pacific/Kiritimati')])),
             ],
             options={
             },
@@ -51,12 +61,18 @@
         migrations.CreateModel(
             name='Account',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
             ],
             options={
@@ -67,19 +83,28 @@
         migrations.CreateModel(
             name='Charge',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('kind', models.CharField(default=b'besteffort', max_length=30, choices=[(b'besteffort', b'besteffort'), (b'reservation', b'reservation'), (b'monthlyfee', b'monthlyfee')])),
-                ('state', models.CharField(default=b'pending', max_length=30, choices=[(b'pending', b'pending'), (b'invoiced', b'invoiced')])),
+                ('kind', models.CharField(default=b'besteffort', max_length=30, choices=[
+                 (b'besteffort', b'besteffort'), (b'reservation', b'reservation'), (b'monthlyfee', b'monthlyfee')])),
+                ('state', models.CharField(default=b'pending', max_length=30, choices=[
+                 (b'pending', b'pending'), (b'invoiced', b'invoiced')])),
                 ('date', models.DateTimeField()),
                 ('amount', models.FloatField(default=0.0)),
                 ('coreHours', models.FloatField(default=0.0)),
-                ('account', models.ForeignKey(related_name=b'charges', to='core.Account')),
+                ('account', models.ForeignKey(
+                    related_name=b'charges', to='core.Account')),
             ],
             options={
                 'abstract': False,
@@ -89,20 +114,33 @@
         migrations.CreateModel(
             name='Controller',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name of the Controller', unique=True, max_length=200)),
-                ('backend_type', models.CharField(help_text=b'Type of compute controller, e.g. EC2, OpenStack, or OpenStack version', max_length=200)),
-                ('version', models.CharField(help_text=b'Controller version', max_length=200)),
-                ('auth_url', models.CharField(help_text=b'Auth url for the compute controller', max_length=200, null=True, blank=True)),
-                ('admin_user', models.CharField(help_text=b'Username of an admin user at this controller', max_length=200, null=True, blank=True)),
-                ('admin_password', models.CharField(help_text=b'Password of theadmin user at this controller', max_length=200, null=True, blank=True)),
-                ('admin_tenant', models.CharField(help_text=b'Name of the tenant the admin user belongs to', max_length=200, null=True, blank=True)),
+                ('name', models.CharField(
+                    help_text=b'Name of the Controller', unique=True, max_length=200)),
+                ('backend_type', models.CharField(
+                    help_text=b'Type of compute controller, e.g. EC2, OpenStack, or OpenStack version', max_length=200)),
+                ('version', models.CharField(
+                    help_text=b'Controller version', max_length=200)),
+                ('auth_url', models.CharField(
+                    help_text=b'Auth url for the compute controller', max_length=200, null=True, blank=True)),
+                ('admin_user', models.CharField(
+                    help_text=b'Username of an admin user at this controller', max_length=200, null=True, blank=True)),
+                ('admin_password', models.CharField(
+                    help_text=b'Password of theadmin user at this controller', max_length=200, null=True, blank=True)),
+                ('admin_tenant', models.CharField(
+                    help_text=b'Name of the tenant the admin user belongs to', max_length=200, null=True, blank=True)),
             ],
             options={
                 'abstract': False,
@@ -112,17 +150,27 @@
         migrations.CreateModel(
             name='ControllerCredential',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The credential type, e.g. ec2', max_length=128)),
-                ('key_id', models.CharField(help_text=b'The backend id of this credential', max_length=1024)),
-                ('enc_value', encrypted_fields.fields.EncryptedCharField(help_text=b'The key value of this credential', max_length=1024)),
-                ('controller', models.ForeignKey(related_name=b'controllercredentials', to='core.Controller', help_text=b'The User this credential is associated with')),
+                ('name', models.SlugField(
+                    help_text=b'The credential type, e.g. ec2', max_length=128)),
+                ('key_id', models.CharField(
+                    help_text=b'The backend id of this credential', max_length=1024)),
+                ('enc_value', encrypted_fields.fields.EncryptedCharField(
+                    help_text=b'The key value of this credential', max_length=1024)),
+                ('controller', models.ForeignKey(related_name=b'controllercredentials',
+                                                 to='core.Controller', help_text=b'The User this credential is associated with')),
             ],
             options={
                 'abstract': False,
@@ -132,16 +180,23 @@
         migrations.CreateModel(
             name='ControllerDashboardView',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('enabled', models.BooleanField(default=True)),
                 ('url', models.CharField(help_text=b'URL of Dashboard', max_length=1024)),
-                ('controller', models.ForeignKey(related_name=b'controllerdashboardviews', to='core.Controller')),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllerdashboardviews', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -151,15 +206,23 @@
         migrations.CreateModel(
             name='ControllerImages',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('glance_image_id', models.CharField(help_text=b'Glance image id', max_length=200, null=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllerimages', to='core.Controller')),
+                ('glance_image_id', models.CharField(
+                    help_text=b'Glance image id', max_length=200, null=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllerimages', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -169,18 +232,28 @@
         migrations.CreateModel(
             name='ControllerNetwork',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('net_id', models.CharField(help_text=b'Quantum network', max_length=256, null=True, blank=True)),
-                ('router_id', models.CharField(help_text=b'Quantum router id', max_length=256, null=True, blank=True)),
-                ('subnet_id', models.CharField(help_text=b'Quantum subnet id', max_length=256, null=True, blank=True)),
+                ('net_id', models.CharField(help_text=b'Quantum network',
+                                            max_length=256, null=True, blank=True)),
+                ('router_id', models.CharField(help_text=b'Quantum router id',
+                                               max_length=256, null=True, blank=True)),
+                ('subnet_id', models.CharField(help_text=b'Quantum subnet id',
+                                               max_length=256, null=True, blank=True)),
                 ('subnet', models.CharField(max_length=32, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllernetworks', to='core.Controller')),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllernetworks', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -190,14 +263,21 @@
         migrations.CreateModel(
             name='ControllerRole',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role', models.CharField(unique=True, max_length=30, choices=[(b'admin', b'Admin')])),
+                ('role', models.CharField(unique=True,
+                                          max_length=30, choices=[(b'admin', b'Admin')])),
             ],
             options={
                 'abstract': False,
@@ -207,15 +287,23 @@
         migrations.CreateModel(
             name='ControllerSite',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('tenant_id', models.CharField(help_text=b'Keystone tenant id', max_length=200, null=True, db_index=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllersite', blank=True, to='core.Controller', null=True)),
+                ('tenant_id', models.CharField(help_text=b'Keystone tenant id',
+                                               max_length=200, null=True, db_index=True, blank=True)),
+                ('controller', models.ForeignKey(related_name=b'controllersite',
+                                                 blank=True, to='core.Controller', null=True)),
             ],
             options={
                 'abstract': False,
@@ -225,15 +313,23 @@
         migrations.CreateModel(
             name='ControllerSitePrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role_id', models.CharField(help_text=b'Keystone id', max_length=200, null=True, db_index=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllersiteprivileges', to='core.Controller')),
+                ('role_id', models.CharField(help_text=b'Keystone id',
+                                             max_length=200, null=True, db_index=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllersiteprivileges', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -243,15 +339,23 @@
         migrations.CreateModel(
             name='ControllerSlice',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('tenant_id', models.CharField(help_text=b'Keystone tenant id', max_length=200, null=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllerslices', to='core.Controller')),
+                ('tenant_id', models.CharField(
+                    help_text=b'Keystone tenant id', max_length=200, null=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllerslices', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -261,15 +365,23 @@
         migrations.CreateModel(
             name='ControllerSlicePrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role_id', models.CharField(help_text=b'Keystone id', max_length=200, null=True, db_index=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllersliceprivileges', to='core.Controller')),
+                ('role_id', models.CharField(help_text=b'Keystone id',
+                                             max_length=200, null=True, db_index=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllersliceprivileges', to='core.Controller')),
             ],
             options={
                 'abstract': False,
@@ -279,16 +391,25 @@
         migrations.CreateModel(
             name='ControllerUser',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('kuser_id', models.CharField(help_text=b'Keystone user id', max_length=200, null=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'controllersusers', to='core.Controller')),
-                ('user', models.ForeignKey(related_name=b'controllerusers', to=settings.AUTH_USER_MODEL)),
+                ('kuser_id', models.CharField(help_text=b'Keystone user id',
+                                              max_length=200, null=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'controllersusers', to='core.Controller')),
+                ('user', models.ForeignKey(
+                    related_name=b'controllerusers', to=settings.AUTH_USER_MODEL)),
             ],
             options={
                 'abstract': False,
@@ -298,17 +419,25 @@
         migrations.CreateModel(
             name='DashboardView',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name of the View', unique=True, max_length=200)),
+                ('name', models.CharField(
+                    help_text=b'Name of the View', unique=True, max_length=200)),
                 ('url', models.CharField(help_text=b'URL of Dashboard', max_length=1024)),
                 ('enabled', models.BooleanField(default=True)),
-                ('controllers', models.ManyToManyField(related_name=b'dashboardviews', through='core.ControllerDashboardView', to='core.Controller', blank=True)),
+                ('controllers', models.ManyToManyField(related_name=b'dashboardviews',
+                                                       through='core.ControllerDashboardView', to='core.Controller', blank=True)),
             ],
             options={
                 'abstract': False,
@@ -318,15 +447,23 @@
         migrations.CreateModel(
             name='Deployment',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name of the Deployment', unique=True, max_length=200)),
-                ('accessControl', models.TextField(default=b'allow all', help_text=b'Access control list that specifies which sites/users may use nodes in this deployment', max_length=200)),
+                ('name', models.CharField(
+                    help_text=b'Name of the Deployment', unique=True, max_length=200)),
+                ('accessControl', models.TextField(default=b'allow all',
+                                                   help_text=b'Access control list that specifies which sites/users may use nodes in this deployment', max_length=200)),
             ],
             options={
                 'abstract': False,
@@ -336,14 +473,21 @@
         migrations.CreateModel(
             name='DeploymentPrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('deployment', models.ForeignKey(related_name=b'deploymentprivileges', to='core.Deployment')),
+                ('deployment', models.ForeignKey(
+                    related_name=b'deploymentprivileges', to='core.Deployment')),
             ],
             options={
                 'abstract': False,
@@ -353,14 +497,21 @@
         migrations.CreateModel(
             name='DeploymentRole',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role', models.CharField(unique=True, max_length=30, choices=[(b'admin', b'Admin')])),
+                ('role', models.CharField(unique=True,
+                                          max_length=30, choices=[(b'admin', b'Admin')])),
             ],
             options={
                 'abstract': False,
@@ -370,19 +521,31 @@
         migrations.CreateModel(
             name='Flavor',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'name of this flavor, as displayed to users', max_length=32)),
-                ('description', models.CharField(max_length=1024, null=True, blank=True)),
-                ('flavor', models.CharField(help_text=b'flavor string used to configure deployments', max_length=32)),
-                ('order', models.IntegerField(default=0, help_text=b'used to order flavors when displayed in a list')),
-                ('default', models.BooleanField(default=False, help_text=b'make this a default flavor to use when creating new instances')),
-                ('deployments', models.ManyToManyField(related_name=b'flavors', to='core.Deployment', blank=True)),
+                ('name', models.CharField(
+                    help_text=b'name of this flavor, as displayed to users', max_length=32)),
+                ('description', models.CharField(
+                    max_length=1024, null=True, blank=True)),
+                ('flavor', models.CharField(
+                    help_text=b'flavor string used to configure deployments', max_length=32)),
+                ('order', models.IntegerField(default=0,
+                                              help_text=b'used to order flavors when displayed in a list')),
+                ('default', models.BooleanField(default=False,
+                                                help_text=b'make this a default flavor to use when creating new instances')),
+                ('deployments', models.ManyToManyField(
+                    related_name=b'flavors', to='core.Deployment', blank=True)),
             ],
             options={
                 'ordering': ('order', 'name'),
@@ -392,17 +555,24 @@
         migrations.CreateModel(
             name='Image',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(unique=True, max_length=256)),
                 ('disk_format', models.CharField(max_length=256)),
                 ('container_format', models.CharField(max_length=256)),
-                ('path', models.CharField(help_text=b'Path to image on local disk', max_length=256, null=True, blank=True)),
+                ('path', models.CharField(help_text=b'Path to image on local disk',
+                                          max_length=256, null=True, blank=True)),
             ],
             options={
                 'abstract': False,
@@ -412,15 +582,23 @@
         migrations.CreateModel(
             name='ImageDeployments',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('deployment', models.ForeignKey(related_name=b'imagedeployments', to='core.Deployment')),
-                ('image', models.ForeignKey(related_name=b'imagedeployments', to='core.Image')),
+                ('deployment', models.ForeignKey(
+                    related_name=b'imagedeployments', to='core.Deployment')),
+                ('image', models.ForeignKey(
+                    related_name=b'imagedeployments', to='core.Image')),
             ],
             options={
                 'abstract': False,
@@ -430,15 +608,22 @@
         migrations.CreateModel(
             name='Invoice',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('date', models.DateTimeField()),
-                ('account', models.ForeignKey(related_name=b'invoices', to='core.Account')),
+                ('account', models.ForeignKey(
+                    related_name=b'invoices', to='core.Account')),
             ],
             options={
                 'abstract': False,
@@ -448,25 +633,36 @@
         migrations.CreateModel(
             name='Network',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=32)),
                 ('subnet', models.CharField(max_length=32, blank=True)),
-                ('ports', models.CharField(blank=True, max_length=1024, null=True, validators=[core.models.network.ValidateNatList])),
+                ('ports', models.CharField(blank=True, max_length=1024,
+                                           null=True, validators=[core.models.network.ValidateNatList])),
                 ('labels', models.CharField(max_length=1024, null=True, blank=True)),
                 ('guaranteed_bandwidth', models.IntegerField(default=0)),
                 ('permit_all_slices', models.BooleanField(default=False)),
                 ('topology_parameters', models.TextField(null=True, blank=True)),
-                ('controller_url', models.CharField(max_length=1024, null=True, blank=True)),
+                ('controller_url', models.CharField(
+                    max_length=1024, null=True, blank=True)),
                 ('controller_parameters', models.TextField(null=True, blank=True)),
-                ('network_id', models.CharField(help_text=b'Quantum network', max_length=256, null=True, blank=True)),
-                ('router_id', models.CharField(help_text=b'Quantum router id', max_length=256, null=True, blank=True)),
-                ('subnet_id', models.CharField(help_text=b'Quantum subnet id', max_length=256, null=True, blank=True)),
+                ('network_id', models.CharField(help_text=b'Quantum network',
+                                                max_length=256, null=True, blank=True)),
+                ('router_id', models.CharField(help_text=b'Quantum router id',
+                                               max_length=256, null=True, blank=True)),
+                ('subnet_id', models.CharField(help_text=b'Quantum subnet id',
+                                               max_length=256, null=True, blank=True)),
             ],
             options={
                 'abstract': False,
@@ -476,14 +672,21 @@
         migrations.CreateModel(
             name='NetworkParameter',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('value', models.CharField(help_text=b'The value of this parameter', max_length=1024)),
+                ('value', models.CharField(
+                    help_text=b'The value of this parameter', max_length=1024)),
                 ('object_id', models.PositiveIntegerField()),
                 ('content_type', models.ForeignKey(to='contenttypes.ContentType')),
             ],
@@ -495,14 +698,21 @@
         migrations.CreateModel(
             name='NetworkParameterType',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The name of this parameter', max_length=128)),
+                ('name', models.SlugField(
+                    help_text=b'The name of this parameter', max_length=128)),
                 ('description', models.CharField(max_length=1024)),
             ],
             options={
@@ -513,14 +723,21 @@
         migrations.CreateModel(
             name='NetworkSlice',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('network', models.ForeignKey(related_name=b'networkslices', to='core.Network')),
+                ('network', models.ForeignKey(
+                    related_name=b'networkslices', to='core.Network')),
             ],
             options={
                 'abstract': False,
@@ -530,16 +747,25 @@
         migrations.CreateModel(
             name='NetworkInstance',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('ip', models.GenericIPAddressField(help_text=b'Instance ip address', null=True, blank=True)),
-                ('port_id', models.CharField(help_text=b'Quantum port id', max_length=256, null=True, blank=True)),
-                ('network', models.ForeignKey(related_name=b'networkinstances', to='core.Network')),
+                ('ip', models.GenericIPAddressField(
+                    help_text=b'Instance ip address', null=True, blank=True)),
+                ('port_id', models.CharField(help_text=b'Quantum port id',
+                                             max_length=256, null=True, blank=True)),
+                ('network', models.ForeignKey(
+                    related_name=b'networkinstances', to='core.Network')),
             ],
             options={
                 'abstract': False,
@@ -549,22 +775,35 @@
         migrations.CreateModel(
             name='NetworkTemplate',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=32)),
-                ('description', models.CharField(max_length=1024, null=True, blank=True)),
+                ('description', models.CharField(
+                    max_length=1024, null=True, blank=True)),
                 ('guaranteed_bandwidth', models.IntegerField(default=0)),
-                ('visibility', models.CharField(default=b'private', max_length=30, choices=[(b'public', b'public'), (b'private', b'private')])),
-                ('translation', models.CharField(default=b'none', max_length=30, choices=[(b'none', b'none'), (b'NAT', b'NAT')])),
-                ('shared_network_name', models.CharField(max_length=30, null=True, blank=True)),
-                ('shared_network_id', models.CharField(help_text=b'Quantum network', max_length=256, null=True, blank=True)),
-                ('topology_kind', models.CharField(default=b'BigSwitch', max_length=30, choices=[(b'bigswitch', b'BigSwitch'), (b'physical', b'Physical'), (b'custom', b'Custom')])),
-                ('controller_kind', models.CharField(default=None, max_length=30, null=True, blank=True, choices=[(None, b'None'), (b'onos', b'ONOS'), (b'custom', b'Custom')])),
+                ('visibility', models.CharField(default=b'private', max_length=30,
+                                                choices=[(b'public', b'public'), (b'private', b'private')])),
+                ('translation', models.CharField(default=b'none', max_length=30,
+                                                 choices=[(b'none', b'none'), (b'NAT', b'NAT')])),
+                ('shared_network_name', models.CharField(
+                    max_length=30, null=True, blank=True)),
+                ('shared_network_id', models.CharField(
+                    help_text=b'Quantum network', max_length=256, null=True, blank=True)),
+                ('topology_kind', models.CharField(default=b'BigSwitch', max_length=30, choices=[
+                 (b'bigswitch', b'BigSwitch'), (b'physical', b'Physical'), (b'custom', b'Custom')])),
+                ('controller_kind', models.CharField(default=None, max_length=30, null=True,
+                                                     blank=True, choices=[(None, b'None'), (b'onos', b'ONOS'), (b'custom', b'Custom')])),
             ],
             options={
                 'abstract': False,
@@ -574,14 +813,21 @@
         migrations.CreateModel(
             name='Node',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name of the Node', unique=True, max_length=200)),
+                ('name', models.CharField(
+                    help_text=b'Name of the Node', unique=True, max_length=200)),
             ],
             options={
                 'abstract': False,
@@ -591,16 +837,23 @@
         migrations.CreateModel(
             name='Payment',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('amount', models.FloatField(default=0.0)),
                 ('date', models.DateTimeField(default=django.utils.timezone.now)),
-                ('account', models.ForeignKey(related_name=b'payments', to='core.Account')),
+                ('account', models.ForeignKey(
+                    related_name=b'payments', to='core.Account')),
             ],
             options={
                 'abstract': False,
@@ -610,14 +863,21 @@
         migrations.CreateModel(
             name='PlanetStack',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('description', models.CharField(default=b'PlanetStack', help_text=b'Used for scoping of roles at the PlanetStack Application level', unique=True, max_length=200)),
+                ('description', models.CharField(default=b'PlanetStack',
+                                                 help_text=b'Used for scoping of roles at the PlanetStack Application level', unique=True, max_length=200)),
             ],
             options={
                 'verbose_name_plural': 'PlanetStack',
@@ -627,14 +887,21 @@
         migrations.CreateModel(
             name='PlanetStackPrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('planetstack', models.ForeignKey(related_name=b'planetstackprivileges', default=1, to='core.PlanetStack')),
+                ('planetstack', models.ForeignKey(
+                    related_name=b'planetstackprivileges', default=1, to='core.PlanetStack')),
             ],
             options={
                 'abstract': False,
@@ -644,14 +911,21 @@
         migrations.CreateModel(
             name='PlanetStackRole',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role', models.CharField(unique=True, max_length=30, choices=[(b'admin', b'Admin')])),
+                ('role', models.CharField(unique=True,
+                                          max_length=30, choices=[(b'admin', b'Admin')])),
             ],
             options={
                 'abstract': False,
@@ -661,14 +935,21 @@
         migrations.CreateModel(
             name='Project',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name of Project', unique=True, max_length=200)),
+                ('name', models.CharField(
+                    help_text=b'Name of Project', unique=True, max_length=200)),
             ],
             options={
                 'abstract': False,
@@ -678,12 +959,18 @@
         migrations.CreateModel(
             name='Reservation',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('startTime', models.DateTimeField()),
                 ('duration', models.IntegerField(default=1)),
@@ -696,15 +983,22 @@
         migrations.CreateModel(
             name='ReservedResource',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('quantity', models.IntegerField(default=1)),
-                ('reservationSet', models.ForeignKey(related_name=b'reservedresources', to='core.Reservation')),
+                ('reservationSet', models.ForeignKey(
+                    related_name=b'reservedresources', to='core.Reservation')),
             ],
             options={
                 'abstract': False,
@@ -715,17 +1009,26 @@
         migrations.CreateModel(
             name='Role',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('role_type', models.CharField(max_length=80, verbose_name=b'Name')),
-                ('role', models.CharField(max_length=80, null=True, verbose_name=b'Keystone role id', blank=True)),
-                ('description', models.CharField(max_length=120, verbose_name=b'Description')),
-                ('content_type', models.ForeignKey(verbose_name=b'Role Scope', to='contenttypes.ContentType')),
+                ('role', models.CharField(max_length=80, null=True,
+                                          verbose_name=b'Keystone role id', blank=True)),
+                ('description', models.CharField(
+                    max_length=120, verbose_name=b'Description')),
+                ('content_type', models.ForeignKey(
+                    verbose_name=b'Role Scope', to='contenttypes.ContentType')),
             ],
             options={
                 'abstract': False,
@@ -735,15 +1038,22 @@
         migrations.CreateModel(
             name='Router',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=32)),
-                ('networks', models.ManyToManyField(related_name=b'routers', to='core.Network', blank=True)),
+                ('networks', models.ManyToManyField(
+                    related_name=b'routers', to='core.Network', blank=True)),
             ],
             options={
                 'abstract': False,
@@ -753,17 +1063,25 @@
         migrations.CreateModel(
             name='Service',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('description', models.TextField(help_text=b'Description of Service', max_length=254, null=True, blank=True)),
+                ('description', models.TextField(
+                    help_text=b'Description of Service', max_length=254, null=True, blank=True)),
                 ('enabled', models.BooleanField(default=True)),
                 ('name', models.CharField(help_text=b'Service Name', max_length=30)),
-                ('versionNumber', models.CharField(help_text=b'Version of Service Definition', max_length=30)),
+                ('versionNumber', models.CharField(
+                    help_text=b'Version of Service Definition', max_length=30)),
                 ('published', models.BooleanField(default=True)),
             ],
             options={
@@ -774,16 +1092,24 @@
         migrations.CreateModel(
             name='ServiceAttribute',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.SlugField(help_text=b'Attribute Name', max_length=128)),
-                ('value', models.CharField(help_text=b'Attribute Value', max_length=1024)),
-                ('service', models.ForeignKey(related_name=b'serviceattributes', to='core.Service', help_text=b'The Service this attribute is associated with')),
+                ('value', models.CharField(
+                    help_text=b'Attribute Value', max_length=1024)),
+                ('service', models.ForeignKey(related_name=b'serviceattributes',
+                                              to='core.Service', help_text=b'The Service this attribute is associated with')),
             ],
             options={
                 'abstract': False,
@@ -793,12 +1119,18 @@
         migrations.CreateModel(
             name='ServiceClass',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=32)),
                 ('description', models.CharField(max_length=255)),
@@ -806,7 +1138,8 @@
                 ('membershipFee', models.IntegerField(default=0)),
                 ('membershipFeeMonths', models.IntegerField(default=12)),
                 ('upgradeRequiresApproval', models.BooleanField(default=False)),
-                ('upgradeFrom', models.ManyToManyField(related_name='upgradeFrom_rel_+', null=True, to='core.ServiceClass', blank=True)),
+                ('upgradeFrom', models.ManyToManyField(
+                    related_name='upgradeFrom_rel_+', null=True, to='core.ServiceClass', blank=True)),
             ],
             options={
                 'abstract': False,
@@ -817,12 +1150,18 @@
         migrations.CreateModel(
             name='ServiceResource',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=32)),
                 ('maxUnitsDeployment', models.IntegerField(default=1)),
@@ -832,7 +1171,8 @@
                 ('bucketMaxSize', models.IntegerField(default=0)),
                 ('cost', models.IntegerField(default=0)),
                 ('calendarReservable', models.BooleanField(default=True)),
-                ('serviceClass', models.ForeignKey(related_name=b'serviceresources', to='core.ServiceClass')),
+                ('serviceClass', models.ForeignKey(
+                    related_name=b'serviceresources', to='core.ServiceClass')),
             ],
             options={
                 'abstract': False,
@@ -842,21 +1182,32 @@
         migrations.CreateModel(
             name='Site',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'Name for this Site', max_length=200)),
-                ('site_url', models.URLField(help_text=b"Site's Home URL Page", max_length=512, null=True, blank=True)),
-                ('enabled', models.BooleanField(default=True, help_text=b'Status for this Site')),
+                ('name', models.CharField(
+                    help_text=b'Name for this Site', max_length=200)),
+                ('site_url', models.URLField(help_text=b"Site's Home URL Page",
+                                             max_length=512, null=True, blank=True)),
+                ('enabled', models.BooleanField(
+                    default=True, help_text=b'Status for this Site')),
                 ('location', geoposition.fields.GeopositionField(max_length=42)),
                 ('longitude', models.FloatField(null=True, blank=True)),
                 ('latitude', models.FloatField(null=True, blank=True)),
-                ('login_base', models.CharField(help_text=b'Prefix for Slices associated with this Site', unique=True, max_length=50)),
-                ('is_public', models.BooleanField(default=True, help_text=b'Indicates the visibility of this site to other members')),
+                ('login_base', models.CharField(
+                    help_text=b'Prefix for Slices associated with this Site', unique=True, max_length=50)),
+                ('is_public', models.BooleanField(
+                    default=True, help_text=b'Indicates the visibility of this site to other members')),
                 ('abbreviated_name', models.CharField(max_length=80)),
             ],
             options={
@@ -867,17 +1218,27 @@
         migrations.CreateModel(
             name='SiteCredential',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The credential type, e.g. ec2', max_length=128)),
-                ('key_id', models.CharField(help_text=b'The backend id of this credential', max_length=1024)),
-                ('enc_value', encrypted_fields.fields.EncryptedCharField(help_text=b'The key value of this credential', max_length=1024)),
-                ('site', models.ForeignKey(related_name=b'sitecredentials', to='core.Site', help_text=b'The User this credential is associated with')),
+                ('name', models.SlugField(
+                    help_text=b'The credential type, e.g. ec2', max_length=128)),
+                ('key_id', models.CharField(
+                    help_text=b'The backend id of this credential', max_length=1024)),
+                ('enc_value', encrypted_fields.fields.EncryptedCharField(
+                    help_text=b'The key value of this credential', max_length=1024)),
+                ('site', models.ForeignKey(related_name=b'sitecredentials', to='core.Site',
+                                           help_text=b'The User this credential is associated with')),
             ],
             options={
                 'abstract': False,
@@ -887,17 +1248,27 @@
         migrations.CreateModel(
             name='SiteDeployment',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('availability_zone', models.CharField(help_text=b'OpenStack availability zone', max_length=200, null=True, blank=True)),
-                ('controller', models.ForeignKey(related_name=b'sitedeployments', blank=True, to='core.Controller', null=True)),
-                ('deployment', models.ForeignKey(related_name=b'sitedeployments', to='core.Deployment')),
-                ('site', models.ForeignKey(related_name=b'sitedeployments', to='core.Site')),
+                ('availability_zone', models.CharField(
+                    help_text=b'OpenStack availability zone', max_length=200, null=True, blank=True)),
+                ('controller', models.ForeignKey(
+                    related_name=b'sitedeployments', blank=True, to='core.Controller', null=True)),
+                ('deployment', models.ForeignKey(
+                    related_name=b'sitedeployments', to='core.Deployment')),
+                ('site', models.ForeignKey(
+                    related_name=b'sitedeployments', to='core.Site')),
             ],
             options={
                 'abstract': False,
@@ -907,12 +1278,18 @@
         migrations.CreateModel(
             name='SitePrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
             ],
             options={
@@ -923,14 +1300,21 @@
         migrations.CreateModel(
             name='SiteRole',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role', models.CharField(unique=True, max_length=30, choices=[(b'admin', b'Admin'), (b'pi', b'PI'), (b'tech', b'Tech'), (b'billing', b'Billing')])),
+                ('role', models.CharField(unique=True, max_length=30, choices=[
+                 (b'admin', b'Admin'), (b'pi', b'PI'), (b'tech', b'Tech'), (b'billing', b'Billing')])),
             ],
             options={
                 'abstract': False,
@@ -940,27 +1324,44 @@
         migrations.CreateModel(
             name='Slice',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'The Name of the Slice', unique=True, max_length=80)),
-                ('enabled', models.BooleanField(default=True, help_text=b'Status for this Slice')),
+                ('name', models.CharField(
+                    help_text=b'The Name of the Slice', unique=True, max_length=80)),
+                ('enabled', models.BooleanField(
+                    default=True, help_text=b'Status for this Slice')),
                 ('omf_friendly', models.BooleanField(default=False)),
-                ('description', models.TextField(help_text=b'High level description of the slice and expected activities', max_length=1024, blank=True)),
+                ('description', models.TextField(
+                    help_text=b'High level description of the slice and expected activities', max_length=1024, blank=True)),
                 ('slice_url', models.URLField(max_length=512, blank=True)),
                 ('max_instances', models.IntegerField(default=10)),
-                ('network', models.CharField(default=b'Private Only', max_length=256, null=True, blank=True)),
-                ('mount_data_sets', models.CharField(default=b'GenBank', max_length=256, null=True, blank=True)),
-                ('creator', models.ForeignKey(related_name=b'slices', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-                ('default_flavor', models.ForeignKey(related_name=b'slices', blank=True, to='core.Flavor', null=True)),
-                ('default_image', models.ForeignKey(related_name=b'slices', blank=True, to='core.Image', null=True)),
-                ('service', models.ForeignKey(related_name=b'service', blank=True, to='core.Service', null=True)),
-                ('serviceClass', models.ForeignKey(related_name=b'slices', default=core.models.serviceclass.get_default_serviceclass, to='core.ServiceClass', null=True)),
-                ('site', models.ForeignKey(related_name=b'slices', to='core.Site', help_text=b'The Site this Slice belongs to')),
+                ('network', models.CharField(default=b'Private Only',
+                                             max_length=256, null=True, blank=True)),
+                ('mount_data_sets', models.CharField(
+                    default=b'GenBank', max_length=256, null=True, blank=True)),
+                ('creator', models.ForeignKey(related_name=b'slices',
+                                              blank=True, to=settings.AUTH_USER_MODEL, null=True)),
+                ('default_flavor', models.ForeignKey(
+                    related_name=b'slices', blank=True, to='core.Flavor', null=True)),
+                ('default_image', models.ForeignKey(
+                    related_name=b'slices', blank=True, to='core.Image', null=True)),
+                ('service', models.ForeignKey(related_name=b'service',
+                                              blank=True, to='core.Service', null=True)),
+                ('serviceClass', models.ForeignKey(related_name=b'slices',
+                                                   default=core.models.serviceclass.get_default_serviceclass, to='core.ServiceClass', null=True)),
+                ('site', models.ForeignKey(related_name=b'slices',
+                                           to='core.Site', help_text=b'The Site this Slice belongs to')),
             ],
             options={
                 'abstract': False,
@@ -970,17 +1371,27 @@
         migrations.CreateModel(
             name='SliceCredential',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The credential type, e.g. ec2', max_length=128)),
-                ('key_id', models.CharField(help_text=b'The backend id of this credential', max_length=1024)),
-                ('enc_value', encrypted_fields.fields.EncryptedCharField(help_text=b'The key value of this credential', max_length=1024)),
-                ('slice', models.ForeignKey(related_name=b'slicecredentials', to='core.Slice', help_text=b'The User this credential is associated with')),
+                ('name', models.SlugField(
+                    help_text=b'The credential type, e.g. ec2', max_length=128)),
+                ('key_id', models.CharField(
+                    help_text=b'The backend id of this credential', max_length=1024)),
+                ('enc_value', encrypted_fields.fields.EncryptedCharField(
+                    help_text=b'The key value of this credential', max_length=1024)),
+                ('slice', models.ForeignKey(related_name=b'slicecredentials',
+                                            to='core.Slice', help_text=b'The User this credential is associated with')),
             ],
             options={
                 'abstract': False,
@@ -990,12 +1401,18 @@
         migrations.CreateModel(
             name='SlicePrivilege',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
             ],
             options={
@@ -1006,14 +1423,21 @@
         migrations.CreateModel(
             name='SliceRole',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('role', models.CharField(unique=True, max_length=30, choices=[(b'admin', b'Admin'), (b'default', b'Default')])),
+                ('role', models.CharField(unique=True, max_length=30,
+                                          choices=[(b'admin', b'Admin'), (b'default', b'Default')])),
             ],
             options={
                 'abstract': False,
@@ -1023,16 +1447,25 @@
         migrations.CreateModel(
             name='SliceTag',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.CharField(help_text=b'The name of this tag', max_length=30, choices=[(b'privatekey', b'Private Key'), (b'publickey', b'Public Key')])),
-                ('value', models.CharField(help_text=b'The value of this tag', max_length=1024)),
-                ('slice', models.ForeignKey(related_name=b'slicetags', to='core.Slice')),
+                ('name', models.CharField(help_text=b'The name of this tag', max_length=30, choices=[
+                 (b'privatekey', b'Private Key'), (b'publickey', b'Public Key')])),
+                ('value', models.CharField(
+                    help_text=b'The value of this tag', max_length=1024)),
+                ('slice', models.ForeignKey(
+                    related_name=b'slicetags', to='core.Slice')),
             ],
             options={
                 'abstract': False,
@@ -1042,26 +1475,43 @@
         migrations.CreateModel(
             name='Instance',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('instance_id', models.CharField(help_text=b'Nova instance id', max_length=200, null=True, blank=True)),
-                ('instance_uuid', models.CharField(help_text=b'Nova instance uuid', max_length=200, null=True, blank=True)),
+                ('instance_id', models.CharField(
+                    help_text=b'Nova instance id', max_length=200, null=True, blank=True)),
+                ('instance_uuid', models.CharField(
+                    help_text=b'Nova instance uuid', max_length=200, null=True, blank=True)),
                 ('name', models.CharField(help_text=b'Instance name', max_length=200)),
-                ('instance_name', models.CharField(help_text=b'OpenStack generated name', max_length=200, null=True, blank=True)),
-                ('ip', models.GenericIPAddressField(help_text=b'Instance ip address', null=True, blank=True)),
-                ('numberCores', models.IntegerField(default=0, help_text=b'Number of cores for instance', verbose_name=b'Number of Cores')),
-                ('userData', models.TextField(help_text=b'user_data passed to instance during creation', null=True, blank=True)),
-                ('creator', models.ForeignKey(related_name=b'instances', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-                ('deployment', models.ForeignKey(related_name=b'instance_deployment', verbose_name=b'deployment', to='core.Deployment')),
-                ('flavor', models.ForeignKey(default=core.models.instance.get_default_flavor, to='core.Flavor', help_text=b'Flavor of this instance')),
-                ('image', models.ForeignKey(related_name=b'instances', to='core.Image')),
+                ('instance_name', models.CharField(
+                    help_text=b'OpenStack generated name', max_length=200, null=True, blank=True)),
+                ('ip', models.GenericIPAddressField(
+                    help_text=b'Instance ip address', null=True, blank=True)),
+                ('numberCores', models.IntegerField(
+                    default=0, help_text=b'Number of cores for instance', verbose_name=b'Number of Cores')),
+                ('userData', models.TextField(
+                    help_text=b'user_data passed to instance during creation', null=True, blank=True)),
+                ('creator', models.ForeignKey(related_name=b'instances',
+                                              blank=True, to=settings.AUTH_USER_MODEL, null=True)),
+                ('deployment', models.ForeignKey(related_name=b'instance_deployment',
+                                                 verbose_name=b'deployment', to='core.Deployment')),
+                ('flavor', models.ForeignKey(default=core.models.instance.get_default_flavor,
+                                             to='core.Flavor', help_text=b'Flavor of this instance')),
+                ('image', models.ForeignKey(
+                    related_name=b'instances', to='core.Image')),
                 ('node', models.ForeignKey(related_name=b'instances', to='core.Node')),
-                ('slice', models.ForeignKey(related_name=b'instances', to='core.Slice')),
+                ('slice', models.ForeignKey(
+                    related_name=b'instances', to='core.Slice')),
             ],
             options={
                 'abstract': False,
@@ -1071,18 +1521,27 @@
         migrations.CreateModel(
             name='Tag',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The name of this tag', max_length=128)),
-                ('value', models.CharField(help_text=b'The value of this tag', max_length=1024)),
+                ('name', models.SlugField(
+                    help_text=b'The name of this tag', max_length=128)),
+                ('value', models.CharField(
+                    help_text=b'The value of this tag', max_length=1024)),
                 ('object_id', models.PositiveIntegerField()),
                 ('content_type', models.ForeignKey(to='contenttypes.ContentType')),
-                ('service', models.ForeignKey(related_name=b'tags', to='core.Service', help_text=b'The Service this Tag is associated with')),
+                ('service', models.ForeignKey(related_name=b'tags', to='core.Service',
+                                              help_text=b'The Service this Tag is associated with')),
             ],
             options={
                 'abstract': False,
@@ -1092,12 +1551,18 @@
         migrations.CreateModel(
             name='UsableObject',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('name', models.CharField(max_length=1024)),
             ],
@@ -1109,17 +1574,27 @@
         migrations.CreateModel(
             name='UserCredential',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
-                ('name', models.SlugField(help_text=b'The credential type, e.g. ec2', max_length=128)),
-                ('key_id', models.CharField(help_text=b'The backend id of this credential', max_length=1024)),
-                ('enc_value', encrypted_fields.fields.EncryptedCharField(help_text=b'The key value of this credential', max_length=1024)),
-                ('user', models.ForeignKey(related_name=b'usercredentials', to=settings.AUTH_USER_MODEL, help_text=b'The User this credential is associated with')),
+                ('name', models.SlugField(
+                    help_text=b'The credential type, e.g. ec2', max_length=128)),
+                ('key_id', models.CharField(
+                    help_text=b'The backend id of this credential', max_length=1024)),
+                ('enc_value', encrypted_fields.fields.EncryptedCharField(
+                    help_text=b'The key value of this credential', max_length=1024)),
+                ('user', models.ForeignKey(related_name=b'usercredentials', to=settings.AUTH_USER_MODEL,
+                                           help_text=b'The User this credential is associated with')),
             ],
             options={
                 'abstract': False,
@@ -1129,16 +1604,24 @@
         migrations.CreateModel(
             name='UserDashboardView',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
-                ('updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
-                ('enacted', models.DateTimeField(default=None, null=True, blank=True)),
-                ('policed', models.DateTimeField(default=None, null=True, blank=True)),
-                ('backend_status', models.CharField(default=b'Provisioning in progress', max_length=140)),
+                ('id', models.AutoField(verbose_name='ID',
+                                        serialize=False, auto_created=True, primary_key=True)),
+                ('created', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now_add=True)),
+                ('updated', models.DateTimeField(
+                    default=django.utils.timezone.now, auto_now=True)),
+                ('enacted', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('policed', models.DateTimeField(
+                    default=None, null=True, blank=True)),
+                ('backend_status', models.CharField(
+                    default=b'Provisioning in progress', max_length=140)),
                 ('deleted', models.BooleanField(default=False)),
                 ('order', models.IntegerField(default=0)),
-                ('dashboardView', models.ForeignKey(related_name=b'userdashboardviews', to='core.DashboardView')),
-                ('user', models.ForeignKey(related_name=b'userdashboardviews', to=settings.AUTH_USER_MODEL)),
+                ('dashboardView', models.ForeignKey(
+                    related_name=b'userdashboardviews', to='core.DashboardView')),
+                ('user', models.ForeignKey(
+                    related_name=b'userdashboardviews', to=settings.AUTH_USER_MODEL)),
             ],
             options={
                 'abstract': False,
@@ -1148,43 +1631,50 @@
         migrations.AddField(
             model_name='sliceprivilege',
             name='role',
-            field=models.ForeignKey(related_name=b'sliceprivileges', to='core.SliceRole'),
+            field=models.ForeignKey(
+                related_name=b'sliceprivileges', to='core.SliceRole'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='sliceprivilege',
             name='slice',
-            field=models.ForeignKey(related_name=b'sliceprivileges', to='core.Slice'),
+            field=models.ForeignKey(
+                related_name=b'sliceprivileges', to='core.Slice'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='sliceprivilege',
             name='user',
-            field=models.ForeignKey(related_name=b'sliceprivileges', to=settings.AUTH_USER_MODEL),
+            field=models.ForeignKey(
+                related_name=b'sliceprivileges', to=settings.AUTH_USER_MODEL),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='siteprivilege',
             name='role',
-            field=models.ForeignKey(related_name=b'siteprivileges', to='core.SiteRole'),
+            field=models.ForeignKey(
+                related_name=b'siteprivileges', to='core.SiteRole'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='siteprivilege',
             name='site',
-            field=models.ForeignKey(related_name=b'siteprivileges', to='core.Site'),
+            field=models.ForeignKey(
+                related_name=b'siteprivileges', to='core.Site'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='siteprivilege',
             name='user',
-            field=models.ForeignKey(related_name=b'siteprivileges', to=settings.AUTH_USER_MODEL),
+            field=models.ForeignKey(
+                related_name=b'siteprivileges', to=settings.AUTH_USER_MODEL),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='site',
             name='deployments',
-            field=models.ManyToManyField(help_text=b'Select which sites are allowed to host nodes in this deployment', related_name=b'sites', through='core.SiteDeployment', to='core.Deployment', blank=True),
+            field=models.ManyToManyField(help_text=b'Select which sites are allowed to host nodes in this deployment',
+                                         related_name=b'sites', through='core.SiteDeployment', to='core.Deployment', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
@@ -1196,25 +1686,29 @@
         migrations.AddField(
             model_name='router',
             name='permittedNetworks',
-            field=models.ManyToManyField(related_name=b'availableRouters', to='core.Network', blank=True),
+            field=models.ManyToManyField(
+                related_name=b'availableRouters', to='core.Network', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='reservedresource',
             name='resource',
-            field=models.ForeignKey(related_name=b'reservedresources', to='core.ServiceResource'),
+            field=models.ForeignKey(
+                related_name=b'reservedresources', to='core.ServiceResource'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='reservedresource',
             name='instance',
-            field=models.ForeignKey(related_name=b'reservedresources', to='core.Instance'),
+            field=models.ForeignKey(
+                related_name=b'reservedresources', to='core.Instance'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='reservation',
             name='slice',
-            field=models.ForeignKey(related_name=b'reservations', to='core.Slice'),
+            field=models.ForeignKey(
+                related_name=b'reservations', to='core.Slice'),
             preserve_default=True,
         ),
         migrations.AddField(
@@ -1226,61 +1720,71 @@
         migrations.AddField(
             model_name='planetstackprivilege',
             name='user',
-            field=models.ForeignKey(related_name=b'planetstackprivileges', to=settings.AUTH_USER_MODEL),
+            field=models.ForeignKey(
+                related_name=b'planetstackprivileges', to=settings.AUTH_USER_MODEL),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='node',
             name='site',
-            field=models.ForeignKey(related_name=b'nodes', blank=True, to='core.Site', null=True),
+            field=models.ForeignKey(
+                related_name=b'nodes', blank=True, to='core.Site', null=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='node',
             name='site_deployment',
-            field=models.ForeignKey(related_name=b'nodes', to='core.SiteDeployment'),
+            field=models.ForeignKey(
+                related_name=b'nodes', to='core.SiteDeployment'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='networkinstance',
             name='instance',
-            field=models.ForeignKey(related_name=b'networkinstances', to='core.Instance'),
+            field=models.ForeignKey(
+                related_name=b'networkinstances', to='core.Instance'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='networkslice',
             name='slice',
-            field=models.ForeignKey(related_name=b'networkslices', to='core.Slice'),
+            field=models.ForeignKey(
+                related_name=b'networkslices', to='core.Slice'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='networkparameter',
             name='parameter',
-            field=models.ForeignKey(related_name=b'networkparameters', to='core.NetworkParameterType', help_text=b'The type of the parameter'),
+            field=models.ForeignKey(related_name=b'networkparameters',
+                                    to='core.NetworkParameterType', help_text=b'The type of the parameter'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='network',
             name='owner',
-            field=models.ForeignKey(related_name=b'ownedNetworks', to='core.Slice', help_text=b'Slice that owns control of this Network'),
+            field=models.ForeignKey(related_name=b'ownedNetworks', to='core.Slice',
+                                    help_text=b'Slice that owns control of this Network'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='network',
             name='permitted_slices',
-            field=models.ManyToManyField(related_name=b'availableNetworks', to='core.Slice', blank=True),
+            field=models.ManyToManyField(
+                related_name=b'availableNetworks', to='core.Slice', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='network',
             name='slices',
-            field=models.ManyToManyField(related_name=b'networks', through='core.NetworkSlice', to='core.Slice', blank=True),
+            field=models.ManyToManyField(
+                related_name=b'networks', through='core.NetworkSlice', to='core.Slice', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='network',
             name='instances',
-            field=models.ManyToManyField(related_name=b'networks', through='core.NetworkInstance', to='core.Instance', blank=True),
+            field=models.ManyToManyField(
+                related_name=b'networks', through='core.NetworkInstance', to='core.Instance', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
@@ -1292,67 +1796,78 @@
         migrations.AddField(
             model_name='image',
             name='deployments',
-            field=models.ManyToManyField(help_text=b'Select which images should be instantiated on this deployment', related_name=b'images', through='core.ImageDeployments', to='core.Deployment', blank=True),
+            field=models.ManyToManyField(help_text=b'Select which images should be instantiated on this deployment',
+                                         related_name=b'images', through='core.ImageDeployments', to='core.Deployment', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='deploymentprivilege',
             name='role',
-            field=models.ForeignKey(related_name=b'deploymentprivileges', to='core.DeploymentRole'),
+            field=models.ForeignKey(
+                related_name=b'deploymentprivileges', to='core.DeploymentRole'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='deploymentprivilege',
             name='user',
-            field=models.ForeignKey(related_name=b'deploymentprivileges', to=settings.AUTH_USER_MODEL),
+            field=models.ForeignKey(
+                related_name=b'deploymentprivileges', to=settings.AUTH_USER_MODEL),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllersliceprivilege',
             name='slice_privilege',
-            field=models.ForeignKey(related_name=b'controllersliceprivileges', to='core.SlicePrivilege'),
+            field=models.ForeignKey(
+                related_name=b'controllersliceprivileges', to='core.SlicePrivilege'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllerslice',
             name='slice',
-            field=models.ForeignKey(related_name=b'controllerslices', to='core.Slice'),
+            field=models.ForeignKey(
+                related_name=b'controllerslices', to='core.Slice'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllersiteprivilege',
             name='site_privilege',
-            field=models.ForeignKey(related_name=b'controllersiteprivileges', to='core.SitePrivilege'),
+            field=models.ForeignKey(
+                related_name=b'controllersiteprivileges', to='core.SitePrivilege'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllersite',
             name='site',
-            field=models.ForeignKey(related_name=b'controllersite', to='core.Site'),
+            field=models.ForeignKey(
+                related_name=b'controllersite', to='core.Site'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllernetwork',
             name='network',
-            field=models.ForeignKey(related_name=b'controllernetworks', to='core.Network'),
+            field=models.ForeignKey(
+                related_name=b'controllernetworks', to='core.Network'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllerimages',
             name='image',
-            field=models.ForeignKey(related_name=b'controllerimages', to='core.Image'),
+            field=models.ForeignKey(
+                related_name=b'controllerimages', to='core.Image'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='controllerdashboardview',
             name='dashboardView',
-            field=models.ForeignKey(related_name=b'controllerdashboardviews', to='core.DashboardView'),
+            field=models.ForeignKey(
+                related_name=b'controllerdashboardviews', to='core.DashboardView'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='charge',
             name='invoice',
-            field=models.ForeignKey(related_name=b'charges', blank=True, to='core.Invoice', null=True),
+            field=models.ForeignKey(
+                related_name=b'charges', blank=True, to='core.Invoice', null=True),
             preserve_default=True,
         ),
         migrations.AddField(
@@ -1364,25 +1879,29 @@
         migrations.AddField(
             model_name='charge',
             name='slice',
-            field=models.ForeignKey(related_name=b'charges', blank=True, to='core.Slice', null=True),
+            field=models.ForeignKey(
+                related_name=b'charges', blank=True, to='core.Slice', null=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='account',
             name='site',
-            field=models.ForeignKey(related_name=b'accounts', to='core.Site', help_text=b'Site for this account'),
+            field=models.ForeignKey(
+                related_name=b'accounts', to='core.Site', help_text=b'Site for this account'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='user',
             name='dashboards',
-            field=models.ManyToManyField(to='core.DashboardView', through='core.UserDashboardView', blank=True),
+            field=models.ManyToManyField(
+                to='core.DashboardView', through='core.UserDashboardView', blank=True),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='user',
             name='site',
-            field=models.ForeignKey(related_name=b'users', to='core.Site', help_text=b'Site this user will be homed too', null=True),
+            field=models.ForeignKey(related_name=b'users', to='core.Site',
+                                    help_text=b'Site this user will be homed too', null=True),
             preserve_default=True,
         ),
     ]
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 920bc3b..641c5ae 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -1,14 +1,18 @@
-from django.db import models
-from core.models import PlCoreBase,SingletonModel,PlCoreBaseManager
-from core.models.plcorebase import StrippedCharField
-from xos.exceptions import *
-from operator import attrgetter
 import json
+from operator import attrgetter
 
-COARSE_KIND="coarse"
+from core.models import PlCoreBase, PlCoreBaseManager, SingletonModel
+from core.models.plcorebase import StrippedCharField
+from django.db import models
+from xos.exceptions import *
+
+COARSE_KIND = "coarse"
+
 
 class AttributeMixin(object):
-    # helper for extracting things from a json-encoded service_specific_attribute
+    # helper for extracting things from a json-encoded
+    # service_specific_attribute
+
     def get_attribute(self, name, default=None):
         if self.service_specific_attribute:
             attributes = json.loads(self.service_specific_attribute)
@@ -21,12 +25,13 @@
             attributes = json.loads(self.service_specific_attribute)
         else:
             attributes = {}
-        attributes[name]=value
+        attributes[name] = value
         self.service_specific_attribute = json.dumps(attributes)
 
     def get_initial_attribute(self, name, default=None):
         if self._initial["service_specific_attribute"]:
-            attributes = json.loads(self._initial["service_specific_attribute"])
+            attributes = json.loads(
+                self._initial["service_specific_attribute"])
         else:
             attributes = {}
         return attributes.get(name, default)
@@ -34,9 +39,9 @@
     @classmethod
     def get_default_attribute(cls, name):
         for (attrname, default) in cls.simple_attributes:
-            if attrname==name:
+            if attrname == name:
                 return default
-        if hasattr(cls,"default_attributes"):
+        if hasattr(cls, "default_attributes"):
             if name in cls.default_attributes:
                 return cls.default_attributes[name]
 
@@ -46,27 +51,34 @@
     def setup_simple_attributes(cls):
         for (attrname, default) in cls.simple_attributes:
             setattr(cls, attrname, property(lambda self, attrname=attrname, default=default: self.get_attribute(attrname, default),
-                                            lambda self, value, attrname=attrname: self.set_attribute(attrname, value),
+                                            lambda self, value, attrname=attrname: self.set_attribute(
+                                                attrname, value),
                                             None,
                                             attrname))
 
+
 class Service(PlCoreBase, AttributeMixin):
     # when subclassing a service, redefine KIND to describe the new service
     KIND = "generic"
 
-    description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Service")
+    description = models.TextField(
+        max_length=254, null=True, blank=True, help_text="Description of Service")
     enabled = models.BooleanField(default=True)
-    kind = StrippedCharField(max_length=30, help_text="Kind of service", default=KIND)
+    kind = StrippedCharField(
+        max_length=30, help_text="Kind of service", default=KIND)
     name = StrippedCharField(max_length=30, help_text="Service Name")
-    versionNumber = StrippedCharField(max_length=30, help_text="Version of Service Definition")
+    versionNumber = StrippedCharField(
+        max_length=30, help_text="Version of Service Definition")
     published = models.BooleanField(default=True)
     view_url = StrippedCharField(blank=True, null=True, max_length=1024)
     icon_url = StrippedCharField(blank=True, null=True, max_length=1024)
-    public_key = models.TextField(null=True, blank=True, max_length=1024, help_text="Public key string")
+    public_key = models.TextField(
+        null=True, blank=True, max_length=1024, help_text="Public key string")
     private_key_fn = StrippedCharField(blank=True, null=True, max_length=1024)
 
     # Service_specific_attribute and service_specific_id are opaque to XOS
-    service_specific_id = StrippedCharField(max_length=30, blank=True, null=True)
+    service_specific_id = StrippedCharField(
+        max_length=30, blank=True, null=True)
     service_specific_attribute = models.TextField(blank=True, null=True)
 
     def __init__(self, *args, **kwargs):
@@ -76,22 +88,23 @@
 
     @classmethod
     def get_service_objects(cls):
-        return cls.objects.filter(kind = cls.KIND)
+        return cls.objects.filter(kind=cls.KIND)
 
     @classmethod
     def get_deleted_service_objects(cls):
-        return cls.deleted_objects.filter(kind = cls.KIND)
+        return cls.deleted_objects.filter(kind=cls.KIND)
 
     @classmethod
     def get_service_objects_by_user(cls, user):
-        return cls.select_by_user(user).filter(kind = cls.KIND)
+        return cls.select_by_user(user).filter(kind=cls.KIND)
 
     @classmethod
     def select_by_user(cls, user):
         if user.is_admin:
             return cls.objects.all()
         else:
-            service_ids = [sp.slice.id for sp in ServicePrivilege.objects.filter(user=user)]
+            service_ids = [
+                sp.slice.id for sp in ServicePrivilege.objects.filter(user=user)]
             return cls.objects.filter(id__in=service_ids)
 
     @property
@@ -115,12 +128,15 @@
                 exclusive_slices - list of slices that must have no nodes in common with 'slice'.
         """
 
-        from core.models import Node, Instance # late import to get around order-of-imports constraint in __init__.py
+        # late import to get around order-of-imports constraint in __init__.py
+        from core.models import Node, Instance
 
         nodes = list(Node.objects.all())
 
-        conflicting_instances = Instance.objects.filter(slice__in = exclusive_slices)
-        conflicting_nodes = Node.objects.filter(instances__in = conflicting_instances)
+        conflicting_instances = Instance.objects.filter(
+            slice__in=exclusive_slices)
+        conflicting_nodes = Node.objects.filter(
+            instances__in=conflicting_instances)
 
         nodes = [x for x in nodes if x not in conflicting_nodes]
 
@@ -146,7 +162,8 @@
         return nodes[0]
 
     def adjust_scale(self, slice_hint, scale, max_per_node=None, exclusive_slices=[]):
-        from core.models import Instance # late import to get around order-of-imports constraint in __init__.py
+        # late import to get around order-of-imports constraint in __init__.py
+        from core.models import Instance
 
         slices = [x for x in self.slices.all() if slice_hint in x.name]
         for slice in slices:
@@ -163,24 +180,26 @@
 
                 image = slice.default_image
                 if not image:
-                    raise XOSConfigurationError("No default_image for slice %s" % slice.name)
+                    raise XOSConfigurationError(
+                        "No default_image for slice %s" % slice.name)
 
                 flavor = slice.default_flavor
                 if not flavor:
-                    raise XOSConfigurationError("No default_flavor for slice %s" % slice.name)
+                    raise XOSConfigurationError(
+                        "No default_flavor for slice %s" % slice.name)
 
                 s = Instance(slice=slice,
-                           node=node,
-                           creator=slice.creator,
-                           image=image,
-                           flavor=flavor,
-                           deployment=node.site_deployment.deployment)
+                             node=node,
+                             creator=slice.creator,
+                             image=image,
+                             flavor=flavor,
+                             deployment=node.site_deployment.deployment)
                 s.save()
 
                 # print "add instance", s
 
     def get_vtn_src_nets(self):
-        nets=[]
+        nets = []
         for slice in self.slices.all():
             for ns in slice.networkslices.all():
                 if not ns.network:
@@ -203,7 +222,7 @@
         return nets
 
     def get_vtn_nets(self):
-        nets=[]
+        nets = []
         for slice in self.slices.all():
             for ns in slice.networkslices.all():
                 if not ns.network:
@@ -230,35 +249,39 @@
         return [x["net_id"] for x in self.get_vtn_dependencies_nets()]
 
     def get_vtn_dependencies_names(self):
-        return [x["name"]+"_"+x["net_id"] for x in self.get_vtn_dependencies_nets()]
+        return [x["name"] + "_" + x["net_id"] for x in self.get_vtn_dependencies_nets()]
 
     def get_vtn_src_ids(self):
         return [x["net_id"] for x in self.get_vtn_src_nets()]
 
     def get_vtn_src_names(self):
-        return [x["name"]+"_"+x["net_id"] for x in self.get_vtn_src_nets()]
+        return [x["name"] + "_" + x["net_id"] for x in self.get_vtn_src_nets()]
 
 
 class ServiceAttribute(PlCoreBase):
     name = models.CharField(help_text="Attribute Name", max_length=128)
     value = StrippedCharField(help_text="Attribute Value", max_length=1024)
-    service = models.ForeignKey(Service, related_name='serviceattributes', help_text="The Service this attribute is associated with")
+    service = models.ForeignKey(Service, related_name='serviceattributes',
+                                help_text="The Service this attribute is associated with")
+
 
 class ServiceRole(PlCoreBase):
-    ROLE_CHOICES = (('admin','Admin'),)
+    ROLE_CHOICES = (('admin', 'Admin'),)
     role = StrippedCharField(choices=ROLE_CHOICES, unique=True, max_length=30)
 
-    def __unicode__(self):  return u'%s' % (self.role)
+    def __unicode__(self): return u'%s' % (self.role)
+
 
 class ServicePrivilege(PlCoreBase):
     user = models.ForeignKey('User', related_name='serviceprivileges')
     service = models.ForeignKey('Service', related_name='serviceprivileges')
-    role = models.ForeignKey('ServiceRole',related_name='serviceprivileges')
+    role = models.ForeignKey('ServiceRole', related_name='serviceprivileges')
 
     class Meta:
-        unique_together =  ('user', 'service', 'role')
+        unique_together = ('user', 'service', 'role')
 
-    def __unicode__(self):  return u'%s %s %s' % (self.service, self.user, self.role)
+    def __unicode__(self): return u'%s %s %s' % (
+        self.service, self.user, self.role)
 
     def can_update(self, user):
         if not self.service.enabled:
@@ -283,17 +306,20 @@
             qs = cls.objects.filter(user=user)
         return qs
 
+
 class TenantRoot(PlCoreBase, AttributeMixin):
     """ A tenantRoot is one of the things that can sit at the root of a chain
         of tenancy. This object represents a node.
     """
 
-    KIND= "generic"
+    KIND = "generic"
     kind = StrippedCharField(max_length=30, default=KIND)
-    name = StrippedCharField(max_length=255, help_text="name", blank=True, null=True)
+    name = StrippedCharField(
+        max_length=255, help_text="name", blank=True, null=True)
 
     service_specific_attribute = models.TextField(blank=True, null=True)
-    service_specific_id = StrippedCharField(max_length=30, blank=True, null=True)
+    service_specific_id = StrippedCharField(
+        max_length=30, blank=True, null=True)
 
     def __init__(self, *args, **kwargs):
         # for subclasses, set the default kind appropriately
@@ -311,7 +337,7 @@
 
     def get_subscribed_tenants(self, tenant_class):
         ids = self.subscribed_tenants.filter(kind=tenant_class.KIND)
-        return tenant_class.objects.filter(id__in = ids)
+        return tenant_class.objects.filter(id__in=ids)
 
     def get_newest_subscribed_tenant(self, kind):
         st = list(self.get_subscribed_tenants(kind))
@@ -321,31 +347,37 @@
 
     @classmethod
     def get_tenant_objects(cls):
-        return cls.objects.filter(kind = cls.KIND)
+        return cls.objects.filter(kind=cls.KIND)
 
     @classmethod
     def get_tenant_objects_by_user(cls, user):
-        return cls.select_by_user(user).filter(kind = cls.KIND)
+        return cls.select_by_user(user).filter(kind=cls.KIND)
 
     @classmethod
     def select_by_user(cls, user):
         if user.is_admin:
             return cls.objects.all()
         else:
-            tr_ids = [trp.tenant_root.id for trp in TenantRootPrivilege.objects.filter(user=user)]
+            tr_ids = [
+                trp.tenant_root.id for trp in TenantRootPrivilege.objects.filter(user=user)]
             return cls.objects.filter(id__in=tr_ids)
 
-    # helper function to be used in subclasses that want to ensure service_specific_id is unique
+    # helper function to be used in subclasses that want to ensure
+    # service_specific_id is unique
     def validate_unique_service_specific_id(self, none_okay=False):
         if not none_okay and (self.service_specific_id is None):
-            raise XOSMissingField("subscriber_specific_id is None, and it's a required field", fields={"service_specific_id": "cannot be none"})
+            raise XOSMissingField("subscriber_specific_id is None, and it's a required field", fields={
+                                  "service_specific_id": "cannot be none"})
 
         if self.service_specific_id:
-            conflicts = self.get_tenant_objects().filter(service_specific_id=self.service_specific_id)
+            conflicts = self.get_tenant_objects().filter(
+                service_specific_id=self.service_specific_id)
             if self.pk:
                 conflicts = conflicts.exclude(pk=self.pk)
             if conflicts:
-                raise XOSDuplicateKey("service_specific_id %s already exists" % self.service_specific_id, fields={"service_specific_id": "duplicate key"})
+                raise XOSDuplicateKey("service_specific_id %s already exists" % self.service_specific_id, fields={
+                                      "service_specific_id": "duplicate key"})
+
 
 class Tenant(PlCoreBase, AttributeMixin):
     """ A tenant is a relationship between two entities, a subscriber and a
@@ -358,29 +390,38 @@
         TODO: rename "Tenant" to "Tenancy"
     """
 
-    CONNECTIVITY_CHOICES = (('public', 'Public'), ('private', 'Private'), ('na', 'Not Applicable'))
+    CONNECTIVITY_CHOICES = (('public', 'Public'),
+                            ('private', 'Private'), ('na', 'Not Applicable'))
 
     # when subclassing a service, redefine KIND to describe the new service
     KIND = "generic"
 
     kind = StrippedCharField(max_length=30, default=KIND)
-    provider_service = models.ForeignKey(Service, related_name='provided_tenants')
+    provider_service = models.ForeignKey(
+        Service, related_name='provided_tenants')
 
     # The next four things are the various type of objects that can be subscribers of this Tenancy
     # relationship. One and only one can be used at a time.
     # XXX these should really be changed to GenericForeignKey
-    subscriber_service = models.ForeignKey(Service, related_name='subscribed_tenants', blank=True, null=True)
-    subscriber_tenant = models.ForeignKey("Tenant", related_name='subscribed_tenants', blank=True, null=True)
-    subscriber_user = models.ForeignKey("User", related_name='subscribed_tenants', blank=True, null=True)
-    subscriber_root = models.ForeignKey("TenantRoot", related_name="subscribed_tenants", blank=True, null=True)
-    subscriber_network = models.ForeignKey("Network", related_name="subscribed_tenants", blank=True, null=True)
+    subscriber_service = models.ForeignKey(
+        Service, related_name='subscribed_tenants', blank=True, null=True)
+    subscriber_tenant = models.ForeignKey(
+        "Tenant", related_name='subscribed_tenants', blank=True, null=True)
+    subscriber_user = models.ForeignKey(
+        "User", related_name='subscribed_tenants', blank=True, null=True)
+    subscriber_root = models.ForeignKey(
+        "TenantRoot", related_name="subscribed_tenants", blank=True, null=True)
+    subscriber_network = models.ForeignKey(
+        "Network", related_name="subscribed_tenants", blank=True, null=True)
 
     # Service_specific_attribute and service_specific_id are opaque to XOS
-    service_specific_id = StrippedCharField(max_length=30, blank=True, null=True)
+    service_specific_id = StrippedCharField(
+        max_length=30, blank=True, null=True)
     service_specific_attribute = models.TextField(blank=True, null=True)
 
     # Connect_method is only used by Coarse tenants
-    connect_method = models.CharField(null=False, blank=False, max_length=30, choices=CONNECTIVITY_CHOICES, default="na")
+    connect_method = models.CharField(
+        null=False, blank=False, max_length=30, choices=CONNECTIVITY_CHOICES, default="na")
 
     def __init__(self, *args, **kwargs):
         # for subclasses, set the default kind appropriately
@@ -392,15 +433,15 @@
 
     @classmethod
     def get_tenant_objects(cls):
-        return cls.objects.filter(kind = cls.KIND)
+        return cls.objects.filter(kind=cls.KIND)
 
     @classmethod
     def get_tenant_objects_by_user(cls, user):
-        return cls.select_by_user(user).filter(kind = cls.KIND)
+        return cls.select_by_user(user).filter(kind=cls.KIND)
 
     @classmethod
     def get_deleted_tenant_objects(cls):
-        return cls.deleted_objects.filter(kind = cls.KIND)
+        return cls.deleted_objects.filter(kind=cls.KIND)
 
     @property
     def tenantattribute_dict(self):
@@ -409,26 +450,32 @@
             attrs[attr.name] = attr.value
         return attrs
 
-    # helper function to be used in subclasses that want to ensure service_specific_id is unique
+    # helper function to be used in subclasses that want to ensure
+    # service_specific_id is unique
     def validate_unique_service_specific_id(self):
         if self.pk is None:
             if self.service_specific_id is None:
-                raise XOSMissingField("subscriber_specific_id is None, and it's a required field", fields={"service_specific_id": "cannot be none"})
+                raise XOSMissingField("subscriber_specific_id is None, and it's a required field", fields={
+                                      "service_specific_id": "cannot be none"})
 
-            conflicts = self.get_tenant_objects().filter(service_specific_id=self.service_specific_id)
+            conflicts = self.get_tenant_objects().filter(
+                service_specific_id=self.service_specific_id)
             if conflicts:
-                raise XOSDuplicateKey("service_specific_id %s already exists" % self.service_specific_id, fields={"service_specific_id": "duplicate key"})
+                raise XOSDuplicateKey("service_specific_id %s already exists" % self.service_specific_id, fields={
+                                      "service_specific_id": "duplicate key"})
 
     def save(self, *args, **kwargs):
-        subCount = sum( [1 for e in [self.subscriber_service, self.subscriber_tenant, self.subscriber_user, self.subscriber_root] if e is not None])
+        subCount = sum([1 for e in [self.subscriber_service, self.subscriber_tenant,
+                                    self.subscriber_user, self.subscriber_root] if e is not None])
         if (subCount > 1):
-            raise XOSConflictingField("Only one of subscriber_service, subscriber_tenant, subscriber_user, subscriber_root should be set")
+            raise XOSConflictingField(
+                "Only one of subscriber_service, subscriber_tenant, subscriber_user, subscriber_root should be set")
 
         super(Tenant, self).save(*args, **kwargs)
 
     def get_subscribed_tenants(self, tenant_class):
         ids = self.subscribed_tenants.filter(kind=tenant_class.KIND)
-        return tenant_class.objects.filter(id__in = ids)
+        return tenant_class.objects.filter(id__in=ids)
 
     def get_newest_subscribed_tenant(self, kind):
         st = list(self.get_subscribed_tenants(kind))
@@ -436,6 +483,7 @@
             return None
         return sorted(st, key=attrgetter('id'))[0]
 
+
 class Scheduler(object):
     # XOS Scheduler Abstract Base Class
     # Used to implement schedulers that pick which node to put instances on
@@ -451,8 +499,10 @@
 
         raise Exception("Abstract Base")
 
+
 class LeastLoadedNodeScheduler(Scheduler):
-    # This scheduler always return the node with the fewest number of instances.
+    # This scheduler always return the node with the fewest number of
+    # instances.
 
     def __init__(self, slice, label=None):
         super(LeastLoadedNodeScheduler, self).__init__(slice)
@@ -463,28 +513,30 @@
         nodes = Node.objects.all()
 
         if self.label:
-           nodes = nodes.filter(nodelabels__name=self.label)
+            nodes = nodes.filter(nodelabels__name=self.label)
 
         nodes = list(nodes)
 
         if not nodes:
-            raise Exception("LeastLoadedNodeScheduler: No suitable nodes to pick from")
+            raise Exception(
+                "LeastLoadedNodeScheduler: No suitable nodes to pick from")
 
         # TODO: logic to filter nodes by which nodes are up, and which
         #   nodes the slice can instantiate on.
         nodes = sorted(nodes, key=lambda node: node.instances.all().count())
         return [nodes[0], None]
 
+
 class ContainerVmScheduler(Scheduler):
     # This scheduler picks a VM in the slice with the fewest containers inside
     # of it. If no VMs are suitable, then it creates a VM.
 
     # this is a hack and should be replaced by something smarter...
-    LOOK_FOR_IMAGES=["ubuntu-vcpe4",        # ONOS demo machine -- preferred vcpe image
-                     "Ubuntu 14.04 LTS",    # portal
-                     "Ubuntu-14.04-LTS",    # ONOS demo machine
-                     "trusty-server-multi-nic", # CloudLab
-                    ]
+    LOOK_FOR_IMAGES = ["ubuntu-vcpe4",        # ONOS demo machine -- preferred vcpe image
+                       "Ubuntu 14.04 LTS",    # portal
+                       "Ubuntu-14.04-LTS",    # ONOS demo machine
+                       "trusty-server-multi-nic",  # CloudLab
+                       ]
 
     MAX_VM_PER_CONTAINER = 10
 
@@ -497,11 +549,12 @@
 
         look_for_images = self.LOOK_FOR_IMAGES
         for image_name in look_for_images:
-            images = Image.objects.filter(name = image_name)
+            images = Image.objects.filter(name=image_name)
             if images:
                 return images[0]
 
-        raise XOSProgrammingError("No ContainerVM image (looked for %s)" % str(look_for_images))
+        raise XOSProgrammingError(
+            "No ContainerVM image (looked for %s)" % str(look_for_images))
 
     def make_new_instance(self):
         from core.models import Instance, Flavor
@@ -510,16 +563,16 @@
         if not flavors:
             raise XOSConfigurationError("No m1.small flavor")
 
-        (node,parent) = LeastLoadedNodeScheduler(self.slice).pick()
+        (node, parent) = LeastLoadedNodeScheduler(self.slice).pick()
 
-        instance = Instance(slice = self.slice,
-                        node = node,
-                        image = self.image,
-                        creator = self.slice.creator,
-                        deployment = node.site_deployment.deployment,
-                        flavor = flavors[0],
-                        isolation = "vm",
-                        parent = parent)
+        instance = Instance(slice=self.slice,
+                            node=node,
+                            image=self.image,
+                            creator=self.slice.creator,
+                            deployment=node.site_deployment.deployment,
+                            flavor=flavors[0],
+                            isolation="vm",
+                            parent=parent)
         instance.save()
         # We rely on a special naming convention to identify the VMs that will
         # hole containers.
@@ -535,9 +588,9 @@
             if (vm.name.startswith("%s-outer-" % self.slice.name)):
                 container_count = Instance.objects.filter(parent=vm).count()
                 if (container_count < self.MAX_VM_PER_CONTAINER):
-                    avail_vms.append( (vm, container_count) )
+                    avail_vms.append((vm, container_count))
             # sort by least containers-per-vm
-            avail_vms = sorted(avail_vms, key = lambda x: x[1])
+            avail_vms = sorted(avail_vms, key=lambda x: x[1])
             print "XXX", avail_vms
             if avail_vms:
                 instance = avail_vms[0][0]
@@ -546,24 +599,25 @@
         instance = self.make_new_instance()
         return (instance.node, instance)
 
+
 class TenantWithContainer(Tenant):
     """ A tenant that manages a container """
 
     # this is a hack and should be replaced by something smarter...
-    LOOK_FOR_IMAGES=["ubuntu-vcpe4",        # ONOS demo machine -- preferred vcpe image
-                     "Ubuntu 14.04 LTS",    # portal
-                     "Ubuntu-14.04-LTS",    # ONOS demo machine
-                     "trusty-server-multi-nic", # CloudLab
-                    ]
+    LOOK_FOR_IMAGES = ["ubuntu-vcpe4",        # ONOS demo machine -- preferred vcpe image
+                       "Ubuntu 14.04 LTS",    # portal
+                       "Ubuntu-14.04-LTS",    # ONOS demo machine
+                       "trusty-server-multi-nic",  # CloudLab
+                       ]
 
-    LOOK_FOR_CONTAINER_IMAGES=["docker-vcpe"]
+    LOOK_FOR_CONTAINER_IMAGES = ["docker-vcpe"]
 
     class Meta:
         proxy = True
 
     def __init__(self, *args, **kwargs):
         super(TenantWithContainer, self).__init__(*args, **kwargs)
-        self.cached_instance=None
+        self.cached_instance = None
         self.orig_instance_id = self.get_initial_attribute("instance_id")
 
     @property
@@ -571,13 +625,13 @@
         from core.models import Instance
         if getattr(self, "cached_instance", None):
             return self.cached_instance
-        instance_id=self.get_attribute("instance_id")
+        instance_id = self.get_attribute("instance_id")
         if not instance_id:
             return None
-        instances=Instance.objects.filter(id=instance_id)
+        instances = Instance.objects.filter(id=instance_id)
         if not instances:
             return None
-        instance=instances[0]
+        instance = instances[0]
         instance.caller = self.creator
         self.cached_instance = instance
         return instance
@@ -587,7 +641,7 @@
         if value:
             value = value.id
         if (value != self.get_attribute("instance_id", None)):
-            self.cached_instance=None
+            self.cached_instance = None
         self.set_attribute("instance_id", value)
 
     @property
@@ -611,13 +665,13 @@
         from core.models import User
         if getattr(self, "cached_creator", None):
             return self.cached_creator
-        creator_id=self.get_attribute("creator_id")
+        creator_id = self.get_attribute("creator_id")
         if not creator_id:
             return None
-        users=User.objects.filter(id=creator_id)
+        users = User.objects.filter(id=creator_id)
         if not users:
             return None
-        user=users[0]
+        user = users[0]
         self.cached_creator = users[0]
         return user
 
@@ -626,7 +680,7 @@
         if value:
             value = value.id
         if (value != self.get_attribute("creator_id", None)):
-            self.cached_creator=None
+            self.cached_creator = None
         self.set_attribute("creator_id", value)
 
     @property
@@ -646,11 +700,12 @@
             look_for_images = self.LOOK_FOR_IMAGES
 
         for image_name in look_for_images:
-            images = Image.objects.filter(name = image_name)
+            images = Image.objects.filter(name=image_name)
             if images:
                 return images[0]
 
-        raise XOSProgrammingError("No VPCE image (looked for %s)" % str(look_for_images))
+        raise XOSProgrammingError(
+            "No VPCE image (looked for %s)" % str(look_for_images))
 
     def save_instance(self, instance):
         # Override this function to do custom pre-save or post-save processing,
@@ -661,14 +716,14 @@
         for slice in slices:
             if slice.instances.all().count() > 0:
                 for instance in slice.instances.all():
-                     #Pick the first instance that has lesser than 5 tenants 
-                     if self.count_of_tenants_of_an_instance(instance) < 5:
-                         return instance
+                    # Pick the first instance that has lesser than 5 tenants
+                    if self.count_of_tenants_of_an_instance(instance) < 5:
+                        return instance
         return None
 
-    #TODO: Ideally the tenant count for an instance should be maintained using a 
-    #many-to-one relationship attribute, however this model being proxy, it does 
-    #not permit any new attributes to be defined. Find if any better solutions 
+    # TODO: Ideally the tenant count for an instance should be maintained using a
+    # many-to-one relationship attribute, however this model being proxy, it does
+    # not permit any new attributes to be defined. Find if any better solutions
     def count_of_tenants_of_an_instance(self, instance):
         tenant_count = 0
         for tenant in self.get_tenant_objects().all():
@@ -693,7 +748,7 @@
             new_instance_created = False
             instance = None
             if self.get_attribute("use_same_instance_for_multiple_tenants", default=False):
-                #Find if any existing instances can be used for this tenant
+                # Find if any existing instances can be used for this tenant
                 slices = self.provider_service.slices.all()
                 instance = self.pick_least_loaded_instance_in_slice(slices)
 
@@ -712,14 +767,14 @@
                 else:
                     (node, parent) = LeastLoadedNodeScheduler(slice).pick()
 
-                instance = Instance(slice = slice,
-                                node = node,
-                                image = self.image,
-                                creator = self.creator,
-                                deployment = node.site_deployment.deployment,
-                                flavor = flavor,
-                                isolation = slice.default_isolation,
-                                parent = parent)
+                instance = Instance(slice=slice,
+                                    node=node,
+                                    image=self.image,
+                                    creator=self.creator,
+                                    deployment=node.site_deployment.deployment,
+                                    flavor=flavor,
+                                    isolation=slice.default_isolation,
+                                    parent=parent)
                 self.save_instance(instance)
                 new_instance_created = True
 
@@ -734,8 +789,10 @@
     def cleanup_container(self):
         if self.instance:
             if self.get_attribute("use_same_instance_for_multiple_tenants", default=False):
-                #Delete the instance only if this is last tenant in that instance
-                tenant_count = self.count_of_tenants_of_an_instance(self.instance)
+                # Delete the instance only if this is last tenant in that
+                # instance
+                tenant_count = self.count_of_tenants_of_an_instance(
+                    self.instance)
                 if tenant_count == 0:
                     self.instance.delete()
             else:
@@ -747,6 +804,7 @@
             self.creator = self.caller
         super(TenantWithContainer, self).save(*args, **kwargs)
 
+
 class CoarseTenant(Tenant):
     """ TODO: rename "CoarseTenant" --> "StaticTenant" """
     class Meta:
@@ -758,9 +816,11 @@
         if (not self.subscriber_service):
             raise XOSValidationError("subscriber_service cannot be null")
         if (self.subscriber_tenant or self.subscriber_user):
-            raise XOSValidationError("subscriber_tenant and subscriber_user must be null")
+            raise XOSValidationError(
+                "subscriber_tenant and subscriber_user must be null")
 
-        super(CoarseTenant,self).save()
+        super(CoarseTenant, self).save()
+
 
 class Subscriber(TenantRoot):
     """ Intermediate class for TenantRoots that are to be Subscribers """
@@ -770,6 +830,7 @@
 
     KIND = "Subscriber"
 
+
 class Provider(TenantRoot):
     """ Intermediate class for TenantRoots that are to be Providers """
 
@@ -778,29 +839,36 @@
 
     KIND = "Provider"
 
+
 class TenantAttribute(PlCoreBase):
     name = models.CharField(help_text="Attribute Name", max_length=128)
     value = models.TextField(help_text="Attribute Value")
-    tenant = models.ForeignKey(Tenant, related_name='tenantattributes', help_text="The Tenant this attribute is associated with")
+    tenant = models.ForeignKey(Tenant, related_name='tenantattributes',
+                               help_text="The Tenant this attribute is associated with")
 
     def __unicode__(self): return u'%s-%s' % (self.name, self.id)
 
+
 class TenantRootRole(PlCoreBase):
-    ROLE_CHOICES = (('admin','Admin'), ('access','Access'))
+    ROLE_CHOICES = (('admin', 'Admin'), ('access', 'Access'))
 
     role = StrippedCharField(choices=ROLE_CHOICES, unique=True, max_length=30)
 
-    def __unicode__(self):  return u'%s' % (self.role)
+    def __unicode__(self): return u'%s' % (self.role)
+
 
 class TenantRootPrivilege(PlCoreBase):
     user = models.ForeignKey('User', related_name="tenant_root_privileges")
-    tenant_root = models.ForeignKey('TenantRoot', related_name="tenant_root_privileges")
-    role = models.ForeignKey('TenantRootRole', related_name="tenant_root_privileges")
+    tenant_root = models.ForeignKey(
+        'TenantRoot', related_name="tenant_root_privileges")
+    role = models.ForeignKey(
+        'TenantRootRole', related_name="tenant_root_privileges")
 
     class Meta:
         unique_together = ('user', 'tenant_root', 'role')
 
-    def __unicode__(self):  return u'%s %s %s' % (self.tenant_root, self.user, self.role)
+    def __unicode__(self): return u'%s %s %s' % (
+        self.tenant_root, self.user, self.role)
 
     def save(self, *args, **kwds):
         if not self.user.is_active:
@@ -820,8 +888,7 @@
 
             # A slice admin can see the SlicePrivileges for his Slice
             for priv in cls.objects.filter(user=user, role__role="admin"):
-                trp_ids.extend( [trp.id for trp in cls.objects.filter(tenant_root=priv.tenant_root)] )
+                trp_ids.extend(
+                    [trp.id for trp in cls.objects.filter(tenant_root=priv.tenant_root)])
 
             return cls.objects.filter(id__in=trp_ids)
-
-
diff --git a/xos/core/models/user.py b/xos/core/models/user.py
index 4acad99..f1d73d2 100644
--- a/xos/core/models/user.py
+++ b/xos/core/models/user.py
@@ -1,21 +1,22 @@
-import os
 import datetime
-import sys
 import hashlib
+import os
+import sys
 from collections import defaultdict
-from django.forms.models import model_to_dict
+from operator import attrgetter, itemgetter
+
+import synchronizers.model_policy
+from core.middleware import get_request
+from core.models import DashboardView, PlCoreBase, PlModelMixIn, Site
+from core.models.plcorebase import StrippedCharField
+from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
+from django.core.exceptions import PermissionDenied
+from django.core.mail import EmailMultiAlternatives
 from django.db import models
 from django.db.models import F, Q
+from django.forms.models import model_to_dict
 from django.utils import timezone
-from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
-from django.core.mail import EmailMultiAlternatives
-from django.core.exceptions import PermissionDenied
-from core.models import PlCoreBase,Site, DashboardView, PlModelMixIn
-from core.models.plcorebase import StrippedCharField
 from timezones.fields import TimeZoneField
-from operator import itemgetter, attrgetter
-from core.middleware import get_request
-import synchronizers.model_policy
 
 # ------ from plcorebase.py ------
 try:
@@ -32,7 +33,10 @@
 # ------ ------
 
 # Create your models here.
+
+
 class UserManager(BaseUserManager):
+
     def create_user(self, email, firstname, lastname, password=None):
         """
         Creates and saves a User with the given email, date of
@@ -47,7 +51,7 @@
             lastname=lastname,
             password=password
         )
-        #user.set_password(password)
+        # user.set_password(password)
         user.is_admin = True
         user.save(using=self._db)
         return user
@@ -58,16 +62,16 @@
         birth and password.
         """
         user = self.create_user(email,
-            password=password,
-            firstname=firstname,
-            lastname=lastname
-        )
+                                password=password,
+                                firstname=firstname,
+                                lastname=lastname
+                                )
         user.is_admin = True
         user.save(using=self._db)
         return user
 
     def get_queryset(self):
-        parent=super(UserManager, self)
+        parent = super(UserManager, self)
         if hasattr(parent, "get_queryset"):
             return parent.get_queryset().filter(deleted=False)
         else:
@@ -77,7 +81,9 @@
     def get_query_set(self):
         return self.get_queryset()
 
+
 class DeletedUserManager(UserManager):
+
     def get_queryset(self):
         return super(UserManager, self).get_query_set().filter(deleted=True)
 
@@ -85,7 +91,9 @@
     def get_query_set(self):
         return self.get_queryset()
 
+
 class User(AbstractBaseUser, PlModelMixIn):
+
     @property
     def remote_password(self):
         return hashlib.md5(self.password).hexdigest()[:12]
@@ -100,15 +108,19 @@
         db_index=True,
     )
 
-    username = StrippedCharField(max_length=255, default="Something" )
+    username = StrippedCharField(max_length=255, default="Something")
 
-    firstname = StrippedCharField(help_text="person's given name", max_length=200)
+    firstname = StrippedCharField(
+        help_text="person's given name", max_length=200)
     lastname = StrippedCharField(help_text="person's surname", max_length=200)
 
-    phone = StrippedCharField(null=True, blank=True, help_text="phone number contact", max_length=100)
+    phone = StrippedCharField(null=True, blank=True,
+                              help_text="phone number contact", max_length=100)
     user_url = models.URLField(null=True, blank=True)
-    site = models.ForeignKey(Site, related_name='users', help_text="Site this user will be homed too")
-    public_key = models.TextField(null=True, blank=True, max_length=1024, help_text="Public key string")
+    site = models.ForeignKey(Site, related_name='users',
+                             help_text="Site this user will be homed too")
+    public_key = models.TextField(
+        null=True, blank=True, max_length=1024, help_text="Public key string")
 
     is_active = models.BooleanField(default=True)
     is_admin = models.BooleanField(default=False)
@@ -117,14 +129,15 @@
     is_registering = models.BooleanField(default=False)
     is_appuser = models.BooleanField(default=False)
 
-    login_page = StrippedCharField(help_text="send this user to a specific page on login", max_length=200, null=True, blank=True)
+    login_page = StrippedCharField(
+        help_text="send this user to a specific page on login", max_length=200, null=True, blank=True)
 
     created = models.DateTimeField(auto_now_add=True)
     updated = models.DateTimeField(auto_now=True)
     enacted = models.DateTimeField(null=True, default=None)
     policed = models.DateTimeField(null=True, default=None)
     backend_status = StrippedCharField(max_length=1024,
-                                      default="Provisioning in progress")
+                                       default="Provisioning in progress")
     deleted = models.BooleanField(default=False)
     write_protect = models.BooleanField(default=False)
     lazy_blocked = models.BooleanField(default=False)
@@ -133,7 +146,8 @@
 
     timezone = TimeZoneField()
 
-    dashboards = models.ManyToManyField('DashboardView', through='UserDashboardView', blank=True)
+    dashboards = models.ManyToManyField(
+        'DashboardView', through='UserDashboardView', blank=True)
 
     objects = UserManager()
     deleted_objects = DeletedUserManager()
@@ -142,11 +156,12 @@
     REQUIRED_FIELDS = ['firstname', 'lastname']
 
     PI_FORBIDDEN_FIELDS = ["is_admin", "site", "is_staff"]
-    USER_FORBIDDEN_FIELDS = ["is_admin", "is_active", "site", "is_staff", "is_readonly"]
+    USER_FORBIDDEN_FIELDS = ["is_admin", "is_active",
+                             "site", "is_staff", "is_readonly"]
 
     def __init__(self, *args, **kwargs):
         super(User, self).__init__(*args, **kwargs)
-        self._initial = self._dict # for PlModelMixIn
+        self._initial = self._dict  # for PlModelMixIn
 
     def isReadOnlyUser(self):
         return self.is_readonly
@@ -161,21 +176,21 @@
 
     def delete(self, *args, **kwds):
         # so we have something to give the observer
-        purge = kwds.get('purge',False)
+        purge = kwds.get('purge', False)
         if purge:
             del kwds['purge']
         try:
             purge = purge or observer_disabled
         except NameError:
             pass
-            
+
         if (purge):
             super(User, self).delete(*args, **kwds)
         else:
             if (not self.write_protect):
-                    self.deleted = True
-                    self.enacted=None
-                    self.save(update_fields=['enacted','deleted'])
+                self.deleted = True
+                self.enacted = None
+                self.save(update_fields=['enacted', 'deleted'])
 
     @property
     def keyname(self):
@@ -198,9 +213,10 @@
         return False
 
     def get_dashboards(self):
-        DEFAULT_DASHBOARDS=["Tenant"]
+        DEFAULT_DASHBOARDS = ["Tenant"]
 
-        dashboards = sorted(list(self.userdashboardviews.all()), key=attrgetter('order'))
+        dashboards = sorted(
+            list(self.userdashboardviews.all()), key=attrgetter('order'))
         dashboards = [x.dashboardView for x in dashboards]
 
         if (not dashboards) and (not self.is_appuser):
@@ -222,14 +238,14 @@
 #            roles[site_privilege.role.role_type].append(site_privilege.site.login_base)
 #        for slice_membership in slice_memberships:
 #            roles[slice_membership.role.role_type].append(slice_membership.slice.name)
-#        return roles   
+#        return roles
 
     def save(self, *args, **kwds):
         if not self.id:
             self.set_password(self.password)
         if self.is_active and self.is_registering:
             self.send_temporary_password()
-            self.is_registering=False
+            self.is_registering = False
 
         self.username = self.email
         super(User, self).save(*args, **kwds)
@@ -239,11 +255,14 @@
     def send_temporary_password(self):
         password = User.objects.make_random_password()
         self.set_password(password)
-        subject, from_email, to = 'OpenCloud Account Credentials', 'support@opencloud.us', str(self.email)
+        subject, from_email, to = 'OpenCloud Account Credentials', 'support@opencloud.us', str(
+            self.email)
         text_content = 'This is an important message.'
-        userUrl="http://%s/" % get_request().get_host()
-        html_content = """<p>Your account has been created on OpenCloud. Please log in <a href="""+userUrl+""">here</a> to activate your account<br><br>Username: """+self.email+"""<br>Temporary Password: """+password+"""<br>Please change your password once you successully login into the site.</p>"""
-        msg = EmailMultiAlternatives(subject,text_content, from_email, [to])
+        userUrl = "http://%s/" % get_request().get_host()
+        html_content = """<p>Your account has been created on OpenCloud. Please log in <a href=""" + userUrl + """>here</a> to activate your account<br><br>Username: """ + \
+            self.email + """<br>Temporary Password: """ + password + \
+            """<br>Please change your password once you successully login into the site.</p>"""
+        msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
         msg.attach_alternative(html_content, "text/html")
         msg.send()
 
@@ -257,7 +276,7 @@
         site_privs = SitePrivilege.objects.filter(user=user, site=self.site)
         for site_priv in site_privs:
             if site_priv.role.role == 'admin':
-                return True 
+                return True
             if site_priv.role.role == 'pi':
                 for fieldName in self.diff.keys():
                     if fieldName in self.PI_FORBIDDEN_FIELDS:
@@ -282,29 +301,29 @@
         if self.is_admin:
             return True
 
-        return False 
+        return False
 
     def can_update_deployment(self, deployment):
         from core.models.site import DeploymentPrivilege
         if self.can_update_root():
-            return True    
-                          
-        if DeploymentPrivilege.objects.filter(
-            deployment=deployment,
-            user=self,
-            role__role__in=['admin', 'Admin']):
             return True
-        return False    
+
+        if DeploymentPrivilege.objects.filter(
+                deployment=deployment,
+                user=self,
+                role__role__in=['admin', 'Admin']):
+            return True
+        return False
 
     def can_update_site(self, site, allow=[]):
         from core.models.site import SitePrivilege
         if self.can_update_root():
             return True
         if SitePrivilege.objects.filter(
-            site=site, user=self, role__role__in=['admin', 'Admin']+allow):
+                site=site, user=self, role__role__in=['admin', 'Admin'] + allow):
             return True
         return False
-    
+
     def can_update_slice(self, slice):
         from core.models.slice import SlicePrivilege
         if self.can_update_root():
@@ -313,9 +332,9 @@
             return True
         if self.can_update_site(slice.site, allow=['pi']):
             return True
-                     
+
         if SlicePrivilege.objects.filter(
-            slice=slice, user=self, role__role__in=['admin', 'Admin']):
+                slice=slice, user=self, role__role__in=['admin', 'Admin']):
             return True
         return False
 
@@ -324,7 +343,7 @@
         if self.can_update_root():
             return True
         if ServicePrivilege.objects.filter(
-            service=service, user=self, role__role__in=['admin', 'Admin']+allow):
+                service=service, user=self, role__role__in=['admin', 'Admin'] + allow):
             return True
         return False
 
@@ -333,7 +352,7 @@
         if self.can_update_root():
             return True
         if TenantRootPrivilege.objects.filter(
-            tenant_root=tenant_root, user=self, role__role__in=['admin', 'Admin']+allow):
+                tenant_root=tenant_root, user=self, role__role__in=['admin', 'Admin'] + allow):
             return True
         return False
 
@@ -341,31 +360,32 @@
         return self.can_update_tenant_root(tenant_root_privilege.tenant_root, allow)
 
     def get_readable_objects(self, filter_by=None):
-       """ Returns a list of objects that the user is allowed to read. """
-       from core.models import Deployment, Flavor, Image, Network, NetworkTemplate, Node, PlModelMixIn, Site, Slice, SliceTag, Instance, Tag, User, DeploymentPrivilege, SitePrivilege, SlicePrivilege
-       models = []
-       if filter_by and isinstance(filter_by, list):
-           models = [m for m in filter_by if issubclass(m, PlModelMixIn)]
-       if not models:
-           models = [Deployment, Network, Site, Slice, SliceTag, Instance, Tag, User]
-       readable_objects = []
-       for model in models:
-           readable_objects.extend(model.select_by_user(self))
-       return readable_objects
+        """ Returns a list of objects that the user is allowed to read. """
+        from core.models import Deployment, Flavor, Image, Network, NetworkTemplate, Node, PlModelMixIn, Site, Slice, SliceTag, Instance, Tag, User, DeploymentPrivilege, SitePrivilege, SlicePrivilege
+        models = []
+        if filter_by and isinstance(filter_by, list):
+            models = [m for m in filter_by if issubclass(m, PlModelMixIn)]
+        if not models:
+            models = [Deployment, Network, Site,
+                      Slice, SliceTag, Instance, Tag, User]
+        readable_objects = []
+        for model in models:
+            readable_objects.extend(model.select_by_user(self))
+        return readable_objects
 
     def get_permissions(self, filter_by=None):
         """ Return a list of objects for which the user has read or read/write 
         access. The object will be an instance of a django model object. 
         Permissions will be either 'r' or 'rw'.
-         
+
         e.g.
         [{'object': django_object_instance, 'permissions': 'rw'}, ...]
 
         Returns:
           list of dicts  
-       
+
         """
-        from core.models import Deployment, Flavor, Image, Network, NetworkTemplate, Node, PlModelMixIn, Site, Slice, SliceTag, Instance, Tag, User, DeploymentPrivilege, SitePrivilege, SlicePrivilege   
+        from core.models import Deployment, Flavor, Image, Network, NetworkTemplate, Node, PlModelMixIn, Site, Slice, SliceTag, Instance, Tag, User, DeploymentPrivilege, SitePrivilege, SlicePrivilege
         READ = 'r'
         READWRITE = 'rw'
         models = []
@@ -374,35 +394,35 @@
 
         deployment_priv_objs = [Image, NetworkTemplate, Flavor]
         site_priv_objs = [Node, Slice, User]
-        slice_priv_objs = [Instance, Network] 
-        
+        slice_priv_objs = [Instance, Network]
+
         # maps the set of objects a paticular role has write access
         write_map = {
-            DeploymentPrivilege : {
+            DeploymentPrivilege: {
                 'admin': deployment_priv_objects,
             },
-            SitePrivilege : {
-                'admin' : site_priv_objs,
-                'pi' : [Slice, User],
+            SitePrivilege: {
+                'admin': site_priv_objs,
+                'pi': [Slice, User],
                 'tech': [Node],
-            },     
-            SlicePrivilege : {
-                'admin': slice_priv_objs, 
-            }, 
+            },
+            SlicePrivilege: {
+                'admin': slice_priv_objs,
+            },
         }
-            
+
         privilege_map = {
-            DeploymentPrivilege : (Deployment, deployment_priv_objs),
-            SitePrivilege : (Site, site_priv_objs),
-            SlicePrivilege : (Slice, slice_priv_objs)
+            DeploymentPrivilege: (Deployment, deployment_priv_objs),
+            SitePrivilege: (Site, site_priv_objs),
+            SlicePrivilege: (Slice, slice_priv_objs)
         }
         permissions = []
-        permission_dict = lambda x,y: {'object': x, 'permission': y}
+        permission_dict = lambda x, y: {'object': x, 'permission': y}
         for privilege_model, (model, affected_models) in privileg_map.items():
             if models and model not in models:
                 continue
 
-            # get the objects affected by this privilege model   
+            # get the objects affected by this privilege model
             affected_objects = []
             for affected_model in affected_models:
                 affected_objects.extend(affected_model.select_by_user(self))
@@ -410,10 +430,11 @@
             if self.is_admin:
                 # assume admin users have read/write access to all objects
                 for affected_object in affected_objects:
-                    permissions.append(permission_dict(affected_object, READWRITE))
+                    permissions.append(permission_dict(
+                        affected_object, READWRITE))
             else:
                 # create a dict of the user's per object privileges
-                # ex:  {princeton_tmack : ['admin']  
+                # ex:  {princeton_tmack : ['admin']
                 privileges = privilege_model.objects.filter(user=self)
                 for privilege in privileges:
                     object_roles = defaultdict(list)
@@ -424,32 +445,33 @@
                             obj = getattr(privilege, field)
                     if obj:
                         object_roles[obj].append(privilege.role.role)
-                        
+
                 # loop through all objects the user has access to and determine
                 # if they also have write access
                 for affected_object in affected_objects:
                     if affected_object not in objects_roles:
-                        permissions.append(permission_dict(affected_object, READ))
+                        permissions.append(
+                            permission_dict(affected_object, READ))
                     else:
                         has_write_permission = False
                         for write_role, models in write_dict.items():
                             if affected_object._meta.model in models and \
-                                write_role in object_roles[affected_object]:
-                                    has_write_permission = True
-                                    break
+                                    write_role in object_roles[affected_object]:
+                                has_write_permission = True
+                                break
                         if has_write_permission:
-                            permissions.append(permission_dict(affected_object, WRITE))
+                            permissions.append(
+                                permission_dict(affected_object, WRITE))
                         else:
-                            permissions.append(permission_dict(affected_object, READ))
-                                
-        return permissions                          
-                     
+                            permissions.append(
+                                permission_dict(affected_object, READ))
+
+        return permissions
 
     def get_tenant_permissions(self):
         from core.models import Site, Slice
-        return self.get_object_permissions(filter_by=[Site,Slice])
+        return self.get_object_permissions(filter_by=[Site, Slice])
 
-    
     @staticmethod
     def select_by_user(user):
         if user.is_admin:
@@ -458,7 +480,8 @@
             # can see all users at any site where this user has pi role
             from core.models.site import SitePrivilege
             site_privs = SitePrivilege.objects.filter(user=user)
-            sites = [sp.site for sp in site_privs if sp.role.role in ['Admin', 'admin', 'pi']]
+            sites = [sp.site for sp in site_privs if sp.role.role in [
+                'Admin', 'admin', 'pi']]
             # get site privs of users at these sites
             site_privs = SitePrivilege.objects.filter(site__in=sites)
             user_ids = [sp.user.id for sp in site_privs] + [user.id]
@@ -468,29 +491,34 @@
     def save_by_user(self, user, *args, **kwds):
         if not self.can_update(user):
             if getattr(self, "_cant_update_fieldName", None) is not None:
-                raise PermissionDenied("You do not have permission to update field %s on object %s" % (self._cant_update_fieldName, self.__class__.__name__))
+                raise PermissionDenied("You do not have permission to update field %s on object %s" % (
+                    self._cant_update_fieldName, self.__class__.__name__))
             else:
-                raise PermissionDenied("You do not have permission to update %s objects" % self.__class__.__name__)
+                raise PermissionDenied(
+                    "You do not have permission to update %s objects" % self.__class__.__name__)
 
         self.save(*args, **kwds)
 
     def delete_by_user(self, user, *args, **kwds):
         if not self.can_update(user):
-            raise PermissionDenied("You do not have permission to delete %s objects" % self.__class__.__name__)
+            raise PermissionDenied(
+                "You do not have permission to delete %s objects" % self.__class__.__name__)
         self.delete(*args, **kwds)
 
     def apply_profile(self, profile):
-        if profile=="regular":
+        if profile == "regular":
             self.is_appuser = False
             self.is_admin = False
 
-        elif profile=="cp":
+        elif profile == "cp":
             self.is_appuser = True
             self.is_admin = False
             for db in self.userdashboardviews.all():
                 db.delete()
 
+
 class UserDashboardView(PlCoreBase):
-     user = models.ForeignKey(User, related_name='userdashboardviews')
-     dashboardView = models.ForeignKey(DashboardView, related_name='userdashboardviews')
-     order = models.IntegerField(default=0)
+    user = models.ForeignKey(User, related_name='userdashboardviews')
+    dashboardView = models.ForeignKey(
+        DashboardView, related_name='userdashboardviews')
+    order = models.IntegerField(default=0)
diff --git a/xos/core/xoslib/dashboards/xosDiagnostic.html b/xos/core/xoslib/dashboards/xosDiagnostic.html
index f988d9a..f87baae 100644
--- a/xos/core/xoslib/dashboards/xosDiagnostic.html
+++ b/xos/core/xoslib/dashboards/xosDiagnostic.html
@@ -4,7 +4,7 @@
 <link rel="stylesheet" href="/static/css/xosDiagnostic.css">
 <!-- endinject -->
 
-<div id="xosDiagnostic">
+<div ng-app="xos.diagnostic" id="xosDiagnostic">
     <div ui-view></div>
 </div>
 
diff --git a/xos/core/xoslib/dashboards/xosSampleView.html b/xos/core/xoslib/dashboards/xosSampleView.html
index 92d6f9a..6ebd9f3 100644
--- a/xos/core/xoslib/dashboards/xosSampleView.html
+++ b/xos/core/xoslib/dashboards/xosSampleView.html
@@ -1,14 +1,14 @@
 <!-- browserSync -->
 
 <!-- inject:css -->
-<link rel="stylesheet" href="/css/dev.css">
+<link rel="stylesheet" href="/static/css/xosSampleView.css">
 <!-- endinject -->
 
-<div id="xosSampleView">
+<div ng-app="xos.sampleView" id="xosSampleView" class="container-fluid">
     <div ui-view></div>
 </div>
 
 
 <!-- inject:js -->
-<script src="/../../static/js/xosSampleView.js"></script>
+<script src="/static/js/xosSampleView.js"></script>
 <!-- endinject -->
diff --git a/xos/core/xoslib/static/css/xosDiagnostic.css b/xos/core/xoslib/static/css/xosDiagnostic.css
index 0c1de20..7aee881 100644
--- a/xos/core/xoslib/static/css/xosDiagnostic.css
+++ b/xos/core/xoslib/static/css/xosDiagnostic.css
@@ -1 +1 @@
-#xosDiagnostic,[ui-view]{min-height:700px;position:relative}diagnostic-container .form-control.small-padding{padding:6px}diagnostic-container .half-height{position:relative;height:50%}diagnostic-container .onethird-height{position:relative;height:33%;border-bottom:1px solid #999}diagnostic-container .twothird-height{position:relative;height:67%}diagnostic-container .subscriber-select{max-width:200px;position:absolute;top:20px;right:20px;z-index:1}diagnostic-container .onethird-height .well,diagnostic-container .twothird-height .well{font-weight:700;max-width:165px;text-align:center;margin-top:15px;background:#eee;border-color:steelblue;padding:10px}diagnostic-container .onethird-height .well.pull-right{position:absolute;right:0;top:-15px;cursor:pointer;z-index:200}subscriber-status-modal .row+.row{margin-top:20px}.half-height+.half-height{border-top:1px solid black}service-topology,logic-topology{height:100%;width:100%;display:block;position:absolute;top:0}logic-topology .subscriber circle,logic-topology .device circle{fill:#fff;stroke:green;stroke-width:1px}logic-topology>svg{position:absolute;top:0}logic-topology .network .cloud{fill:#fff;stroke:green;stroke-width:1px}logic-topology .node.rack>g>rect{fill:#ccc;stroke:steelblue;stroke-width:1px}logic-topology .compute-node>rect{fill:#fff;stroke:steelblue;stroke-width:1px}logic-topology .compute-node>text{font-size:16px}logic-topology .instance>rect{fill:#eee;stroke:steelblue;stroke-width:1px}logic-topology .node .instance.active rect{fill:lightsteelblue;stroke:steelblue;stroke-width:1px}logic-topology .node .instance.active.good>rect{fill:green}logic-topology .node .instance.active.provisioning>rect{fill:yellow}logic-topology .node .instance.active.bad>rect{fill:red}logic-topology .node .instance .stats-container rect{fill:white}logic-topology .node .instance .stats-container text.name{font-weight:700}logic-topology .node .instance .stats-container text.ip{font-style:italic;font-size:10px}logic-topology .node .instance .stats-container .container rect{fill:#eee;stroke:steelblue;stroke-width:1px}.legend{fill:#fff;stroke:#ccc;stroke-width:1px;position:relative}.legend text{stroke:#000}.node{cursor:pointer}.node circle,.node rect{fill:#fff;stroke:steelblue;stroke-width:1px}.node.subscriber circle,.node.subscriber rect,.node.router circle,.node.router rect{stroke:#05ffcb}.node.slice rect{stroke:#b01dff}.node.instance rect{stroke:#ccc}.node.instance rect.active{stroke:#ff8b00}.node rect.slice-detail{fill:#fff;stroke:steelblue;stroke-width:3px}.node text{font:18px sans-serif}.node .instance text{font:12px sans-serif}.node text.small{font-size:10px}.link,.device-link{fill:none;stroke:#ccc;stroke-width:2px}.link.slice{stroke:rgba(157,4,183,.29)}.link.instance{stroke:#ccc}.link.instance.active{stroke:rgba(255,138,0,.65)}.service-details{width:200px;position:absolute;top:20px;right:20px}.animate.ng-hide-remove{animation:.5s bounceInRight ease}.animate.ng-hide-add{animation:.5s bounceOutRight ease}.loader{font-size:10px;margin:150px auto;text-indent:-9999em;width:11em;height:11em;border-radius:50%;background:#fff;background:linear-gradient(to right,#fff 10%,rgba(255,255,255,0) 42%);position:relative;animation:load3 1.4s infinite linear;transform:translateZ(0)}.loader:before{width:50%;height:50%;background:#105e9e;border-radius:100% 0 0;position:absolute;top:0;left:0;content:''}.loader:after{background:#fff;width:75%;height:75%;border-radius:50%;content:'';margin:auto;position:absolute;top:0;left:0;bottom:0;right:0}@keyframes load3{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.modal.fade.in{display:block}@keyframes bounceInRight{from,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1.000)}from{opacity:0;transform:translate3d(3000px,0,0)}60%{opacity:1;transform:translate3d(-25px,0,0)}75%{transform:translate3d(10px,0,0)}90%{transform:translate3d(-5px,0,0)}to{transform:none}}@keyframes bounceOutRight{20%{opacity:1;transform:translate3d(-20px,0,0)}to{opacity:0;transform:translate3d(2000px,0,0)}}
\ No newline at end of file
+#xosDiagnostic,[ui-view]{min-height:700px;position:relative}diagnostic-container .form-control.small-padding{padding:6px}diagnostic-container .half-height{position:relative;height:50%}diagnostic-container .onethird-height{position:relative;height:33%;border-bottom:1px solid #999}diagnostic-container .twothird-height{position:relative;height:67%}diagnostic-container .subscriber-select{max-width:200px;position:absolute;top:20px;right:20px;z-index:1}diagnostic-container .onethird-height .well,diagnostic-container .twothird-height .well{font-weight:700;max-width:165px;text-align:center;margin-top:15px;background:#eee;border-color:steelblue;padding:10px}diagnostic-container .onethird-height .well.pull-right{position:absolute;right:0;top:-15px;cursor:pointer;z-index:200}subscriber-status-modal .row+.row{margin-top:20px}.half-height+.half-height{border-top:1px solid black}service-topology,logic-topology{height:100%;width:100%;display:block;position:absolute;top:0}logic-topology .subscriber circle,logic-topology .device circle{fill:#fff;stroke:green;stroke-width:1px}logic-topology>svg{position:absolute;top:0}logic-topology .network .cloud{fill:#fff;stroke:green;stroke-width:1px}logic-topology .node.rack>g>rect{fill:#ccc;stroke:steelblue;stroke-width:1px}logic-topology .compute-node>rect{fill:#fff;stroke:steelblue;stroke-width:1px}logic-topology .compute-node>text{font-size:16px}logic-topology .instance>rect{fill:#eee;stroke:steelblue;stroke-width:1px}logic-topology .node .instance.active rect{fill:lightsteelblue;stroke:steelblue;stroke-width:1px}logic-topology .node .instance.active.good>rect{fill:green}logic-topology .node .instance.active.provisioning>rect{fill:yellow}logic-topology .node .instance.active.bad>rect{fill:red}logic-topology .node .instance .stats-container rect{fill:white}logic-topology .node .instance .stats-container text.name{font-weight:700}logic-topology .node .instance .stats-container text.ip{font-style:italic;font-size:10px}logic-topology .node .instance .stats-container .container rect{fill:#eee;stroke:steelblue;stroke-width:1px}.legend{fill:#fff;stroke:#ccc;stroke-width:1px;position:relative}.legend text{stroke:#000}.node{cursor:pointer}.node circle,.node rect{fill:#fff;stroke:steelblue;stroke-width:1px}.node.subscriber circle,.node.subscriber rect,.node.router circle,.node.router rect{stroke:#05ffcb}.node.slice rect{stroke:#b01dff}.node.instance rect{stroke:#ccc}.node.instance rect.active{stroke:#ff8b00}.node rect.slice-detail{fill:#fff;stroke:steelblue;stroke-width:3px}.node text{font:18px sans-serif}.node .instance text{font:12px sans-serif}.node text.small{font-size:10px}.link,.device-link{fill:none;stroke:#ccc;stroke-width:2px}.link.slice{stroke:rgba(157,4,183,.29)}.link.instance{stroke:#ccc}.link.instance.active{stroke:rgba(255,138,0,.65)}.service-details{width:200px;position:absolute;top:20px;right:20px}.animate.ng-hide-remove{animation:.5s bounceInRight ease}.animate.ng-hide-add{animation:.5s bounceOutRight ease}.loader{font-size:10px;margin:150px auto;text-indent:-9999em;width:11em;height:11em;border-radius:50%;background:#fff;background:linear-gradient(to right,#fff 10%,rgba(255,255,255,0) 42%);position:relative;animation:load3 1.4s infinite linear;transform:translateZ(0)}.loader:before{width:50%;height:50%;background:#105e9e;border-radius:100% 0 0;position:absolute;top:0;left:0;content:''}.loader:after{background:#fff;width:75%;height:75%;border-radius:50%;content:'';margin:auto;position:absolute;top:0;left:0;bottom:0;right:0}@keyframes load3{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.modal.fade.in{display:block}@keyframes bounceInRight{from,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}from{opacity:0;transform:translate3d(3000px,0,0)}60%{opacity:1;transform:translate3d(-25px,0,0)}75%{transform:translate3d(10px,0,0)}90%{transform:translate3d(-5px,0,0)}to{transform:none}}@keyframes bounceOutRight{20%{opacity:1;transform:translate3d(-20px,0,0)}to{opacity:0;transform:translate3d(2000px,0,0)}}
\ No newline at end of file
diff --git a/views/ngXosLib/api/.gitignore b/xos/core/xoslib/static/css/xosSampleView.css
similarity index 100%
copy from views/ngXosLib/api/.gitignore
copy to xos/core/xoslib/static/css/xosSampleView.css
diff --git a/xos/core/xoslib/static/js/vendor/ngXosHelpers.js b/xos/core/xoslib/static/js/vendor/ngXosHelpers.js
index 69cbbf4..f981551 100644
--- a/xos/core/xoslib/static/js/vendor/ngXosHelpers.js
+++ b/xos/core/xoslib/static/js/vendor/ngXosHelpers.js
@@ -1 +1 @@
-!function(){"use strict";function e(e,n,o){e.interceptors.push("SetCSRFToken"),n.startSymbol("{$"),n.endSymbol("$}"),o.defaults.stripTrailingSlashes=!1}e.$inject=["$httpProvider","$interpolateProvider","$resourceProvider"],angular.module("bugSnag",[]).factory("$exceptionHandler",function(){return function(e,n){window.Bugsnag?Bugsnag.notifyException(e,{diagnostics:{cause:n}}):console.error(e,n,e.stack)}}),angular.module("xos.helpers",["ngCookies","xos.xos","xos.hpcapi","xos.xoslib","bugSnag"]).config(e)}(),function(){"use strict";function e(){return{request:function(e){return-1===e.url.indexOf(".html")&&(e.url+="?no_hyperlinks=1"),e}}}angular.module("xos.helpers").factory("NoHyperlinks",e)}(),function(){"use strict";function e(e){return{request:function(n){return"GET"!==n.method&&(n.headers["X-CSRFToken"]=e.get("xoscsrftoken")),n}}}e.$inject=["$cookies"],angular.module("xos.helpers").factory("SetCSRFToken",e)}(),function(){"use strict";function e(e){return r||(r=new e({domain:""})),r}function n(e){return t||(t=new e({domain:""})),t}function o(e){return i||(i=new e({domain:""})),i}e.$inject=["xos"],n.$inject=["xoslib"],o.$inject=["hpcapi"],angular.module("xos.helpers").service("XosApi",e).service("XoslibApi",n).service("HpcApi",o);var r,t,i}();
\ No newline at end of file
+"use strict";!function(){angular.module("xos.uiComponents",[])}(),function(){angular.module("xos.uiComponents").directive("xosTable",function(){return{restrict:"E",scope:{data:"=",config:"="},template:'\n          <div ng-show="vm.data.length > 0">\n            <div class="row" ng-if="vm.config.filter == \'fulltext\'">\n              <div class="col-xs-12">\n                <input\n                  class="form-control"\n                  placeholder="Type to search.."\n                  type="text"\n                  ng-model="vm.query"/>\n              </div>\n            </div>\n            <table ng-class="vm.classes" ng-show="vm.data.length > 0">\n              <thead>\n                <tr>\n                  <th ng-repeat="col in vm.columns">\n                    {{col.label}}\n                    <span ng-if="vm.config.order">\n                      <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = false">\n                        <i class="glyphicon glyphicon-chevron-up"></i>\n                      </a>\n                      <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = true">\n                        <i class="glyphicon glyphicon-chevron-down"></i>\n                      </a>\n                    </span>\n                  </th>\n                  <th ng-if="vm.config.actions">Actions</th>\n                </tr>\n              </thead>\n              <tbody ng-if="vm.config.filter == \'field\'">\n                <tr>\n                  <td ng-repeat="col in vm.columns">\n                    <input\n                      class="form-control"\n                      placeholder="Type to search by {{col.label}}"\n                      type="text"\n                      ng-model="vm.query[col.prop]"/>\n                  </td>\n                  <td ng-if="vm.config.actions"></td>\n                </tr>\n              </tbody>\n              <tbody>\n                <tr ng-repeat="item in vm.data | filter:vm.query | orderBy:vm.orderBy:vm.reverse | pagination:vm.currentPage * vm.config.pagination.pageSize | limitTo: (vm.config.pagination.pageSize || vm.data.length) track by $index">\n                  <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td>\n                  <td ng-if="vm.config.actions">\n                    <a href=""\n                      ng-repeat="action in vm.config.actions"\n                      ng-click="action.cb(item)"\n                      title="{{action.label}}">\n                      <i\n                        class="glyphicon glyphicon-{{action.icon}}"\n                        style="color: {{action.color}};"></i>\n                    </a>\n                  </td>\n                </tr>\n              </tbody>\n            </table>\n            <xos-pagination\n              ng-if="vm.config.pagination"\n              page-size="vm.config.pagination.pageSize"\n              total-elements="vm.data.length"\n              change="vm.goToPage">\n              </xos-pagination>\n          </div>\n          <div ng-show="vm.data.length == 0 || !vm.data">\n            <div class="alert alert-info">\n              No data to show.\n            </div>\n          </div>\n        ',bindToController:!0,controllerAs:"vm",controller:function(){var n=this;if(!this.config)throw new Error('[xosTable] Please provide a configuration via the "config" attribute');if(!this.config.columns)throw new Error("[xosTable] Please provide a columns list in the configuration");this.columns=this.config.columns,this.classes=this.config.classes||"table table-striped table-bordered",this.config.actions,this.config.pagination&&(this.currentPage=0,this.goToPage=function(e){n.currentPage=e})}}})}(),function(){angular.module("xos.uiComponents").directive("xosPagination",function(){return{restrict:"E",scope:{pageSize:"=",totalElements:"=",change:"="},template:'\n        <div class="row" ng-if="vm.pageList.length > 1">\n          <div class="col-xs-12 text-center">\n            <ul class="pagination">\n              <li\n                ng-click="vm.goToPage(vm.currentPage - 1)"\n                ng-class="{disabled: vm.currentPage == 0}">\n                <a href="" aria-label="Previous">\n                    <span aria-hidden="true">&laquo;</span>\n                </a>\n              </li>\n              <li ng-repeat="i in vm.pageList" ng-class="{active: i === vm.currentPage}">\n                <a href="" ng-click="vm.goToPage(i)">{{i + 1}}</a>\n              </li>\n              <li\n                ng-click="vm.goToPage(vm.currentPage + 1)"\n                ng-class="{disabled: vm.currentPage == vm.pages - 1}">\n                <a href="" aria-label="Next">\n                    <span aria-hidden="true">&raquo;</span>\n                </a>\n              </li>\n            </ul>\n          </div>\n        </div>\n      ',bindToController:!0,controllerAs:"vm",controller:["$scope",function(n){var e=this;this.currentPage=0,this.goToPage=function(n){0>n||n===e.pages||(e.currentPage=n,e.change(n))},this.createPages=function(n){for(var e=[],r=0;n>r;r++)e.push(r);return e},n.$watch(function(){return e.totalElements},function(){e.totalElements&&(e.pages=Math.ceil(e.totalElements/e.pageSize),e.pageList=e.createPages(e.pages))})}]}}).filter("pagination",function(){return function(n,e){return n&&angular.isArray(n)?(e=parseInt(e,10),n.slice(e)):n}})}(),function(){angular.module("xos.uiComponents").directive("xosAlert",function(){return{restrict:"E",scope:{config:"=",show:"=?"},template:'\n        <div class="alert alert-{{vm.config.type}}" ng-show="vm.show">\n          <button type="button" class="close" ng-if="vm.config.closeBtn" ng-click="vm.dismiss()">\n            <span aria-hidden="true">&times;</span>\n          </button>\n          <p ng-transclude></p>\n        </div>\n      ',transclude:!0,bindToController:!0,controllerAs:"vm",controller:["$timeout",function(n){var e=this;if(!this.config)throw new Error('[xosAlert] Please provide a configuration via the "config" attribute');this.show=this.show!==!1,this.dismiss=function(){e.show=!1},this.config.autoHide&&!function(){var r=n(function(){e.dismiss(),n.cancel(r)},e.config.autoHide)}()}]}})}(),function(){function n(n,e,r){n.interceptors.push("SetCSRFToken"),e.startSymbol("{$"),e.endSymbol("$}"),r.defaults.stripTrailingSlashes=!1}n.$inject=["$httpProvider","$interpolateProvider","$resourceProvider"],angular.module("bugSnag",[]).factory("$exceptionHandler",function(){return function(n,e){window.Bugsnag?Bugsnag.notifyException(n,{diagnostics:{cause:e}}):console.error(n,e,n.stack)}}),angular.module("xos.helpers",["ngCookies","ngResource","bugSnag","xos.uiComponents"]).config(n)}(),function(){angular.module("xos.helpers").service("vSG-Collection",["$resource",function(n){return n("/api/service/vsg/")}])}(),function(){angular.module("xos.helpers").service("vOLT-Collection",["$resource",function(n){return n("/api/tenant/cord/volt/:volt_id/",{volt_id:"@id"})}])}(),function(){angular.module("xos.helpers").service("Users",["$resource",function(n){return n("/api/core/users/")}])}(),function(){angular.module("xos.helpers").service("Truckroll-Collection",["$resource",function(n){return n("/api/tenant/truckroll/:truckroll_id/",{truckroll_id:"@id"})}])}(),function(){angular.module("xos.helpers").service("Subscribers",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/",{subscriber_id:"@id"})}]).service("Subscriber-features",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/",{subscriber_id:"@id"})}]).service("Subscriber-features-uplink_speed",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/uplink_speed/",{subscriber_id:"@id"})}]).service("Subscriber-features-downlink_speed",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/downlink_speed/",{subscriber_id:"@id"})}]).service("Subscriber-features-cdn",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/cdn/",{subscriber_id:"@id"})}]).service("Subscriber-features-uverse",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/uverse/",{subscriber_id:"@id"})}]).service("Subscriber-features-status",["$resource",function(n){return n("/api/tenant/cord/subscriber/:subscriber_id/features/status/",{subscriber_id:"@id"})}])}(),function(){angular.module("xos.helpers").service("ONOS-Services-Collection",["$resource",function(n){return n("/api/service/onos/")}])}(),function(){angular.module("xos.helpers").service("ONOS-App-Collection",["$resource",function(n){return n("/api/tenant/onos/app/")}])}(),function(){function n(){return{request:function(n){return-1===n.url.indexOf(".html")&&(n.url+="?no_hyperlinks=1"),n}}}angular.module("xos.helpers").factory("NoHyperlinks",n)}(),function(){function n(n){return{request:function(e){return"GET"!==e.method&&(e.headers["X-CSRFToken"]=n.get("xoscsrftoken")),e}}}n.$inject=["$cookies"],angular.module("xos.helpers").factory("SetCSRFToken",n)}();
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/vendor/ngXosVendor.js b/xos/core/xoslib/static/js/vendor/ngXosVendor.js
index 6f92beb..f537697 100644
--- a/xos/core/xoslib/static/js/vendor/ngXosVendor.js
+++ b/xos/core/xoslib/static/js/vendor/ngXosVendor.js
@@ -45536,3 +45536,3932 @@
 
 
 })(window, window.angular);
+
+/**
+ * @license AngularJS v1.4.7
+ * (c) 2010-2015 Google, Inc. http://angularjs.org
+ * License: MIT
+ */
+(function(window, angular, undefined) {'use strict';
+
+/* jshint ignore:start */
+var noop        = angular.noop;
+var extend      = angular.extend;
+var jqLite      = angular.element;
+var forEach     = angular.forEach;
+var isArray     = angular.isArray;
+var isString    = angular.isString;
+var isObject    = angular.isObject;
+var isUndefined = angular.isUndefined;
+var isDefined   = angular.isDefined;
+var isFunction  = angular.isFunction;
+var isElement   = angular.isElement;
+
+var ELEMENT_NODE = 1;
+var COMMENT_NODE = 8;
+
+var ADD_CLASS_SUFFIX = '-add';
+var REMOVE_CLASS_SUFFIX = '-remove';
+var EVENT_CLASS_PREFIX = 'ng-';
+var ACTIVE_CLASS_SUFFIX = '-active';
+
+var NG_ANIMATE_CLASSNAME = 'ng-animate';
+var NG_ANIMATE_CHILDREN_DATA = '$$ngAnimateChildren';
+
+// Detect proper transitionend/animationend event names.
+var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;
+
+// If unprefixed events are not supported but webkit-prefixed are, use the latter.
+// Otherwise, just use W3C names, browsers not supporting them at all will just ignore them.
+// Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend`
+// but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`.
+// Register both events in case `window.onanimationend` is not supported because of that,
+// do the same for `transitionend` as Safari is likely to exhibit similar behavior.
+// Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
+// therefore there is no reason to test anymore for other vendor prefixes:
+// http://caniuse.com/#search=transition
+if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionend)) {
+  CSS_PREFIX = '-webkit-';
+  TRANSITION_PROP = 'WebkitTransition';
+  TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
+} else {
+  TRANSITION_PROP = 'transition';
+  TRANSITIONEND_EVENT = 'transitionend';
+}
+
+if (isUndefined(window.onanimationend) && isDefined(window.onwebkitanimationend)) {
+  CSS_PREFIX = '-webkit-';
+  ANIMATION_PROP = 'WebkitAnimation';
+  ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
+} else {
+  ANIMATION_PROP = 'animation';
+  ANIMATIONEND_EVENT = 'animationend';
+}
+
+var DURATION_KEY = 'Duration';
+var PROPERTY_KEY = 'Property';
+var DELAY_KEY = 'Delay';
+var TIMING_KEY = 'TimingFunction';
+var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
+var ANIMATION_PLAYSTATE_KEY = 'PlayState';
+var SAFE_FAST_FORWARD_DURATION_VALUE = 9999;
+
+var ANIMATION_DELAY_PROP = ANIMATION_PROP + DELAY_KEY;
+var ANIMATION_DURATION_PROP = ANIMATION_PROP + DURATION_KEY;
+var TRANSITION_DELAY_PROP = TRANSITION_PROP + DELAY_KEY;
+var TRANSITION_DURATION_PROP = TRANSITION_PROP + DURATION_KEY;
+
+var isPromiseLike = function(p) {
+  return p && p.then ? true : false;
+};
+
+function assertArg(arg, name, reason) {
+  if (!arg) {
+    throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required"));
+  }
+  return arg;
+}
+
+function mergeClasses(a,b) {
+  if (!a && !b) return '';
+  if (!a) return b;
+  if (!b) return a;
+  if (isArray(a)) a = a.join(' ');
+  if (isArray(b)) b = b.join(' ');
+  return a + ' ' + b;
+}
+
+function packageStyles(options) {
+  var styles = {};
+  if (options && (options.to || options.from)) {
+    styles.to = options.to;
+    styles.from = options.from;
+  }
+  return styles;
+}
+
+function pendClasses(classes, fix, isPrefix) {
+  var className = '';
+  classes = isArray(classes)
+      ? classes
+      : classes && isString(classes) && classes.length
+          ? classes.split(/\s+/)
+          : [];
+  forEach(classes, function(klass, i) {
+    if (klass && klass.length > 0) {
+      className += (i > 0) ? ' ' : '';
+      className += isPrefix ? fix + klass
+                            : klass + fix;
+    }
+  });
+  return className;
+}
+
+function removeFromArray(arr, val) {
+  var index = arr.indexOf(val);
+  if (val >= 0) {
+    arr.splice(index, 1);
+  }
+}
+
+function stripCommentsFromElement(element) {
+  if (element instanceof jqLite) {
+    switch (element.length) {
+      case 0:
+        return [];
+        break;
+
+      case 1:
+        // there is no point of stripping anything if the element
+        // is the only element within the jqLite wrapper.
+        // (it's important that we retain the element instance.)
+        if (element[0].nodeType === ELEMENT_NODE) {
+          return element;
+        }
+        break;
+
+      default:
+        return jqLite(extractElementNode(element));
+        break;
+    }
+  }
+
+  if (element.nodeType === ELEMENT_NODE) {
+    return jqLite(element);
+  }
+}
+
+function extractElementNode(element) {
+  if (!element[0]) return element;
+  for (var i = 0; i < element.length; i++) {
+    var elm = element[i];
+    if (elm.nodeType == ELEMENT_NODE) {
+      return elm;
+    }
+  }
+}
+
+function $$addClass($$jqLite, element, className) {
+  forEach(element, function(elm) {
+    $$jqLite.addClass(elm, className);
+  });
+}
+
+function $$removeClass($$jqLite, element, className) {
+  forEach(element, function(elm) {
+    $$jqLite.removeClass(elm, className);
+  });
+}
+
+function applyAnimationClassesFactory($$jqLite) {
+  return function(element, options) {
+    if (options.addClass) {
+      $$addClass($$jqLite, element, options.addClass);
+      options.addClass = null;
+    }
+    if (options.removeClass) {
+      $$removeClass($$jqLite, element, options.removeClass);
+      options.removeClass = null;
+    }
+  }
+}
+
+function prepareAnimationOptions(options) {
+  options = options || {};
+  if (!options.$$prepared) {
+    var domOperation = options.domOperation || noop;
+    options.domOperation = function() {
+      options.$$domOperationFired = true;
+      domOperation();
+      domOperation = noop;
+    };
+    options.$$prepared = true;
+  }
+  return options;
+}
+
+function applyAnimationStyles(element, options) {
+  applyAnimationFromStyles(element, options);
+  applyAnimationToStyles(element, options);
+}
+
+function applyAnimationFromStyles(element, options) {
+  if (options.from) {
+    element.css(options.from);
+    options.from = null;
+  }
+}
+
+function applyAnimationToStyles(element, options) {
+  if (options.to) {
+    element.css(options.to);
+    options.to = null;
+  }
+}
+
+function mergeAnimationOptions(element, target, newOptions) {
+  var toAdd = (target.addClass || '') + ' ' + (newOptions.addClass || '');
+  var toRemove = (target.removeClass || '') + ' ' + (newOptions.removeClass || '');
+  var classes = resolveElementClasses(element.attr('class'), toAdd, toRemove);
+
+  if (newOptions.preparationClasses) {
+    target.preparationClasses = concatWithSpace(newOptions.preparationClasses, target.preparationClasses);
+    delete newOptions.preparationClasses;
+  }
+
+  // noop is basically when there is no callback; otherwise something has been set
+  var realDomOperation = target.domOperation !== noop ? target.domOperation : null;
+
+  extend(target, newOptions);
+
+  // TODO(matsko or sreeramu): proper fix is to maintain all animation callback in array and call at last,but now only leave has the callback so no issue with this.
+  if (realDomOperation) {
+    target.domOperation = realDomOperation;
+  }
+
+  if (classes.addClass) {
+    target.addClass = classes.addClass;
+  } else {
+    target.addClass = null;
+  }
+
+  if (classes.removeClass) {
+    target.removeClass = classes.removeClass;
+  } else {
+    target.removeClass = null;
+  }
+
+  return target;
+}
+
+function resolveElementClasses(existing, toAdd, toRemove) {
+  var ADD_CLASS = 1;
+  var REMOVE_CLASS = -1;
+
+  var flags = {};
+  existing = splitClassesToLookup(existing);
+
+  toAdd = splitClassesToLookup(toAdd);
+  forEach(toAdd, function(value, key) {
+    flags[key] = ADD_CLASS;
+  });
+
+  toRemove = splitClassesToLookup(toRemove);
+  forEach(toRemove, function(value, key) {
+    flags[key] = flags[key] === ADD_CLASS ? null : REMOVE_CLASS;
+  });
+
+  var classes = {
+    addClass: '',
+    removeClass: ''
+  };
+
+  forEach(flags, function(val, klass) {
+    var prop, allow;
+    if (val === ADD_CLASS) {
+      prop = 'addClass';
+      allow = !existing[klass];
+    } else if (val === REMOVE_CLASS) {
+      prop = 'removeClass';
+      allow = existing[klass];
+    }
+    if (allow) {
+      if (classes[prop].length) {
+        classes[prop] += ' ';
+      }
+      classes[prop] += klass;
+    }
+  });
+
+  function splitClassesToLookup(classes) {
+    if (isString(classes)) {
+      classes = classes.split(' ');
+    }
+
+    var obj = {};
+    forEach(classes, function(klass) {
+      // sometimes the split leaves empty string values
+      // incase extra spaces were applied to the options
+      if (klass.length) {
+        obj[klass] = true;
+      }
+    });
+    return obj;
+  }
+
+  return classes;
+}
+
+function getDomNode(element) {
+  return (element instanceof angular.element) ? element[0] : element;
+}
+
+function applyGeneratedPreparationClasses(element, event, options) {
+  var classes = '';
+  if (event) {
+    classes = pendClasses(event, EVENT_CLASS_PREFIX, true);
+  }
+  if (options.addClass) {
+    classes = concatWithSpace(classes, pendClasses(options.addClass, ADD_CLASS_SUFFIX));
+  }
+  if (options.removeClass) {
+    classes = concatWithSpace(classes, pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX));
+  }
+  if (classes.length) {
+    options.preparationClasses = classes;
+    element.addClass(classes);
+  }
+}
+
+function clearGeneratedClasses(element, options) {
+  if (options.preparationClasses) {
+    element.removeClass(options.preparationClasses);
+    options.preparationClasses = null;
+  }
+  if (options.activeClasses) {
+    element.removeClass(options.activeClasses);
+    options.activeClasses = null;
+  }
+}
+
+function blockTransitions(node, duration) {
+  // we use a negative delay value since it performs blocking
+  // yet it doesn't kill any existing transitions running on the
+  // same element which makes this safe for class-based animations
+  var value = duration ? '-' + duration + 's' : '';
+  applyInlineStyle(node, [TRANSITION_DELAY_PROP, value]);
+  return [TRANSITION_DELAY_PROP, value];
+}
+
+function blockKeyframeAnimations(node, applyBlock) {
+  var value = applyBlock ? 'paused' : '';
+  var key = ANIMATION_PROP + ANIMATION_PLAYSTATE_KEY;
+  applyInlineStyle(node, [key, value]);
+  return [key, value];
+}
+
+function applyInlineStyle(node, styleTuple) {
+  var prop = styleTuple[0];
+  var value = styleTuple[1];
+  node.style[prop] = value;
+}
+
+function concatWithSpace(a,b) {
+  if (!a) return b;
+  if (!b) return a;
+  return a + ' ' + b;
+}
+
+var $$rAFSchedulerFactory = ['$$rAF', function($$rAF) {
+  var queue, cancelFn;
+
+  function scheduler(tasks) {
+    // we make a copy since RAFScheduler mutates the state
+    // of the passed in array variable and this would be difficult
+    // to track down on the outside code
+    queue = queue.concat(tasks);
+    nextTick();
+  }
+
+  queue = scheduler.queue = [];
+
+  /* waitUntilQuiet does two things:
+   * 1. It will run the FINAL `fn` value only when an uncancelled RAF has passed through
+   * 2. It will delay the next wave of tasks from running until the quiet `fn` has run.
+   *
+   * The motivation here is that animation code can request more time from the scheduler
+   * before the next wave runs. This allows for certain DOM properties such as classes to
+   * be resolved in time for the next animation to run.
+   */
+  scheduler.waitUntilQuiet = function(fn) {
+    if (cancelFn) cancelFn();
+
+    cancelFn = $$rAF(function() {
+      cancelFn = null;
+      fn();
+      nextTick();
+    });
+  };
+
+  return scheduler;
+
+  function nextTick() {
+    if (!queue.length) return;
+
+    var items = queue.shift();
+    for (var i = 0; i < items.length; i++) {
+      items[i]();
+    }
+
+    if (!cancelFn) {
+      $$rAF(function() {
+        if (!cancelFn) nextTick();
+      });
+    }
+  }
+}];
+
+var $$AnimateChildrenDirective = [function() {
+  return function(scope, element, attrs) {
+    var val = attrs.ngAnimateChildren;
+    if (angular.isString(val) && val.length === 0) { //empty attribute
+      element.data(NG_ANIMATE_CHILDREN_DATA, true);
+    } else {
+      attrs.$observe('ngAnimateChildren', function(value) {
+        value = value === 'on' || value === 'true';
+        element.data(NG_ANIMATE_CHILDREN_DATA, value);
+      });
+    }
+  };
+}];
+
+var ANIMATE_TIMER_KEY = '$$animateCss';
+
+/**
+ * @ngdoc service
+ * @name $animateCss
+ * @kind object
+ *
+ * @description
+ * The `$animateCss` service is a useful utility to trigger customized CSS-based transitions/keyframes
+ * from a JavaScript-based animation or directly from a directive. The purpose of `$animateCss` is NOT
+ * to side-step how `$animate` and ngAnimate work, but the goal is to allow pre-existing animations or
+ * directives to create more complex animations that can be purely driven using CSS code.
+ *
+ * Note that only browsers that support CSS transitions and/or keyframe animations are capable of
+ * rendering animations triggered via `$animateCss` (bad news for IE9 and lower).
+ *
+ * ## Usage
+ * Once again, `$animateCss` is designed to be used inside of a registered JavaScript animation that
+ * is powered by ngAnimate. It is possible to use `$animateCss` directly inside of a directive, however,
+ * any automatic control over cancelling animations and/or preventing animations from being run on
+ * child elements will not be handled by Angular. For this to work as expected, please use `$animate` to
+ * trigger the animation and then setup a JavaScript animation that injects `$animateCss` to trigger
+ * the CSS animation.
+ *
+ * The example below shows how we can create a folding animation on an element using `ng-if`:
+ *
+ * ```html
+ * <!-- notice the `fold-animation` CSS class -->
+ * <div ng-if="onOff" class="fold-animation">
+ *   This element will go BOOM
+ * </div>
+ * <button ng-click="onOff=true">Fold In</button>
+ * ```
+ *
+ * Now we create the **JavaScript animation** that will trigger the CSS transition:
+ *
+ * ```js
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
+ *   return {
+ *     enter: function(element, doneFn) {
+ *       var height = element[0].offsetHeight;
+ *       return $animateCss(element, {
+ *         from: { height:'0px' },
+ *         to: { height:height + 'px' },
+ *         duration: 1 // one second
+ *       });
+ *     }
+ *   }
+ * }]);
+ * ```
+ *
+ * ## More Advanced Uses
+ *
+ * `$animateCss` is the underlying code that ngAnimate uses to power **CSS-based animations** behind the scenes. Therefore CSS hooks
+ * like `.ng-EVENT`, `.ng-EVENT-active`, `.ng-EVENT-stagger` are all features that can be triggered using `$animateCss` via JavaScript code.
+ *
+ * This also means that just about any combination of adding classes, removing classes, setting styles, dynamically setting a keyframe animation,
+ * applying a hardcoded duration or delay value, changing the animation easing or applying a stagger animation are all options that work with
+ * `$animateCss`. The service itself is smart enough to figure out the combination of options and examine the element styling properties in order
+ * to provide a working animation that will run in CSS.
+ *
+ * The example below showcases a more advanced version of the `.fold-animation` from the example above:
+ *
+ * ```js
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
+ *   return {
+ *     enter: function(element, doneFn) {
+ *       var height = element[0].offsetHeight;
+ *       return $animateCss(element, {
+ *         addClass: 'red large-text pulse-twice',
+ *         easing: 'ease-out',
+ *         from: { height:'0px' },
+ *         to: { height:height + 'px' },
+ *         duration: 1 // one second
+ *       });
+ *     }
+ *   }
+ * }]);
+ * ```
+ *
+ * Since we're adding/removing CSS classes then the CSS transition will also pick those up:
+ *
+ * ```css
+ * /&#42; since a hardcoded duration value of 1 was provided in the JavaScript animation code,
+ * the CSS classes below will be transitioned despite them being defined as regular CSS classes &#42;/
+ * .red { background:red; }
+ * .large-text { font-size:20px; }
+ *
+ * /&#42; we can also use a keyframe animation and $animateCss will make it work alongside the transition &#42;/
+ * .pulse-twice {
+ *   animation: 0.5s pulse linear 2;
+ *   -webkit-animation: 0.5s pulse linear 2;
+ * }
+ *
+ * @keyframes pulse {
+ *   from { transform: scale(0.5); }
+ *   to { transform: scale(1.5); }
+ * }
+ *
+ * @-webkit-keyframes pulse {
+ *   from { -webkit-transform: scale(0.5); }
+ *   to { -webkit-transform: scale(1.5); }
+ * }
+ * ```
+ *
+ * Given this complex combination of CSS classes, styles and options, `$animateCss` will figure everything out and make the animation happen.
+ *
+ * ## How the Options are handled
+ *
+ * `$animateCss` is very versatile and intelligent when it comes to figuring out what configurations to apply to the element to ensure the animation
+ * works with the options provided. Say for example we were adding a class that contained a keyframe value and we wanted to also animate some inline
+ * styles using the `from` and `to` properties.
+ *
+ * ```js
+ * var animator = $animateCss(element, {
+ *   from: { background:'red' },
+ *   to: { background:'blue' }
+ * });
+ * animator.start();
+ * ```
+ *
+ * ```css
+ * .rotating-animation {
+ *   animation:0.5s rotate linear;
+ *   -webkit-animation:0.5s rotate linear;
+ * }
+ *
+ * @keyframes rotate {
+ *   from { transform: rotate(0deg); }
+ *   to { transform: rotate(360deg); }
+ * }
+ *
+ * @-webkit-keyframes rotate {
+ *   from { -webkit-transform: rotate(0deg); }
+ *   to { -webkit-transform: rotate(360deg); }
+ * }
+ * ```
+ *
+ * The missing pieces here are that we do not have a transition set (within the CSS code nor within the `$animateCss` options) and the duration of the animation is
+ * going to be detected from what the keyframe styles on the CSS class are. In this event, `$animateCss` will automatically create an inline transition
+ * style matching the duration detected from the keyframe style (which is present in the CSS class that is being added) and then prepare both the transition
+ * and keyframe animations to run in parallel on the element. Then when the animation is underway the provided `from` and `to` CSS styles will be applied
+ * and spread across the transition and keyframe animation.
+ *
+ * ## What is returned
+ *
+ * `$animateCss` works in two stages: a preparation phase and an animation phase. Therefore when `$animateCss` is first called it will NOT actually
+ * start the animation. All that is going on here is that the element is being prepared for the animation (which means that the generated CSS classes are
+ * added and removed on the element). Once `$animateCss` is called it will return an object with the following properties:
+ *
+ * ```js
+ * var animator = $animateCss(element, { ... });
+ * ```
+ *
+ * Now what do the contents of our `animator` variable look like:
+ *
+ * ```js
+ * {
+ *   // starts the animation
+ *   start: Function,
+ *
+ *   // ends (aborts) the animation
+ *   end: Function
+ * }
+ * ```
+ *
+ * To actually start the animation we need to run `animation.start()` which will then return a promise that we can hook into to detect when the animation ends.
+ * If we choose not to run the animation then we MUST run `animation.end()` to perform a cleanup on the element (since some CSS classes and stlyes may have been
+ * applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties
+ * and that changing them will not reconfigure the parameters of the animation.
+ *
+ * ### runner.done() vs runner.then()
+ * It is documented that `animation.start()` will return a promise object and this is true, however, there is also an additional method available on the
+ * runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**.
+ * Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()`
+ * unless you really need a digest to kick off afterwards.
+ *
+ * Keep in mind that, to make this easier, ngAnimate has tweaked the JS animations API to recognize when a runner instance is returned from $animateCss
+ * (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code).
+ * Check the {@link ngAnimate.$animateCss#usage animation code above} to see how this works.
+ *
+ * @param {DOMElement} element the element that will be animated
+ * @param {object} options the animation-related options that will be applied during the animation
+ *
+ * * `event` - The DOM event (e.g. enter, leave, move). When used, a generated CSS class of `ng-EVENT` and `ng-EVENT-active` will be applied
+ * to the element during the animation. Multiple events can be provided when spaces are used as a separator. (Note that this will not perform any DOM operation.)
+ * * `easing` - The CSS easing value that will be applied to the transition or keyframe animation (or both).
+ * * `transitionStyle` - The raw CSS transition style that will be used (e.g. `1s linear all`).
+ * * `keyframeStyle` - The raw CSS keyframe animation style that will be used (e.g. `1s my_animation linear`).
+ * * `from` - The starting CSS styles (a key/value object) that will be applied at the start of the animation.
+ * * `to` - The ending CSS styles (a key/value object) that will be applied across the animation via a CSS transition.
+ * * `addClass` - A space separated list of CSS classes that will be added to the element and spread across the animation.
+ * * `removeClass` - A space separated list of CSS classes that will be removed from the element and spread across the animation.
+ * * `duration` - A number value representing the total duration of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `0`
+ * is provided then the animation will be skipped entirely.
+ * * `delay` - A number value representing the total delay of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `true` is
+ * used then whatever delay value is detected from the CSS classes will be mirrored on the elements styles (e.g. by setting delay true then the style value
+ * of the element will be `transition-delay: DETECTED_VALUE`). Using `true` is useful when you want the CSS classes and inline styles to all share the same
+ * CSS delay value.
+ * * `stagger` - A numeric time value representing the delay between successively animated elements
+ * ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.})
+ * * `staggerIndex` - The numeric index representing the stagger item (e.g. a value of 5 is equal to the sixth item in the stagger; therefore when a
+ * * `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
+ * * `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occuring on the classes being added and removed.)
+ * * `cleanupStyles` - Whether or not the provided `from` and `to` styles will be removed once
+ *    the animation is closed. This is useful for when the styles are used purely for the sake of
+ *    the animation and do not have a lasting visual effect on the element (e.g. a colapse and open animation).
+ *    By default this value is set to `false`.
+ *
+ * @return {object} an object with start and end methods and details about the animation.
+ *
+ * * `start` - The method to start the animation. This will return a `Promise` when called.
+ * * `end` - This method will cancel the animation and remove all applied CSS classes and styles.
+ */
+var ONE_SECOND = 1000;
+var BASE_TEN = 10;
+
+var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
+var CLOSING_TIME_BUFFER = 1.5;
+
+var DETECT_CSS_PROPERTIES = {
+  transitionDuration:      TRANSITION_DURATION_PROP,
+  transitionDelay:         TRANSITION_DELAY_PROP,
+  transitionProperty:      TRANSITION_PROP + PROPERTY_KEY,
+  animationDuration:       ANIMATION_DURATION_PROP,
+  animationDelay:          ANIMATION_DELAY_PROP,
+  animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY
+};
+
+var DETECT_STAGGER_CSS_PROPERTIES = {
+  transitionDuration:      TRANSITION_DURATION_PROP,
+  transitionDelay:         TRANSITION_DELAY_PROP,
+  animationDuration:       ANIMATION_DURATION_PROP,
+  animationDelay:          ANIMATION_DELAY_PROP
+};
+
+function getCssKeyframeDurationStyle(duration) {
+  return [ANIMATION_DURATION_PROP, duration + 's'];
+}
+
+function getCssDelayStyle(delay, isKeyframeAnimation) {
+  var prop = isKeyframeAnimation ? ANIMATION_DELAY_PROP : TRANSITION_DELAY_PROP;
+  return [prop, delay + 's'];
+}
+
+function computeCssStyles($window, element, properties) {
+  var styles = Object.create(null);
+  var detectedStyles = $window.getComputedStyle(element) || {};
+  forEach(properties, function(formalStyleName, actualStyleName) {
+    var val = detectedStyles[formalStyleName];
+    if (val) {
+      var c = val.charAt(0);
+
+      // only numerical-based values have a negative sign or digit as the first value
+      if (c === '-' || c === '+' || c >= 0) {
+        val = parseMaxTime(val);
+      }
+
+      // by setting this to null in the event that the delay is not set or is set directly as 0
+      // then we can still allow for zegative values to be used later on and not mistake this
+      // value for being greater than any other negative value.
+      if (val === 0) {
+        val = null;
+      }
+      styles[actualStyleName] = val;
+    }
+  });
+
+  return styles;
+}
+
+function parseMaxTime(str) {
+  var maxValue = 0;
+  var values = str.split(/\s*,\s*/);
+  forEach(values, function(value) {
+    // it's always safe to consider only second values and omit `ms` values since
+    // getComputedStyle will always handle the conversion for us
+    if (value.charAt(value.length - 1) == 's') {
+      value = value.substring(0, value.length - 1);
+    }
+    value = parseFloat(value) || 0;
+    maxValue = maxValue ? Math.max(value, maxValue) : value;
+  });
+  return maxValue;
+}
+
+function truthyTimingValue(val) {
+  return val === 0 || val != null;
+}
+
+function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
+  var style = TRANSITION_PROP;
+  var value = duration + 's';
+  if (applyOnlyDuration) {
+    style += DURATION_KEY;
+  } else {
+    value += ' linear all';
+  }
+  return [style, value];
+}
+
+function createLocalCacheLookup() {
+  var cache = Object.create(null);
+  return {
+    flush: function() {
+      cache = Object.create(null);
+    },
+
+    count: function(key) {
+      var entry = cache[key];
+      return entry ? entry.total : 0;
+    },
+
+    get: function(key) {
+      var entry = cache[key];
+      return entry && entry.value;
+    },
+
+    put: function(key, value) {
+      if (!cache[key]) {
+        cache[key] = { total: 1, value: value };
+      } else {
+        cache[key].total++;
+      }
+    }
+  };
+}
+
+// we do not reassign an already present style value since
+// if we detect the style property value again we may be
+// detecting styles that were added via the `from` styles.
+// We make use of `isDefined` here since an empty string
+// or null value (which is what getPropertyValue will return
+// for a non-existing style) will still be marked as a valid
+// value for the style (a falsy value implies that the style
+// is to be removed at the end of the animation). If we had a simple
+// "OR" statement then it would not be enough to catch that.
+function registerRestorableStyles(backup, node, properties) {
+  forEach(properties, function(prop) {
+    backup[prop] = isDefined(backup[prop])
+        ? backup[prop]
+        : node.style.getPropertyValue(prop);
+  });
+}
+
+var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
+  var gcsLookup = createLocalCacheLookup();
+  var gcsStaggerLookup = createLocalCacheLookup();
+
+  this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout',
+               '$$forceReflow', '$sniffer', '$$rAFScheduler', '$animate',
+       function($window,   $$jqLite,   $$AnimateRunner,   $timeout,
+                $$forceReflow,   $sniffer,   $$rAFScheduler, $animate) {
+
+    var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
+
+    var parentCounter = 0;
+    function gcsHashFn(node, extraClasses) {
+      var KEY = "$$ngAnimateParentKey";
+      var parentNode = node.parentNode;
+      var parentID = parentNode[KEY] || (parentNode[KEY] = ++parentCounter);
+      return parentID + '-' + node.getAttribute('class') + '-' + extraClasses;
+    }
+
+    function computeCachedCssStyles(node, className, cacheKey, properties) {
+      var timings = gcsLookup.get(cacheKey);
+
+      if (!timings) {
+        timings = computeCssStyles($window, node, properties);
+        if (timings.animationIterationCount === 'infinite') {
+          timings.animationIterationCount = 1;
+        }
+      }
+
+      // we keep putting this in multiple times even though the value and the cacheKey are the same
+      // because we're keeping an interal tally of how many duplicate animations are detected.
+      gcsLookup.put(cacheKey, timings);
+      return timings;
+    }
+
+    function computeCachedCssStaggerStyles(node, className, cacheKey, properties) {
+      var stagger;
+
+      // if we have one or more existing matches of matching elements
+      // containing the same parent + CSS styles (which is how cacheKey works)
+      // then staggering is possible
+      if (gcsLookup.count(cacheKey) > 0) {
+        stagger = gcsStaggerLookup.get(cacheKey);
+
+        if (!stagger) {
+          var staggerClassName = pendClasses(className, '-stagger');
+
+          $$jqLite.addClass(node, staggerClassName);
+
+          stagger = computeCssStyles($window, node, properties);
+
+          // force the conversion of a null value to zero incase not set
+          stagger.animationDuration = Math.max(stagger.animationDuration, 0);
+          stagger.transitionDuration = Math.max(stagger.transitionDuration, 0);
+
+          $$jqLite.removeClass(node, staggerClassName);
+
+          gcsStaggerLookup.put(cacheKey, stagger);
+        }
+      }
+
+      return stagger || {};
+    }
+
+    var cancelLastRAFRequest;
+    var rafWaitQueue = [];
+    function waitUntilQuiet(callback) {
+      rafWaitQueue.push(callback);
+      $$rAFScheduler.waitUntilQuiet(function() {
+        gcsLookup.flush();
+        gcsStaggerLookup.flush();
+
+        // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
+        // PLEASE EXAMINE THE `$$forceReflow` service to understand why.
+        var pageWidth = $$forceReflow();
+
+        // we use a for loop to ensure that if the queue is changed
+        // during this looping then it will consider new requests
+        for (var i = 0; i < rafWaitQueue.length; i++) {
+          rafWaitQueue[i](pageWidth);
+        }
+        rafWaitQueue.length = 0;
+      });
+    }
+
+    function computeTimings(node, className, cacheKey) {
+      var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES);
+      var aD = timings.animationDelay;
+      var tD = timings.transitionDelay;
+      timings.maxDelay = aD && tD
+          ? Math.max(aD, tD)
+          : (aD || tD);
+      timings.maxDuration = Math.max(
+          timings.animationDuration * timings.animationIterationCount,
+          timings.transitionDuration);
+
+      return timings;
+    }
+
+    return function init(element, options) {
+      var restoreStyles = {};
+      var node = getDomNode(element);
+      if (!node
+          || !node.parentNode
+          || !$animate.enabled()) {
+        return closeAndReturnNoopAnimator();
+      }
+
+      options = prepareAnimationOptions(options);
+
+      var temporaryStyles = [];
+      var classes = element.attr('class');
+      var styles = packageStyles(options);
+      var animationClosed;
+      var animationPaused;
+      var animationCompleted;
+      var runner;
+      var runnerHost;
+      var maxDelay;
+      var maxDelayTime;
+      var maxDuration;
+      var maxDurationTime;
+
+      if (options.duration === 0 || (!$sniffer.animations && !$sniffer.transitions)) {
+        return closeAndReturnNoopAnimator();
+      }
+
+      var method = options.event && isArray(options.event)
+            ? options.event.join(' ')
+            : options.event;
+
+      var isStructural = method && options.structural;
+      var structuralClassName = '';
+      var addRemoveClassName = '';
+
+      if (isStructural) {
+        structuralClassName = pendClasses(method, EVENT_CLASS_PREFIX, true);
+      } else if (method) {
+        structuralClassName = method;
+      }
+
+      if (options.addClass) {
+        addRemoveClassName += pendClasses(options.addClass, ADD_CLASS_SUFFIX);
+      }
+
+      if (options.removeClass) {
+        if (addRemoveClassName.length) {
+          addRemoveClassName += ' ';
+        }
+        addRemoveClassName += pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX);
+      }
+
+      // there may be a situation where a structural animation is combined together
+      // with CSS classes that need to resolve before the animation is computed.
+      // However this means that there is no explicit CSS code to block the animation
+      // from happening (by setting 0s none in the class name). If this is the case
+      // we need to apply the classes before the first rAF so we know to continue if
+      // there actually is a detected transition or keyframe animation
+      if (options.applyClassesEarly && addRemoveClassName.length) {
+        applyAnimationClasses(element, options);
+      }
+
+      var preparationClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
+      var fullClassName = classes + ' ' + preparationClasses;
+      var activeClasses = pendClasses(preparationClasses, ACTIVE_CLASS_SUFFIX);
+      var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
+      var containsKeyframeAnimation = (options.keyframeStyle || '').length > 0;
+
+      // there is no way we can trigger an animation if no styles and
+      // no classes are being applied which would then trigger a transition,
+      // unless there a is raw keyframe value that is applied to the element.
+      if (!containsKeyframeAnimation
+           && !hasToStyles
+           && !preparationClasses) {
+        return closeAndReturnNoopAnimator();
+      }
+
+      var cacheKey, stagger;
+      if (options.stagger > 0) {
+        var staggerVal = parseFloat(options.stagger);
+        stagger = {
+          transitionDelay: staggerVal,
+          animationDelay: staggerVal,
+          transitionDuration: 0,
+          animationDuration: 0
+        };
+      } else {
+        cacheKey = gcsHashFn(node, fullClassName);
+        stagger = computeCachedCssStaggerStyles(node, preparationClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
+      }
+
+      if (!options.$$skipPreparationClasses) {
+        $$jqLite.addClass(element, preparationClasses);
+      }
+
+      var applyOnlyDuration;
+
+      if (options.transitionStyle) {
+        var transitionStyle = [TRANSITION_PROP, options.transitionStyle];
+        applyInlineStyle(node, transitionStyle);
+        temporaryStyles.push(transitionStyle);
+      }
+
+      if (options.duration >= 0) {
+        applyOnlyDuration = node.style[TRANSITION_PROP].length > 0;
+        var durationStyle = getCssTransitionDurationStyle(options.duration, applyOnlyDuration);
+
+        // we set the duration so that it will be picked up by getComputedStyle later
+        applyInlineStyle(node, durationStyle);
+        temporaryStyles.push(durationStyle);
+      }
+
+      if (options.keyframeStyle) {
+        var keyframeStyle = [ANIMATION_PROP, options.keyframeStyle];
+        applyInlineStyle(node, keyframeStyle);
+        temporaryStyles.push(keyframeStyle);
+      }
+
+      var itemIndex = stagger
+          ? options.staggerIndex >= 0
+              ? options.staggerIndex
+              : gcsLookup.count(cacheKey)
+          : 0;
+
+      var isFirst = itemIndex === 0;
+
+      // this is a pre-emptive way of forcing the setup classes to be added and applied INSTANTLY
+      // without causing any combination of transitions to kick in. By adding a negative delay value
+      // it forces the setup class' transition to end immediately. We later then remove the negative
+      // transition delay to allow for the transition to naturally do it's thing. The beauty here is
+      // that if there is no transition defined then nothing will happen and this will also allow
+      // other transitions to be stacked on top of each other without any chopping them out.
+      if (isFirst && !options.skipBlocking) {
+        blockTransitions(node, SAFE_FAST_FORWARD_DURATION_VALUE);
+      }
+
+      var timings = computeTimings(node, fullClassName, cacheKey);
+      var relativeDelay = timings.maxDelay;
+      maxDelay = Math.max(relativeDelay, 0);
+      maxDuration = timings.maxDuration;
+
+      var flags = {};
+      flags.hasTransitions          = timings.transitionDuration > 0;
+      flags.hasAnimations           = timings.animationDuration > 0;
+      flags.hasTransitionAll        = flags.hasTransitions && timings.transitionProperty == 'all';
+      flags.applyTransitionDuration = hasToStyles && (
+                                        (flags.hasTransitions && !flags.hasTransitionAll)
+                                         || (flags.hasAnimations && !flags.hasTransitions));
+      flags.applyAnimationDuration  = options.duration && flags.hasAnimations;
+      flags.applyTransitionDelay    = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
+      flags.applyAnimationDelay     = truthyTimingValue(options.delay) && flags.hasAnimations;
+      flags.recalculateTimingStyles = addRemoveClassName.length > 0;
+
+      if (flags.applyTransitionDuration || flags.applyAnimationDuration) {
+        maxDuration = options.duration ? parseFloat(options.duration) : maxDuration;
+
+        if (flags.applyTransitionDuration) {
+          flags.hasTransitions = true;
+          timings.transitionDuration = maxDuration;
+          applyOnlyDuration = node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0;
+          temporaryStyles.push(getCssTransitionDurationStyle(maxDuration, applyOnlyDuration));
+        }
+
+        if (flags.applyAnimationDuration) {
+          flags.hasAnimations = true;
+          timings.animationDuration = maxDuration;
+          temporaryStyles.push(getCssKeyframeDurationStyle(maxDuration));
+        }
+      }
+
+      if (maxDuration === 0 && !flags.recalculateTimingStyles) {
+        return closeAndReturnNoopAnimator();
+      }
+
+      if (options.delay != null) {
+        var delayStyle = parseFloat(options.delay);
+
+        if (flags.applyTransitionDelay) {
+          temporaryStyles.push(getCssDelayStyle(delayStyle));
+        }
+
+        if (flags.applyAnimationDelay) {
+          temporaryStyles.push(getCssDelayStyle(delayStyle, true));
+        }
+      }
+
+      // we need to recalculate the delay value since we used a pre-emptive negative
+      // delay value and the delay value is required for the final event checking. This
+      // property will ensure that this will happen after the RAF phase has passed.
+      if (options.duration == null && timings.transitionDuration > 0) {
+        flags.recalculateTimingStyles = flags.recalculateTimingStyles || isFirst;
+      }
+
+      maxDelayTime = maxDelay * ONE_SECOND;
+      maxDurationTime = maxDuration * ONE_SECOND;
+      if (!options.skipBlocking) {
+        flags.blockTransition = timings.transitionDuration > 0;
+        flags.blockKeyframeAnimation = timings.animationDuration > 0 &&
+                                       stagger.animationDelay > 0 &&
+                                       stagger.animationDuration === 0;
+      }
+
+      if (options.from) {
+        if (options.cleanupStyles) {
+          registerRestorableStyles(restoreStyles, node, Object.keys(options.from));
+        }
+        applyAnimationFromStyles(element, options);
+      }
+
+      if (flags.blockTransition || flags.blockKeyframeAnimation) {
+        applyBlocking(maxDuration);
+      } else if (!options.skipBlocking) {
+        blockTransitions(node, false);
+      }
+
+      // TODO(matsko): for 1.5 change this code to have an animator object for better debugging
+      return {
+        $$willAnimate: true,
+        end: endFn,
+        start: function() {
+          if (animationClosed) return;
+
+          runnerHost = {
+            end: endFn,
+            cancel: cancelFn,
+            resume: null, //this will be set during the start() phase
+            pause: null
+          };
+
+          runner = new $$AnimateRunner(runnerHost);
+
+          waitUntilQuiet(start);
+
+          // we don't have access to pause/resume the animation
+          // since it hasn't run yet. AnimateRunner will therefore
+          // set noop functions for resume and pause and they will
+          // later be overridden once the animation is triggered
+          return runner;
+        }
+      };
+
+      function endFn() {
+        close();
+      }
+
+      function cancelFn() {
+        close(true);
+      }
+
+      function close(rejected) { // jshint ignore:line
+        // if the promise has been called already then we shouldn't close
+        // the animation again
+        if (animationClosed || (animationCompleted && animationPaused)) return;
+        animationClosed = true;
+        animationPaused = false;
+
+        if (!options.$$skipPreparationClasses) {
+          $$jqLite.removeClass(element, preparationClasses);
+        }
+        $$jqLite.removeClass(element, activeClasses);
+
+        blockKeyframeAnimations(node, false);
+        blockTransitions(node, false);
+
+        forEach(temporaryStyles, function(entry) {
+          // There is only one way to remove inline style properties entirely from elements.
+          // By using `removeProperty` this works, but we need to convert camel-cased CSS
+          // styles down to hyphenated values.
+          node.style[entry[0]] = '';
+        });
+
+        applyAnimationClasses(element, options);
+        applyAnimationStyles(element, options);
+
+        if (Object.keys(restoreStyles).length) {
+          forEach(restoreStyles, function(value, prop) {
+            value ? node.style.setProperty(prop, value)
+                  : node.style.removeProperty(prop);
+          });
+        }
+
+        // the reason why we have this option is to allow a synchronous closing callback
+        // that is fired as SOON as the animation ends (when the CSS is removed) or if
+        // the animation never takes off at all. A good example is a leave animation since
+        // the element must be removed just after the animation is over or else the element
+        // will appear on screen for one animation frame causing an overbearing flicker.
+        if (options.onDone) {
+          options.onDone();
+        }
+
+        // if the preparation function fails then the promise is not setup
+        if (runner) {
+          runner.complete(!rejected);
+        }
+      }
+
+      function applyBlocking(duration) {
+        if (flags.blockTransition) {
+          blockTransitions(node, duration);
+        }
+
+        if (flags.blockKeyframeAnimation) {
+          blockKeyframeAnimations(node, !!duration);
+        }
+      }
+
+      function closeAndReturnNoopAnimator() {
+        runner = new $$AnimateRunner({
+          end: endFn,
+          cancel: cancelFn
+        });
+
+        // should flush the cache animation
+        waitUntilQuiet(noop);
+        close();
+
+        return {
+          $$willAnimate: false,
+          start: function() {
+            return runner;
+          },
+          end: endFn
+        };
+      }
+
+      function start() {
+        if (animationClosed) return;
+        if (!node.parentNode) {
+          close();
+          return;
+        }
+
+        var startTime, events = [];
+
+        // even though we only pause keyframe animations here the pause flag
+        // will still happen when transitions are used. Only the transition will
+        // not be paused since that is not possible. If the animation ends when
+        // paused then it will not complete until unpaused or cancelled.
+        var playPause = function(playAnimation) {
+          if (!animationCompleted) {
+            animationPaused = !playAnimation;
+            if (timings.animationDuration) {
+              var value = blockKeyframeAnimations(node, animationPaused);
+              animationPaused
+                  ? temporaryStyles.push(value)
+                  : removeFromArray(temporaryStyles, value);
+            }
+          } else if (animationPaused && playAnimation) {
+            animationPaused = false;
+            close();
+          }
+        };
+
+        // checking the stagger duration prevents an accidently cascade of the CSS delay style
+        // being inherited from the parent. If the transition duration is zero then we can safely
+        // rely that the delay value is an intential stagger delay style.
+        var maxStagger = itemIndex > 0
+                         && ((timings.transitionDuration && stagger.transitionDuration === 0) ||
+                            (timings.animationDuration && stagger.animationDuration === 0))
+                         && Math.max(stagger.animationDelay, stagger.transitionDelay);
+        if (maxStagger) {
+          $timeout(triggerAnimationStart,
+                   Math.floor(maxStagger * itemIndex * ONE_SECOND),
+                   false);
+        } else {
+          triggerAnimationStart();
+        }
+
+        // this will decorate the existing promise runner with pause/resume methods
+        runnerHost.resume = function() {
+          playPause(true);
+        };
+
+        runnerHost.pause = function() {
+          playPause(false);
+        };
+
+        function triggerAnimationStart() {
+          // just incase a stagger animation kicks in when the animation
+          // itself was cancelled entirely
+          if (animationClosed) return;
+
+          applyBlocking(false);
+
+          forEach(temporaryStyles, function(entry) {
+            var key = entry[0];
+            var value = entry[1];
+            node.style[key] = value;
+          });
+
+          applyAnimationClasses(element, options);
+          $$jqLite.addClass(element, activeClasses);
+
+          if (flags.recalculateTimingStyles) {
+            fullClassName = node.className + ' ' + preparationClasses;
+            cacheKey = gcsHashFn(node, fullClassName);
+
+            timings = computeTimings(node, fullClassName, cacheKey);
+            relativeDelay = timings.maxDelay;
+            maxDelay = Math.max(relativeDelay, 0);
+            maxDuration = timings.maxDuration;
+
+            if (maxDuration === 0) {
+              close();
+              return;
+            }
+
+            flags.hasTransitions = timings.transitionDuration > 0;
+            flags.hasAnimations = timings.animationDuration > 0;
+          }
+
+          if (flags.applyAnimationDelay) {
+            relativeDelay = typeof options.delay !== "boolean" && truthyTimingValue(options.delay)
+                  ? parseFloat(options.delay)
+                  : relativeDelay;
+
+            maxDelay = Math.max(relativeDelay, 0);
+            timings.animationDelay = relativeDelay;
+            delayStyle = getCssDelayStyle(relativeDelay, true);
+            temporaryStyles.push(delayStyle);
+            node.style[delayStyle[0]] = delayStyle[1];
+          }
+
+          maxDelayTime = maxDelay * ONE_SECOND;
+          maxDurationTime = maxDuration * ONE_SECOND;
+
+          if (options.easing) {
+            var easeProp, easeVal = options.easing;
+            if (flags.hasTransitions) {
+              easeProp = TRANSITION_PROP + TIMING_KEY;
+              temporaryStyles.push([easeProp, easeVal]);
+              node.style[easeProp] = easeVal;
+            }
+            if (flags.hasAnimations) {
+              easeProp = ANIMATION_PROP + TIMING_KEY;
+              temporaryStyles.push([easeProp, easeVal]);
+              node.style[easeProp] = easeVal;
+            }
+          }
+
+          if (timings.transitionDuration) {
+            events.push(TRANSITIONEND_EVENT);
+          }
+
+          if (timings.animationDuration) {
+            events.push(ANIMATIONEND_EVENT);
+          }
+
+          startTime = Date.now();
+          var timerTime = maxDelayTime + CLOSING_TIME_BUFFER * maxDurationTime;
+          var endTime = startTime + timerTime;
+
+          var animationsData = element.data(ANIMATE_TIMER_KEY) || [];
+          var setupFallbackTimer = true;
+          if (animationsData.length) {
+            var currentTimerData = animationsData[0];
+            setupFallbackTimer = endTime > currentTimerData.expectedEndTime;
+            if (setupFallbackTimer) {
+              $timeout.cancel(currentTimerData.timer);
+            } else {
+              animationsData.push(close);
+            }
+          }
+
+          if (setupFallbackTimer) {
+            var timer = $timeout(onAnimationExpired, timerTime, false);
+            animationsData[0] = {
+              timer: timer,
+              expectedEndTime: endTime
+            };
+            animationsData.push(close);
+            element.data(ANIMATE_TIMER_KEY, animationsData);
+          }
+
+          element.on(events.join(' '), onAnimationProgress);
+          if (options.to) {
+            if (options.cleanupStyles) {
+              registerRestorableStyles(restoreStyles, node, Object.keys(options.to));
+            }
+            applyAnimationToStyles(element, options);
+          }
+        }
+
+        function onAnimationExpired() {
+          var animationsData = element.data(ANIMATE_TIMER_KEY);
+
+          // this will be false in the event that the element was
+          // removed from the DOM (via a leave animation or something
+          // similar)
+          if (animationsData) {
+            for (var i = 1; i < animationsData.length; i++) {
+              animationsData[i]();
+            }
+            element.removeData(ANIMATE_TIMER_KEY);
+          }
+        }
+
+        function onAnimationProgress(event) {
+          event.stopPropagation();
+          var ev = event.originalEvent || event;
+          var timeStamp = ev.$manualTimeStamp || ev.timeStamp || Date.now();
+
+          /* Firefox (or possibly just Gecko) likes to not round values up
+           * when a ms measurement is used for the animation */
+          var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES));
+
+          /* $manualTimeStamp is a mocked timeStamp value which is set
+           * within browserTrigger(). This is only here so that tests can
+           * mock animations properly. Real events fallback to event.timeStamp,
+           * or, if they don't, then a timeStamp is automatically created for them.
+           * We're checking to see if the timeStamp surpasses the expected delay,
+           * but we're using elapsedTime instead of the timeStamp on the 2nd
+           * pre-condition since animations sometimes close off early */
+          if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
+            // we set this flag to ensure that if the transition is paused then, when resumed,
+            // the animation will automatically close itself since transitions cannot be paused.
+            animationCompleted = true;
+            close();
+          }
+        }
+      }
+    };
+  }];
+}];
+
+var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationProvider) {
+  $$animationProvider.drivers.push('$$animateCssDriver');
+
+  var NG_ANIMATE_SHIM_CLASS_NAME = 'ng-animate-shim';
+  var NG_ANIMATE_ANCHOR_CLASS_NAME = 'ng-anchor';
+
+  var NG_OUT_ANCHOR_CLASS_NAME = 'ng-anchor-out';
+  var NG_IN_ANCHOR_CLASS_NAME = 'ng-anchor-in';
+
+  function isDocumentFragment(node) {
+    return node.parentNode && node.parentNode.nodeType === 11;
+  }
+
+  this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$sniffer', '$$jqLite', '$document',
+       function($animateCss,   $rootScope,   $$AnimateRunner,   $rootElement,   $sniffer,   $$jqLite,   $document) {
+
+    // only browsers that support these properties can render animations
+    if (!$sniffer.animations && !$sniffer.transitions) return noop;
+
+    var bodyNode = $document[0].body;
+    var rootNode = getDomNode($rootElement);
+
+    var rootBodyElement = jqLite(
+      // this is to avoid using something that exists outside of the body
+      // we also special case the doc fragement case because our unit test code
+      // appends the $rootElement to the body after the app has been bootstrapped
+      isDocumentFragment(rootNode) || bodyNode.contains(rootNode) ? rootNode : bodyNode
+    );
+
+    var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
+
+    return function initDriverFn(animationDetails) {
+      return animationDetails.from && animationDetails.to
+          ? prepareFromToAnchorAnimation(animationDetails.from,
+                                         animationDetails.to,
+                                         animationDetails.classes,
+                                         animationDetails.anchors)
+          : prepareRegularAnimation(animationDetails);
+    };
+
+    function filterCssClasses(classes) {
+      //remove all the `ng-` stuff
+      return classes.replace(/\bng-\S+\b/g, '');
+    }
+
+    function getUniqueValues(a, b) {
+      if (isString(a)) a = a.split(' ');
+      if (isString(b)) b = b.split(' ');
+      return a.filter(function(val) {
+        return b.indexOf(val) === -1;
+      }).join(' ');
+    }
+
+    function prepareAnchoredAnimation(classes, outAnchor, inAnchor) {
+      var clone = jqLite(getDomNode(outAnchor).cloneNode(true));
+      var startingClasses = filterCssClasses(getClassVal(clone));
+
+      outAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
+      inAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
+
+      clone.addClass(NG_ANIMATE_ANCHOR_CLASS_NAME);
+
+      rootBodyElement.append(clone);
+
+      var animatorIn, animatorOut = prepareOutAnimation();
+
+      // the user may not end up using the `out` animation and
+      // only making use of the `in` animation or vice-versa.
+      // In either case we should allow this and not assume the
+      // animation is over unless both animations are not used.
+      if (!animatorOut) {
+        animatorIn = prepareInAnimation();
+        if (!animatorIn) {
+          return end();
+        }
+      }
+
+      var startingAnimator = animatorOut || animatorIn;
+
+      return {
+        start: function() {
+          var runner;
+
+          var currentAnimation = startingAnimator.start();
+          currentAnimation.done(function() {
+            currentAnimation = null;
+            if (!animatorIn) {
+              animatorIn = prepareInAnimation();
+              if (animatorIn) {
+                currentAnimation = animatorIn.start();
+                currentAnimation.done(function() {
+                  currentAnimation = null;
+                  end();
+                  runner.complete();
+                });
+                return currentAnimation;
+              }
+            }
+            // in the event that there is no `in` animation
+            end();
+            runner.complete();
+          });
+
+          runner = new $$AnimateRunner({
+            end: endFn,
+            cancel: endFn
+          });
+
+          return runner;
+
+          function endFn() {
+            if (currentAnimation) {
+              currentAnimation.end();
+            }
+          }
+        }
+      };
+
+      function calculateAnchorStyles(anchor) {
+        var styles = {};
+
+        var coords = getDomNode(anchor).getBoundingClientRect();
+
+        // we iterate directly since safari messes up and doesn't return
+        // all the keys for the coods object when iterated
+        forEach(['width','height','top','left'], function(key) {
+          var value = coords[key];
+          switch (key) {
+            case 'top':
+              value += bodyNode.scrollTop;
+              break;
+            case 'left':
+              value += bodyNode.scrollLeft;
+              break;
+          }
+          styles[key] = Math.floor(value) + 'px';
+        });
+        return styles;
+      }
+
+      function prepareOutAnimation() {
+        var animator = $animateCss(clone, {
+          addClass: NG_OUT_ANCHOR_CLASS_NAME,
+          delay: true,
+          from: calculateAnchorStyles(outAnchor)
+        });
+
+        // read the comment within `prepareRegularAnimation` to understand
+        // why this check is necessary
+        return animator.$$willAnimate ? animator : null;
+      }
+
+      function getClassVal(element) {
+        return element.attr('class') || '';
+      }
+
+      function prepareInAnimation() {
+        var endingClasses = filterCssClasses(getClassVal(inAnchor));
+        var toAdd = getUniqueValues(endingClasses, startingClasses);
+        var toRemove = getUniqueValues(startingClasses, endingClasses);
+
+        var animator = $animateCss(clone, {
+          to: calculateAnchorStyles(inAnchor),
+          addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + toAdd,
+          removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + toRemove,
+          delay: true
+        });
+
+        // read the comment within `prepareRegularAnimation` to understand
+        // why this check is necessary
+        return animator.$$willAnimate ? animator : null;
+      }
+
+      function end() {
+        clone.remove();
+        outAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
+        inAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
+      }
+    }
+
+    function prepareFromToAnchorAnimation(from, to, classes, anchors) {
+      var fromAnimation = prepareRegularAnimation(from, noop);
+      var toAnimation = prepareRegularAnimation(to, noop);
+
+      var anchorAnimations = [];
+      forEach(anchors, function(anchor) {
+        var outElement = anchor['out'];
+        var inElement = anchor['in'];
+        var animator = prepareAnchoredAnimation(classes, outElement, inElement);
+        if (animator) {
+          anchorAnimations.push(animator);
+        }
+      });
+
+      // no point in doing anything when there are no elements to animate
+      if (!fromAnimation && !toAnimation && anchorAnimations.length === 0) return;
+
+      return {
+        start: function() {
+          var animationRunners = [];
+
+          if (fromAnimation) {
+            animationRunners.push(fromAnimation.start());
+          }
+
+          if (toAnimation) {
+            animationRunners.push(toAnimation.start());
+          }
+
+          forEach(anchorAnimations, function(animation) {
+            animationRunners.push(animation.start());
+          });
+
+          var runner = new $$AnimateRunner({
+            end: endFn,
+            cancel: endFn // CSS-driven animations cannot be cancelled, only ended
+          });
+
+          $$AnimateRunner.all(animationRunners, function(status) {
+            runner.complete(status);
+          });
+
+          return runner;
+
+          function endFn() {
+            forEach(animationRunners, function(runner) {
+              runner.end();
+            });
+          }
+        }
+      };
+    }
+
+    function prepareRegularAnimation(animationDetails) {
+      var element = animationDetails.element;
+      var options = animationDetails.options || {};
+
+      if (animationDetails.structural) {
+        options.event = animationDetails.event;
+        options.structural = true;
+        options.applyClassesEarly = true;
+
+        // we special case the leave animation since we want to ensure that
+        // the element is removed as soon as the animation is over. Otherwise
+        // a flicker might appear or the element may not be removed at all
+        if (animationDetails.event === 'leave') {
+          options.onDone = options.domOperation;
+        }
+      }
+
+      // We assign the preparationClasses as the actual animation event since
+      // the internals of $animateCss will just suffix the event token values
+      // with `-active` to trigger the animation.
+      if (options.preparationClasses) {
+        options.event = concatWithSpace(options.event, options.preparationClasses);
+      }
+
+      var animator = $animateCss(element, options);
+
+      // the driver lookup code inside of $$animation attempts to spawn a
+      // driver one by one until a driver returns a.$$willAnimate animator object.
+      // $animateCss will always return an object, however, it will pass in
+      // a flag as a hint as to whether an animation was detected or not
+      return animator.$$willAnimate ? animator : null;
+    }
+  }];
+}];
+
+// TODO(matsko): use caching here to speed things up for detection
+// TODO(matsko): add documentation
+//  by the time...
+
+var $$AnimateJsProvider = ['$animateProvider', function($animateProvider) {
+  this.$get = ['$injector', '$$AnimateRunner', '$$jqLite',
+       function($injector,   $$AnimateRunner,   $$jqLite) {
+
+    var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
+         // $animateJs(element, 'enter');
+    return function(element, event, classes, options) {
+      // the `classes` argument is optional and if it is not used
+      // then the classes will be resolved from the element's className
+      // property as well as options.addClass/options.removeClass.
+      if (arguments.length === 3 && isObject(classes)) {
+        options = classes;
+        classes = null;
+      }
+
+      options = prepareAnimationOptions(options);
+      if (!classes) {
+        classes = element.attr('class') || '';
+        if (options.addClass) {
+          classes += ' ' + options.addClass;
+        }
+        if (options.removeClass) {
+          classes += ' ' + options.removeClass;
+        }
+      }
+
+      var classesToAdd = options.addClass;
+      var classesToRemove = options.removeClass;
+
+      // the lookupAnimations function returns a series of animation objects that are
+      // matched up with one or more of the CSS classes. These animation objects are
+      // defined via the module.animation factory function. If nothing is detected then
+      // we don't return anything which then makes $animation query the next driver.
+      var animations = lookupAnimations(classes);
+      var before, after;
+      if (animations.length) {
+        var afterFn, beforeFn;
+        if (event == 'leave') {
+          beforeFn = 'leave';
+          afterFn = 'afterLeave'; // TODO(matsko): get rid of this
+        } else {
+          beforeFn = 'before' + event.charAt(0).toUpperCase() + event.substr(1);
+          afterFn = event;
+        }
+
+        if (event !== 'enter' && event !== 'move') {
+          before = packageAnimations(element, event, options, animations, beforeFn);
+        }
+        after  = packageAnimations(element, event, options, animations, afterFn);
+      }
+
+      // no matching animations
+      if (!before && !after) return;
+
+      function applyOptions() {
+        options.domOperation();
+        applyAnimationClasses(element, options);
+      }
+
+      return {
+        start: function() {
+          var closeActiveAnimations;
+          var chain = [];
+
+          if (before) {
+            chain.push(function(fn) {
+              closeActiveAnimations = before(fn);
+            });
+          }
+
+          if (chain.length) {
+            chain.push(function(fn) {
+              applyOptions();
+              fn(true);
+            });
+          } else {
+            applyOptions();
+          }
+
+          if (after) {
+            chain.push(function(fn) {
+              closeActiveAnimations = after(fn);
+            });
+          }
+
+          var animationClosed = false;
+          var runner = new $$AnimateRunner({
+            end: function() {
+              endAnimations();
+            },
+            cancel: function() {
+              endAnimations(true);
+            }
+          });
+
+          $$AnimateRunner.chain(chain, onComplete);
+          return runner;
+
+          function onComplete(success) {
+            animationClosed = true;
+            applyOptions();
+            applyAnimationStyles(element, options);
+            runner.complete(success);
+          }
+
+          function endAnimations(cancelled) {
+            if (!animationClosed) {
+              (closeActiveAnimations || noop)(cancelled);
+              onComplete(cancelled);
+            }
+          }
+        }
+      };
+
+      function executeAnimationFn(fn, element, event, options, onDone) {
+        var args;
+        switch (event) {
+          case 'animate':
+            args = [element, options.from, options.to, onDone];
+            break;
+
+          case 'setClass':
+            args = [element, classesToAdd, classesToRemove, onDone];
+            break;
+
+          case 'addClass':
+            args = [element, classesToAdd, onDone];
+            break;
+
+          case 'removeClass':
+            args = [element, classesToRemove, onDone];
+            break;
+
+          default:
+            args = [element, onDone];
+            break;
+        }
+
+        args.push(options);
+
+        var value = fn.apply(fn, args);
+        if (value) {
+          if (isFunction(value.start)) {
+            value = value.start();
+          }
+
+          if (value instanceof $$AnimateRunner) {
+            value.done(onDone);
+          } else if (isFunction(value)) {
+            // optional onEnd / onCancel callback
+            return value;
+          }
+        }
+
+        return noop;
+      }
+
+      function groupEventedAnimations(element, event, options, animations, fnName) {
+        var operations = [];
+        forEach(animations, function(ani) {
+          var animation = ani[fnName];
+          if (!animation) return;
+
+          // note that all of these animations will run in parallel
+          operations.push(function() {
+            var runner;
+            var endProgressCb;
+
+            var resolved = false;
+            var onAnimationComplete = function(rejected) {
+              if (!resolved) {
+                resolved = true;
+                (endProgressCb || noop)(rejected);
+                runner.complete(!rejected);
+              }
+            };
+
+            runner = new $$AnimateRunner({
+              end: function() {
+                onAnimationComplete();
+              },
+              cancel: function() {
+                onAnimationComplete(true);
+              }
+            });
+
+            endProgressCb = executeAnimationFn(animation, element, event, options, function(result) {
+              var cancelled = result === false;
+              onAnimationComplete(cancelled);
+            });
+
+            return runner;
+          });
+        });
+
+        return operations;
+      }
+
+      function packageAnimations(element, event, options, animations, fnName) {
+        var operations = groupEventedAnimations(element, event, options, animations, fnName);
+        if (operations.length === 0) {
+          var a,b;
+          if (fnName === 'beforeSetClass') {
+            a = groupEventedAnimations(element, 'removeClass', options, animations, 'beforeRemoveClass');
+            b = groupEventedAnimations(element, 'addClass', options, animations, 'beforeAddClass');
+          } else if (fnName === 'setClass') {
+            a = groupEventedAnimations(element, 'removeClass', options, animations, 'removeClass');
+            b = groupEventedAnimations(element, 'addClass', options, animations, 'addClass');
+          }
+
+          if (a) {
+            operations = operations.concat(a);
+          }
+          if (b) {
+            operations = operations.concat(b);
+          }
+        }
+
+        if (operations.length === 0) return;
+
+        // TODO(matsko): add documentation
+        return function startAnimation(callback) {
+          var runners = [];
+          if (operations.length) {
+            forEach(operations, function(animateFn) {
+              runners.push(animateFn());
+            });
+          }
+
+          runners.length ? $$AnimateRunner.all(runners, callback) : callback();
+
+          return function endFn(reject) {
+            forEach(runners, function(runner) {
+              reject ? runner.cancel() : runner.end();
+            });
+          };
+        };
+      }
+    };
+
+    function lookupAnimations(classes) {
+      classes = isArray(classes) ? classes : classes.split(' ');
+      var matches = [], flagMap = {};
+      for (var i=0; i < classes.length; i++) {
+        var klass = classes[i],
+            animationFactory = $animateProvider.$$registeredAnimations[klass];
+        if (animationFactory && !flagMap[klass]) {
+          matches.push($injector.get(animationFactory));
+          flagMap[klass] = true;
+        }
+      }
+      return matches;
+    }
+  }];
+}];
+
+var $$AnimateJsDriverProvider = ['$$animationProvider', function($$animationProvider) {
+  $$animationProvider.drivers.push('$$animateJsDriver');
+  this.$get = ['$$animateJs', '$$AnimateRunner', function($$animateJs, $$AnimateRunner) {
+    return function initDriverFn(animationDetails) {
+      if (animationDetails.from && animationDetails.to) {
+        var fromAnimation = prepareAnimation(animationDetails.from);
+        var toAnimation = prepareAnimation(animationDetails.to);
+        if (!fromAnimation && !toAnimation) return;
+
+        return {
+          start: function() {
+            var animationRunners = [];
+
+            if (fromAnimation) {
+              animationRunners.push(fromAnimation.start());
+            }
+
+            if (toAnimation) {
+              animationRunners.push(toAnimation.start());
+            }
+
+            $$AnimateRunner.all(animationRunners, done);
+
+            var runner = new $$AnimateRunner({
+              end: endFnFactory(),
+              cancel: endFnFactory()
+            });
+
+            return runner;
+
+            function endFnFactory() {
+              return function() {
+                forEach(animationRunners, function(runner) {
+                  // at this point we cannot cancel animations for groups just yet. 1.5+
+                  runner.end();
+                });
+              };
+            }
+
+            function done(status) {
+              runner.complete(status);
+            }
+          }
+        };
+      } else {
+        return prepareAnimation(animationDetails);
+      }
+    };
+
+    function prepareAnimation(animationDetails) {
+      // TODO(matsko): make sure to check for grouped animations and delegate down to normal animations
+      var element = animationDetails.element;
+      var event = animationDetails.event;
+      var options = animationDetails.options;
+      var classes = animationDetails.classes;
+      return $$animateJs(element, event, classes, options);
+    }
+  }];
+}];
+
+var NG_ANIMATE_ATTR_NAME = 'data-ng-animate';
+var NG_ANIMATE_PIN_DATA = '$ngAnimatePin';
+var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
+  var PRE_DIGEST_STATE = 1;
+  var RUNNING_STATE = 2;
+
+  var rules = this.rules = {
+    skip: [],
+    cancel: [],
+    join: []
+  };
+
+  function isAllowed(ruleType, element, currentAnimation, previousAnimation) {
+    return rules[ruleType].some(function(fn) {
+      return fn(element, currentAnimation, previousAnimation);
+    });
+  }
+
+  function hasAnimationClasses(options, and) {
+    options = options || {};
+    var a = (options.addClass || '').length > 0;
+    var b = (options.removeClass || '').length > 0;
+    return and ? a && b : a || b;
+  }
+
+  rules.join.push(function(element, newAnimation, currentAnimation) {
+    // if the new animation is class-based then we can just tack that on
+    return !newAnimation.structural && hasAnimationClasses(newAnimation.options);
+  });
+
+  rules.skip.push(function(element, newAnimation, currentAnimation) {
+    // there is no need to animate anything if no classes are being added and
+    // there is no structural animation that will be triggered
+    return !newAnimation.structural && !hasAnimationClasses(newAnimation.options);
+  });
+
+  rules.skip.push(function(element, newAnimation, currentAnimation) {
+    // why should we trigger a new structural animation if the element will
+    // be removed from the DOM anyway?
+    return currentAnimation.event == 'leave' && newAnimation.structural;
+  });
+
+  rules.skip.push(function(element, newAnimation, currentAnimation) {
+    // if there is an ongoing current animation then don't even bother running the class-based animation
+    return currentAnimation.structural && currentAnimation.state === RUNNING_STATE && !newAnimation.structural;
+  });
+
+  rules.cancel.push(function(element, newAnimation, currentAnimation) {
+    // there can never be two structural animations running at the same time
+    return currentAnimation.structural && newAnimation.structural;
+  });
+
+  rules.cancel.push(function(element, newAnimation, currentAnimation) {
+    // if the previous animation is already running, but the new animation will
+    // be triggered, but the new animation is structural
+    return currentAnimation.state === RUNNING_STATE && newAnimation.structural;
+  });
+
+  rules.cancel.push(function(element, newAnimation, currentAnimation) {
+    var nO = newAnimation.options;
+    var cO = currentAnimation.options;
+
+    // if the exact same CSS class is added/removed then it's safe to cancel it
+    return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass);
+  });
+
+  this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap',
+               '$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow',
+       function($$rAF,   $rootScope,   $rootElement,   $document,   $$HashMap,
+                $$animation,   $$AnimateRunner,   $templateRequest,   $$jqLite,   $$forceReflow) {
+
+    var activeAnimationsLookup = new $$HashMap();
+    var disabledElementsLookup = new $$HashMap();
+    var animationsEnabled = null;
+
+    function postDigestTaskFactory() {
+      var postDigestCalled = false;
+      return function(fn) {
+        // we only issue a call to postDigest before
+        // it has first passed. This prevents any callbacks
+        // from not firing once the animation has completed
+        // since it will be out of the digest cycle.
+        if (postDigestCalled) {
+          fn();
+        } else {
+          $rootScope.$$postDigest(function() {
+            postDigestCalled = true;
+            fn();
+          });
+        }
+      };
+    }
+
+    // Wait until all directive and route-related templates are downloaded and
+    // compiled. The $templateRequest.totalPendingRequests variable keeps track of
+    // all of the remote templates being currently downloaded. If there are no
+    // templates currently downloading then the watcher will still fire anyway.
+    var deregisterWatch = $rootScope.$watch(
+      function() { return $templateRequest.totalPendingRequests === 0; },
+      function(isEmpty) {
+        if (!isEmpty) return;
+        deregisterWatch();
+
+        // Now that all templates have been downloaded, $animate will wait until
+        // the post digest queue is empty before enabling animations. By having two
+        // calls to $postDigest calls we can ensure that the flag is enabled at the
+        // very end of the post digest queue. Since all of the animations in $animate
+        // use $postDigest, it's important that the code below executes at the end.
+        // This basically means that the page is fully downloaded and compiled before
+        // any animations are triggered.
+        $rootScope.$$postDigest(function() {
+          $rootScope.$$postDigest(function() {
+            // we check for null directly in the event that the application already called
+            // .enabled() with whatever arguments that it provided it with
+            if (animationsEnabled === null) {
+              animationsEnabled = true;
+            }
+          });
+        });
+      }
+    );
+
+    var callbackRegistry = {};
+
+    // remember that the classNameFilter is set during the provider/config
+    // stage therefore we can optimize here and setup a helper function
+    var classNameFilter = $animateProvider.classNameFilter();
+    var isAnimatableClassName = !classNameFilter
+              ? function() { return true; }
+              : function(className) {
+                return classNameFilter.test(className);
+              };
+
+    var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
+
+    function normalizeAnimationOptions(element, options) {
+      return mergeAnimationOptions(element, options, {});
+    }
+
+    function findCallbacks(element, event) {
+      var targetNode = getDomNode(element);
+
+      var matches = [];
+      var entries = callbackRegistry[event];
+      if (entries) {
+        forEach(entries, function(entry) {
+          if (entry.node.contains(targetNode)) {
+            matches.push(entry.callback);
+          }
+        });
+      }
+
+      return matches;
+    }
+
+    return {
+      on: function(event, container, callback) {
+        var node = extractElementNode(container);
+        callbackRegistry[event] = callbackRegistry[event] || [];
+        callbackRegistry[event].push({
+          node: node,
+          callback: callback
+        });
+      },
+
+      off: function(event, container, callback) {
+        var entries = callbackRegistry[event];
+        if (!entries) return;
+
+        callbackRegistry[event] = arguments.length === 1
+            ? null
+            : filterFromRegistry(entries, container, callback);
+
+        function filterFromRegistry(list, matchContainer, matchCallback) {
+          var containerNode = extractElementNode(matchContainer);
+          return list.filter(function(entry) {
+            var isMatch = entry.node === containerNode &&
+                            (!matchCallback || entry.callback === matchCallback);
+            return !isMatch;
+          });
+        }
+      },
+
+      pin: function(element, parentElement) {
+        assertArg(isElement(element), 'element', 'not an element');
+        assertArg(isElement(parentElement), 'parentElement', 'not an element');
+        element.data(NG_ANIMATE_PIN_DATA, parentElement);
+      },
+
+      push: function(element, event, options, domOperation) {
+        options = options || {};
+        options.domOperation = domOperation;
+        return queueAnimation(element, event, options);
+      },
+
+      // this method has four signatures:
+      //  () - global getter
+      //  (bool) - global setter
+      //  (element) - element getter
+      //  (element, bool) - element setter<F37>
+      enabled: function(element, bool) {
+        var argCount = arguments.length;
+
+        if (argCount === 0) {
+          // () - Global getter
+          bool = !!animationsEnabled;
+        } else {
+          var hasElement = isElement(element);
+
+          if (!hasElement) {
+            // (bool) - Global setter
+            bool = animationsEnabled = !!element;
+          } else {
+            var node = getDomNode(element);
+            var recordExists = disabledElementsLookup.get(node);
+
+            if (argCount === 1) {
+              // (element) - Element getter
+              bool = !recordExists;
+            } else {
+              // (element, bool) - Element setter
+              bool = !!bool;
+              if (!bool) {
+                disabledElementsLookup.put(node, true);
+              } else if (recordExists) {
+                disabledElementsLookup.remove(node);
+              }
+            }
+          }
+        }
+
+        return bool;
+      }
+    };
+
+    function queueAnimation(element, event, options) {
+      var node, parent;
+      element = stripCommentsFromElement(element);
+      if (element) {
+        node = getDomNode(element);
+        parent = element.parent();
+      }
+
+      options = prepareAnimationOptions(options);
+
+      // we create a fake runner with a working promise.
+      // These methods will become available after the digest has passed
+      var runner = new $$AnimateRunner();
+
+      // this is used to trigger callbacks in postDigest mode
+      var runInNextPostDigestOrNow = postDigestTaskFactory();
+
+      if (isArray(options.addClass)) {
+        options.addClass = options.addClass.join(' ');
+      }
+
+      if (options.addClass && !isString(options.addClass)) {
+        options.addClass = null;
+      }
+
+      if (isArray(options.removeClass)) {
+        options.removeClass = options.removeClass.join(' ');
+      }
+
+      if (options.removeClass && !isString(options.removeClass)) {
+        options.removeClass = null;
+      }
+
+      if (options.from && !isObject(options.from)) {
+        options.from = null;
+      }
+
+      if (options.to && !isObject(options.to)) {
+        options.to = null;
+      }
+
+      // there are situations where a directive issues an animation for
+      // a jqLite wrapper that contains only comment nodes... If this
+      // happens then there is no way we can perform an animation
+      if (!node) {
+        close();
+        return runner;
+      }
+
+      var className = [node.className, options.addClass, options.removeClass].join(' ');
+      if (!isAnimatableClassName(className)) {
+        close();
+        return runner;
+      }
+
+      var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
+
+      // this is a hard disable of all animations for the application or on
+      // the element itself, therefore  there is no need to continue further
+      // past this point if not enabled
+      var skipAnimations = !animationsEnabled || disabledElementsLookup.get(node);
+      var existingAnimation = (!skipAnimations && activeAnimationsLookup.get(node)) || {};
+      var hasExistingAnimation = !!existingAnimation.state;
+
+      // there is no point in traversing the same collection of parent ancestors if a followup
+      // animation will be run on the same element that already did all that checking work
+      if (!skipAnimations && (!hasExistingAnimation || existingAnimation.state != PRE_DIGEST_STATE)) {
+        skipAnimations = !areAnimationsAllowed(element, parent, event);
+      }
+
+      if (skipAnimations) {
+        close();
+        return runner;
+      }
+
+      if (isStructural) {
+        closeChildAnimations(element);
+      }
+
+      var newAnimation = {
+        structural: isStructural,
+        element: element,
+        event: event,
+        close: close,
+        options: options,
+        runner: runner
+      };
+
+      if (hasExistingAnimation) {
+        var skipAnimationFlag = isAllowed('skip', element, newAnimation, existingAnimation);
+        if (skipAnimationFlag) {
+          if (existingAnimation.state === RUNNING_STATE) {
+            close();
+            return runner;
+          } else {
+            mergeAnimationOptions(element, existingAnimation.options, options);
+            return existingAnimation.runner;
+          }
+        }
+
+        var cancelAnimationFlag = isAllowed('cancel', element, newAnimation, existingAnimation);
+        if (cancelAnimationFlag) {
+          if (existingAnimation.state === RUNNING_STATE) {
+            // this will end the animation right away and it is safe
+            // to do so since the animation is already running and the
+            // runner callback code will run in async
+            existingAnimation.runner.end();
+          } else if (existingAnimation.structural) {
+            // this means that the animation is queued into a digest, but
+            // hasn't started yet. Therefore it is safe to run the close
+            // method which will call the runner methods in async.
+            existingAnimation.close();
+          } else {
+            // this will merge the new animation options into existing animation options
+            mergeAnimationOptions(element, existingAnimation.options, newAnimation.options);
+            return existingAnimation.runner;
+          }
+        } else {
+          // a joined animation means that this animation will take over the existing one
+          // so an example would involve a leave animation taking over an enter. Then when
+          // the postDigest kicks in the enter will be ignored.
+          var joinAnimationFlag = isAllowed('join', element, newAnimation, existingAnimation);
+          if (joinAnimationFlag) {
+            if (existingAnimation.state === RUNNING_STATE) {
+              normalizeAnimationOptions(element, options);
+            } else {
+              applyGeneratedPreparationClasses(element, isStructural ? event : null, options);
+
+              event = newAnimation.event = existingAnimation.event;
+              options = mergeAnimationOptions(element, existingAnimation.options, newAnimation.options);
+
+              //we return the same runner since only the option values of this animation will
+              //be fed into the `existingAnimation`.
+              return existingAnimation.runner;
+            }
+          }
+        }
+      } else {
+        // normalization in this case means that it removes redundant CSS classes that
+        // already exist (addClass) or do not exist (removeClass) on the element
+        normalizeAnimationOptions(element, options);
+      }
+
+      // when the options are merged and cleaned up we may end up not having to do
+      // an animation at all, therefore we should check this before issuing a post
+      // digest callback. Structural animations will always run no matter what.
+      var isValidAnimation = newAnimation.structural;
+      if (!isValidAnimation) {
+        // animate (from/to) can be quickly checked first, otherwise we check if any classes are present
+        isValidAnimation = (newAnimation.event === 'animate' && Object.keys(newAnimation.options.to || {}).length > 0)
+                            || hasAnimationClasses(newAnimation.options);
+      }
+
+      if (!isValidAnimation) {
+        close();
+        clearElementAnimationState(element);
+        return runner;
+      }
+
+      // the counter keeps track of cancelled animations
+      var counter = (existingAnimation.counter || 0) + 1;
+      newAnimation.counter = counter;
+
+      markElementAnimationState(element, PRE_DIGEST_STATE, newAnimation);
+
+      $rootScope.$$postDigest(function() {
+        var animationDetails = activeAnimationsLookup.get(node);
+        var animationCancelled = !animationDetails;
+        animationDetails = animationDetails || {};
+
+        // if addClass/removeClass is called before something like enter then the
+        // registered parent element may not be present. The code below will ensure
+        // that a final value for parent element is obtained
+        var parentElement = element.parent() || [];
+
+        // animate/structural/class-based animations all have requirements. Otherwise there
+        // is no point in performing an animation. The parent node must also be set.
+        var isValidAnimation = parentElement.length > 0
+                                && (animationDetails.event === 'animate'
+                                    || animationDetails.structural
+                                    || hasAnimationClasses(animationDetails.options));
+
+        // this means that the previous animation was cancelled
+        // even if the follow-up animation is the same event
+        if (animationCancelled || animationDetails.counter !== counter || !isValidAnimation) {
+          // if another animation did not take over then we need
+          // to make sure that the domOperation and options are
+          // handled accordingly
+          if (animationCancelled) {
+            applyAnimationClasses(element, options);
+            applyAnimationStyles(element, options);
+          }
+
+          // if the event changed from something like enter to leave then we do
+          // it, otherwise if it's the same then the end result will be the same too
+          if (animationCancelled || (isStructural && animationDetails.event !== event)) {
+            options.domOperation();
+            runner.end();
+          }
+
+          // in the event that the element animation was not cancelled or a follow-up animation
+          // isn't allowed to animate from here then we need to clear the state of the element
+          // so that any future animations won't read the expired animation data.
+          if (!isValidAnimation) {
+            clearElementAnimationState(element);
+          }
+
+          return;
+        }
+
+        // this combined multiple class to addClass / removeClass into a setClass event
+        // so long as a structural event did not take over the animation
+        event = !animationDetails.structural && hasAnimationClasses(animationDetails.options, true)
+            ? 'setClass'
+            : animationDetails.event;
+
+        markElementAnimationState(element, RUNNING_STATE);
+        var realRunner = $$animation(element, event, animationDetails.options);
+
+        realRunner.done(function(status) {
+          close(!status);
+          var animationDetails = activeAnimationsLookup.get(node);
+          if (animationDetails && animationDetails.counter === counter) {
+            clearElementAnimationState(getDomNode(element));
+          }
+          notifyProgress(runner, event, 'close', {});
+        });
+
+        // this will update the runner's flow-control events based on
+        // the `realRunner` object.
+        runner.setHost(realRunner);
+        notifyProgress(runner, event, 'start', {});
+      });
+
+      return runner;
+
+      function notifyProgress(runner, event, phase, data) {
+        runInNextPostDigestOrNow(function() {
+          var callbacks = findCallbacks(element, event);
+          if (callbacks.length) {
+            // do not optimize this call here to RAF because
+            // we don't know how heavy the callback code here will
+            // be and if this code is buffered then this can
+            // lead to a performance regression.
+            $$rAF(function() {
+              forEach(callbacks, function(callback) {
+                callback(element, phase, data);
+              });
+            });
+          }
+        });
+        runner.progress(event, phase, data);
+      }
+
+      function close(reject) { // jshint ignore:line
+        clearGeneratedClasses(element, options);
+        applyAnimationClasses(element, options);
+        applyAnimationStyles(element, options);
+        options.domOperation();
+        runner.complete(!reject);
+      }
+    }
+
+    function closeChildAnimations(element) {
+      var node = getDomNode(element);
+      var children = node.querySelectorAll('[' + NG_ANIMATE_ATTR_NAME + ']');
+      forEach(children, function(child) {
+        var state = parseInt(child.getAttribute(NG_ANIMATE_ATTR_NAME));
+        var animationDetails = activeAnimationsLookup.get(child);
+        switch (state) {
+          case RUNNING_STATE:
+            animationDetails.runner.end();
+            /* falls through */
+          case PRE_DIGEST_STATE:
+            if (animationDetails) {
+              activeAnimationsLookup.remove(child);
+            }
+            break;
+        }
+      });
+    }
+
+    function clearElementAnimationState(element) {
+      var node = getDomNode(element);
+      node.removeAttribute(NG_ANIMATE_ATTR_NAME);
+      activeAnimationsLookup.remove(node);
+    }
+
+    function isMatchingElement(nodeOrElmA, nodeOrElmB) {
+      return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
+    }
+
+    function areAnimationsAllowed(element, parentElement, event) {
+      var bodyElement = jqLite($document[0].body);
+      var bodyElementDetected = isMatchingElement(element, bodyElement) || element[0].nodeName === 'HTML';
+      var rootElementDetected = isMatchingElement(element, $rootElement);
+      var parentAnimationDetected = false;
+      var animateChildren;
+
+      var parentHost = element.data(NG_ANIMATE_PIN_DATA);
+      if (parentHost) {
+        parentElement = parentHost;
+      }
+
+      while (parentElement && parentElement.length) {
+        if (!rootElementDetected) {
+          // angular doesn't want to attempt to animate elements outside of the application
+          // therefore we need to ensure that the rootElement is an ancestor of the current element
+          rootElementDetected = isMatchingElement(parentElement, $rootElement);
+        }
+
+        var parentNode = parentElement[0];
+        if (parentNode.nodeType !== ELEMENT_NODE) {
+          // no point in inspecting the #document element
+          break;
+        }
+
+        var details = activeAnimationsLookup.get(parentNode) || {};
+        // either an enter, leave or move animation will commence
+        // therefore we can't allow any animations to take place
+        // but if a parent animation is class-based then that's ok
+        if (!parentAnimationDetected) {
+          parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
+        }
+
+        if (isUndefined(animateChildren) || animateChildren === true) {
+          var value = parentElement.data(NG_ANIMATE_CHILDREN_DATA);
+          if (isDefined(value)) {
+            animateChildren = value;
+          }
+        }
+
+        // there is no need to continue traversing at this point
+        if (parentAnimationDetected && animateChildren === false) break;
+
+        if (!rootElementDetected) {
+          // angular doesn't want to attempt to animate elements outside of the application
+          // therefore we need to ensure that the rootElement is an ancestor of the current element
+          rootElementDetected = isMatchingElement(parentElement, $rootElement);
+          if (!rootElementDetected) {
+            parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);
+            if (parentHost) {
+              parentElement = parentHost;
+            }
+          }
+        }
+
+        if (!bodyElementDetected) {
+          // we also need to ensure that the element is or will be apart of the body element
+          // otherwise it is pointless to even issue an animation to be rendered
+          bodyElementDetected = isMatchingElement(parentElement, bodyElement);
+        }
+
+        parentElement = parentElement.parent();
+      }
+
+      var allowAnimation = !parentAnimationDetected || animateChildren;
+      return allowAnimation && rootElementDetected && bodyElementDetected;
+    }
+
+    function markElementAnimationState(element, state, details) {
+      details = details || {};
+      details.state = state;
+
+      var node = getDomNode(element);
+      node.setAttribute(NG_ANIMATE_ATTR_NAME, state);
+
+      var oldValue = activeAnimationsLookup.get(node);
+      var newValue = oldValue
+          ? extend(oldValue, details)
+          : details;
+      activeAnimationsLookup.put(node, newValue);
+    }
+  }];
+}];
+
+var $$AnimateAsyncRunFactory = ['$$rAF', function($$rAF) {
+  var waitQueue = [];
+
+  function waitForTick(fn) {
+    waitQueue.push(fn);
+    if (waitQueue.length > 1) return;
+    $$rAF(function() {
+      for (var i = 0; i < waitQueue.length; i++) {
+        waitQueue[i]();
+      }
+      waitQueue = [];
+    });
+  }
+
+  return function() {
+    var passed = false;
+    waitForTick(function() {
+      passed = true;
+    });
+    return function(callback) {
+      passed ? callback() : waitForTick(callback);
+    };
+  };
+}];
+
+var $$AnimateRunnerFactory = ['$q', '$sniffer', '$$animateAsyncRun',
+                      function($q,   $sniffer,   $$animateAsyncRun) {
+
+  var INITIAL_STATE = 0;
+  var DONE_PENDING_STATE = 1;
+  var DONE_COMPLETE_STATE = 2;
+
+  AnimateRunner.chain = function(chain, callback) {
+    var index = 0;
+
+    next();
+    function next() {
+      if (index === chain.length) {
+        callback(true);
+        return;
+      }
+
+      chain[index](function(response) {
+        if (response === false) {
+          callback(false);
+          return;
+        }
+        index++;
+        next();
+      });
+    }
+  };
+
+  AnimateRunner.all = function(runners, callback) {
+    var count = 0;
+    var status = true;
+    forEach(runners, function(runner) {
+      runner.done(onProgress);
+    });
+
+    function onProgress(response) {
+      status = status && response;
+      if (++count === runners.length) {
+        callback(status);
+      }
+    }
+  };
+
+  function AnimateRunner(host) {
+    this.setHost(host);
+
+    this._doneCallbacks = [];
+    this._runInAnimationFrame = $$animateAsyncRun();
+    this._state = 0;
+  }
+
+  AnimateRunner.prototype = {
+    setHost: function(host) {
+      this.host = host || {};
+    },
+
+    done: function(fn) {
+      if (this._state === DONE_COMPLETE_STATE) {
+        fn();
+      } else {
+        this._doneCallbacks.push(fn);
+      }
+    },
+
+    progress: noop,
+
+    getPromise: function() {
+      if (!this.promise) {
+        var self = this;
+        this.promise = $q(function(resolve, reject) {
+          self.done(function(status) {
+            status === false ? reject() : resolve();
+          });
+        });
+      }
+      return this.promise;
+    },
+
+    then: function(resolveHandler, rejectHandler) {
+      return this.getPromise().then(resolveHandler, rejectHandler);
+    },
+
+    'catch': function(handler) {
+      return this.getPromise()['catch'](handler);
+    },
+
+    'finally': function(handler) {
+      return this.getPromise()['finally'](handler);
+    },
+
+    pause: function() {
+      if (this.host.pause) {
+        this.host.pause();
+      }
+    },
+
+    resume: function() {
+      if (this.host.resume) {
+        this.host.resume();
+      }
+    },
+
+    end: function() {
+      if (this.host.end) {
+        this.host.end();
+      }
+      this._resolve(true);
+    },
+
+    cancel: function() {
+      if (this.host.cancel) {
+        this.host.cancel();
+      }
+      this._resolve(false);
+    },
+
+    complete: function(response) {
+      var self = this;
+      if (self._state === INITIAL_STATE) {
+        self._state = DONE_PENDING_STATE;
+        self._runInAnimationFrame(function() {
+          self._resolve(response);
+        });
+      }
+    },
+
+    _resolve: function(response) {
+      if (this._state !== DONE_COMPLETE_STATE) {
+        forEach(this._doneCallbacks, function(fn) {
+          fn(response);
+        });
+        this._doneCallbacks.length = 0;
+        this._state = DONE_COMPLETE_STATE;
+      }
+    }
+  };
+
+  return AnimateRunner;
+}];
+
+var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
+  var NG_ANIMATE_REF_ATTR = 'ng-animate-ref';
+
+  var drivers = this.drivers = [];
+
+  var RUNNER_STORAGE_KEY = '$$animationRunner';
+
+  function setRunner(element, runner) {
+    element.data(RUNNER_STORAGE_KEY, runner);
+  }
+
+  function removeRunner(element) {
+    element.removeData(RUNNER_STORAGE_KEY);
+  }
+
+  function getRunner(element) {
+    return element.data(RUNNER_STORAGE_KEY);
+  }
+
+  this.$get = ['$$jqLite', '$rootScope', '$injector', '$$AnimateRunner', '$$HashMap', '$$rAFScheduler',
+       function($$jqLite,   $rootScope,   $injector,   $$AnimateRunner,   $$HashMap,   $$rAFScheduler) {
+
+    var animationQueue = [];
+    var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
+
+    function sortAnimations(animations) {
+      var tree = { children: [] };
+      var i, lookup = new $$HashMap();
+
+      // this is done first beforehand so that the hashmap
+      // is filled with a list of the elements that will be animated
+      for (i = 0; i < animations.length; i++) {
+        var animation = animations[i];
+        lookup.put(animation.domNode, animations[i] = {
+          domNode: animation.domNode,
+          fn: animation.fn,
+          children: []
+        });
+      }
+
+      for (i = 0; i < animations.length; i++) {
+        processNode(animations[i]);
+      }
+
+      return flatten(tree);
+
+      function processNode(entry) {
+        if (entry.processed) return entry;
+        entry.processed = true;
+
+        var elementNode = entry.domNode;
+        var parentNode = elementNode.parentNode;
+        lookup.put(elementNode, entry);
+
+        var parentEntry;
+        while (parentNode) {
+          parentEntry = lookup.get(parentNode);
+          if (parentEntry) {
+            if (!parentEntry.processed) {
+              parentEntry = processNode(parentEntry);
+            }
+            break;
+          }
+          parentNode = parentNode.parentNode;
+        }
+
+        (parentEntry || tree).children.push(entry);
+        return entry;
+      }
+
+      function flatten(tree) {
+        var result = [];
+        var queue = [];
+        var i;
+
+        for (i = 0; i < tree.children.length; i++) {
+          queue.push(tree.children[i]);
+        }
+
+        var remainingLevelEntries = queue.length;
+        var nextLevelEntries = 0;
+        var row = [];
+
+        for (i = 0; i < queue.length; i++) {
+          var entry = queue[i];
+          if (remainingLevelEntries <= 0) {
+            remainingLevelEntries = nextLevelEntries;
+            nextLevelEntries = 0;
+            result.push(row);
+            row = [];
+          }
+          row.push(entry.fn);
+          entry.children.forEach(function(childEntry) {
+            nextLevelEntries++;
+            queue.push(childEntry);
+          });
+          remainingLevelEntries--;
+        }
+
+        if (row.length) {
+          result.push(row);
+        }
+
+        return result;
+      }
+    }
+
+    // TODO(matsko): document the signature in a better way
+    return function(element, event, options) {
+      options = prepareAnimationOptions(options);
+      var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
+
+      // there is no animation at the current moment, however
+      // these runner methods will get later updated with the
+      // methods leading into the driver's end/cancel methods
+      // for now they just stop the animation from starting
+      var runner = new $$AnimateRunner({
+        end: function() { close(); },
+        cancel: function() { close(true); }
+      });
+
+      if (!drivers.length) {
+        close();
+        return runner;
+      }
+
+      setRunner(element, runner);
+
+      var classes = mergeClasses(element.attr('class'), mergeClasses(options.addClass, options.removeClass));
+      var tempClasses = options.tempClasses;
+      if (tempClasses) {
+        classes += ' ' + tempClasses;
+        options.tempClasses = null;
+      }
+
+      animationQueue.push({
+        // this data is used by the postDigest code and passed into
+        // the driver step function
+        element: element,
+        classes: classes,
+        event: event,
+        structural: isStructural,
+        options: options,
+        beforeStart: beforeStart,
+        close: close
+      });
+
+      element.on('$destroy', handleDestroyedElement);
+
+      // we only want there to be one function called within the post digest
+      // block. This way we can group animations for all the animations that
+      // were apart of the same postDigest flush call.
+      if (animationQueue.length > 1) return runner;
+
+      $rootScope.$$postDigest(function() {
+        var animations = [];
+        forEach(animationQueue, function(entry) {
+          // the element was destroyed early on which removed the runner
+          // form its storage. This means we can't animate this element
+          // at all and it already has been closed due to destruction.
+          if (getRunner(entry.element)) {
+            animations.push(entry);
+          } else {
+            entry.close();
+          }
+        });
+
+        // now any future animations will be in another postDigest
+        animationQueue.length = 0;
+
+        var groupedAnimations = groupAnimations(animations);
+        var toBeSortedAnimations = [];
+
+        forEach(groupedAnimations, function(animationEntry) {
+          toBeSortedAnimations.push({
+            domNode: getDomNode(animationEntry.from ? animationEntry.from.element : animationEntry.element),
+            fn: function triggerAnimationStart() {
+              // it's important that we apply the `ng-animate` CSS class and the
+              // temporary classes before we do any driver invoking since these
+              // CSS classes may be required for proper CSS detection.
+              animationEntry.beforeStart();
+
+              var startAnimationFn, closeFn = animationEntry.close;
+
+              // in the event that the element was removed before the digest runs or
+              // during the RAF sequencing then we should not trigger the animation.
+              var targetElement = animationEntry.anchors
+                  ? (animationEntry.from.element || animationEntry.to.element)
+                  : animationEntry.element;
+
+              if (getRunner(targetElement)) {
+                var operation = invokeFirstDriver(animationEntry);
+                if (operation) {
+                  startAnimationFn = operation.start;
+                }
+              }
+
+              if (!startAnimationFn) {
+                closeFn();
+              } else {
+                var animationRunner = startAnimationFn();
+                animationRunner.done(function(status) {
+                  closeFn(!status);
+                });
+                updateAnimationRunners(animationEntry, animationRunner);
+              }
+            }
+          });
+        });
+
+        // we need to sort each of the animations in order of parent to child
+        // relationships. This ensures that the child classes are applied at the
+        // right time.
+        $$rAFScheduler(sortAnimations(toBeSortedAnimations));
+      });
+
+      return runner;
+
+      // TODO(matsko): change to reference nodes
+      function getAnchorNodes(node) {
+        var SELECTOR = '[' + NG_ANIMATE_REF_ATTR + ']';
+        var items = node.hasAttribute(NG_ANIMATE_REF_ATTR)
+              ? [node]
+              : node.querySelectorAll(SELECTOR);
+        var anchors = [];
+        forEach(items, function(node) {
+          var attr = node.getAttribute(NG_ANIMATE_REF_ATTR);
+          if (attr && attr.length) {
+            anchors.push(node);
+          }
+        });
+        return anchors;
+      }
+
+      function groupAnimations(animations) {
+        var preparedAnimations = [];
+        var refLookup = {};
+        forEach(animations, function(animation, index) {
+          var element = animation.element;
+          var node = getDomNode(element);
+          var event = animation.event;
+          var enterOrMove = ['enter', 'move'].indexOf(event) >= 0;
+          var anchorNodes = animation.structural ? getAnchorNodes(node) : [];
+
+          if (anchorNodes.length) {
+            var direction = enterOrMove ? 'to' : 'from';
+
+            forEach(anchorNodes, function(anchor) {
+              var key = anchor.getAttribute(NG_ANIMATE_REF_ATTR);
+              refLookup[key] = refLookup[key] || {};
+              refLookup[key][direction] = {
+                animationID: index,
+                element: jqLite(anchor)
+              };
+            });
+          } else {
+            preparedAnimations.push(animation);
+          }
+        });
+
+        var usedIndicesLookup = {};
+        var anchorGroups = {};
+        forEach(refLookup, function(operations, key) {
+          var from = operations.from;
+          var to = operations.to;
+
+          if (!from || !to) {
+            // only one of these is set therefore we can't have an
+            // anchor animation since all three pieces are required
+            var index = from ? from.animationID : to.animationID;
+            var indexKey = index.toString();
+            if (!usedIndicesLookup[indexKey]) {
+              usedIndicesLookup[indexKey] = true;
+              preparedAnimations.push(animations[index]);
+            }
+            return;
+          }
+
+          var fromAnimation = animations[from.animationID];
+          var toAnimation = animations[to.animationID];
+          var lookupKey = from.animationID.toString();
+          if (!anchorGroups[lookupKey]) {
+            var group = anchorGroups[lookupKey] = {
+              structural: true,
+              beforeStart: function() {
+                fromAnimation.beforeStart();
+                toAnimation.beforeStart();
+              },
+              close: function() {
+                fromAnimation.close();
+                toAnimation.close();
+              },
+              classes: cssClassesIntersection(fromAnimation.classes, toAnimation.classes),
+              from: fromAnimation,
+              to: toAnimation,
+              anchors: [] // TODO(matsko): change to reference nodes
+            };
+
+            // the anchor animations require that the from and to elements both have at least
+            // one shared CSS class which effictively marries the two elements together to use
+            // the same animation driver and to properly sequence the anchor animation.
+            if (group.classes.length) {
+              preparedAnimations.push(group);
+            } else {
+              preparedAnimations.push(fromAnimation);
+              preparedAnimations.push(toAnimation);
+            }
+          }
+
+          anchorGroups[lookupKey].anchors.push({
+            'out': from.element, 'in': to.element
+          });
+        });
+
+        return preparedAnimations;
+      }
+
+      function cssClassesIntersection(a,b) {
+        a = a.split(' ');
+        b = b.split(' ');
+        var matches = [];
+
+        for (var i = 0; i < a.length; i++) {
+          var aa = a[i];
+          if (aa.substring(0,3) === 'ng-') continue;
+
+          for (var j = 0; j < b.length; j++) {
+            if (aa === b[j]) {
+              matches.push(aa);
+              break;
+            }
+          }
+        }
+
+        return matches.join(' ');
+      }
+
+      function invokeFirstDriver(animationDetails) {
+        // we loop in reverse order since the more general drivers (like CSS and JS)
+        // may attempt more elements, but custom drivers are more particular
+        for (var i = drivers.length - 1; i >= 0; i--) {
+          var driverName = drivers[i];
+          if (!$injector.has(driverName)) continue; // TODO(matsko): remove this check
+
+          var factory = $injector.get(driverName);
+          var driver = factory(animationDetails);
+          if (driver) {
+            return driver;
+          }
+        }
+      }
+
+      function beforeStart() {
+        element.addClass(NG_ANIMATE_CLASSNAME);
+        if (tempClasses) {
+          $$jqLite.addClass(element, tempClasses);
+        }
+      }
+
+      function updateAnimationRunners(animation, newRunner) {
+        if (animation.from && animation.to) {
+          update(animation.from.element);
+          update(animation.to.element);
+        } else {
+          update(animation.element);
+        }
+
+        function update(element) {
+          getRunner(element).setHost(newRunner);
+        }
+      }
+
+      function handleDestroyedElement() {
+        var runner = getRunner(element);
+        if (runner && (event !== 'leave' || !options.$$domOperationFired)) {
+          runner.end();
+        }
+      }
+
+      function close(rejected) { // jshint ignore:line
+        element.off('$destroy', handleDestroyedElement);
+        removeRunner(element);
+
+        applyAnimationClasses(element, options);
+        applyAnimationStyles(element, options);
+        options.domOperation();
+
+        if (tempClasses) {
+          $$jqLite.removeClass(element, tempClasses);
+        }
+
+        element.removeClass(NG_ANIMATE_CLASSNAME);
+        runner.complete(!rejected);
+      }
+    };
+  }];
+}];
+
+/* global angularAnimateModule: true,
+
+   $$AnimateAsyncRunFactory,
+   $$rAFSchedulerFactory,
+   $$AnimateChildrenDirective,
+   $$AnimateRunnerFactory,
+   $$AnimateQueueProvider,
+   $$AnimationProvider,
+   $AnimateCssProvider,
+   $$AnimateCssDriverProvider,
+   $$AnimateJsProvider,
+   $$AnimateJsDriverProvider,
+*/
+
+/**
+ * @ngdoc module
+ * @name ngAnimate
+ * @description
+ *
+ * The `ngAnimate` module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via
+ * callback hooks. Animations are not enabled by default, however, by including `ngAnimate` the animation hooks are enabled for an Angular app.
+ *
+ * <div doc-module-components="ngAnimate"></div>
+ *
+ * # Usage
+ * Simply put, there are two ways to make use of animations when ngAnimate is used: by using **CSS** and **JavaScript**. The former works purely based
+ * using CSS (by using matching CSS selectors/styles) and the latter triggers animations that are registered via `module.animation()`. For
+ * both CSS and JS animations the sole requirement is to have a matching `CSS class` that exists both in the registered animation and within
+ * the HTML element that the animation will be triggered on.
+ *
+ * ## Directive Support
+ * The following directives are "animation aware":
+ *
+ * | Directive                                                                                                | Supported Animations                                                     |
+ * |----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
+ * | {@link ng.directive:ngRepeat#animations ngRepeat}                                                        | enter, leave and move                                                    |
+ * | {@link ngRoute.directive:ngView#animations ngView}                                                       | enter and leave                                                          |
+ * | {@link ng.directive:ngInclude#animations ngInclude}                                                      | enter and leave                                                          |
+ * | {@link ng.directive:ngSwitch#animations ngSwitch}                                                        | enter and leave                                                          |
+ * | {@link ng.directive:ngIf#animations ngIf}                                                                | enter and leave                                                          |
+ * | {@link ng.directive:ngClass#animations ngClass}                                                          | add and remove (the CSS class(es) present)                               |
+ * | {@link ng.directive:ngShow#animations ngShow} & {@link ng.directive:ngHide#animations ngHide}            | add and remove (the ng-hide class value)                                 |
+ * | {@link ng.directive:form#animation-hooks form} & {@link ng.directive:ngModel#animation-hooks ngModel}    | add and remove (dirty, pristine, valid, invalid & all other validations) |
+ * | {@link module:ngMessages#animations ngMessages}                                                          | add and remove (ng-active & ng-inactive)                                 |
+ * | {@link module:ngMessages#animations ngMessage}                                                           | enter and leave                                                          |
+ *
+ * (More information can be found by visiting each the documentation associated with each directive.)
+ *
+ * ## CSS-based Animations
+ *
+ * CSS-based animations with ngAnimate are unique since they require no JavaScript code at all. By using a CSS class that we reference between our HTML
+ * and CSS code we can create an animation that will be picked up by Angular when an the underlying directive performs an operation.
+ *
+ * The example below shows how an `enter` animation can be made possible on an element using `ng-if`:
+ *
+ * ```html
+ * <div ng-if="bool" class="fade">
+ *    Fade me in out
+ * </div>
+ * <button ng-click="bool=true">Fade In!</button>
+ * <button ng-click="bool=false">Fade Out!</button>
+ * ```
+ *
+ * Notice the CSS class **fade**? We can now create the CSS transition code that references this class:
+ *
+ * ```css
+ * /&#42; The starting CSS styles for the enter animation &#42;/
+ * .fade.ng-enter {
+ *   transition:0.5s linear all;
+ *   opacity:0;
+ * }
+ *
+ * /&#42; The finishing CSS styles for the enter animation &#42;/
+ * .fade.ng-enter.ng-enter-active {
+ *   opacity:1;
+ * }
+ * ```
+ *
+ * The key thing to remember here is that, depending on the animation event (which each of the directives above trigger depending on what's going on) two
+ * generated CSS classes will be applied to the element; in the example above we have `.ng-enter` and `.ng-enter-active`. For CSS transitions, the transition
+ * code **must** be defined within the starting CSS class (in this case `.ng-enter`). The destination class is what the transition will animate towards.
+ *
+ * If for example we wanted to create animations for `leave` and `move` (ngRepeat triggers move) then we can do so using the same CSS naming conventions:
+ *
+ * ```css
+ * /&#42; now the element will fade out before it is removed from the DOM &#42;/
+ * .fade.ng-leave {
+ *   transition:0.5s linear all;
+ *   opacity:1;
+ * }
+ * .fade.ng-leave.ng-leave-active {
+ *   opacity:0;
+ * }
+ * ```
+ *
+ * We can also make use of **CSS Keyframes** by referencing the keyframe animation within the starting CSS class:
+ *
+ * ```css
+ * /&#42; there is no need to define anything inside of the destination
+ * CSS class since the keyframe will take charge of the animation &#42;/
+ * .fade.ng-leave {
+ *   animation: my_fade_animation 0.5s linear;
+ *   -webkit-animation: my_fade_animation 0.5s linear;
+ * }
+ *
+ * @keyframes my_fade_animation {
+ *   from { opacity:1; }
+ *   to { opacity:0; }
+ * }
+ *
+ * @-webkit-keyframes my_fade_animation {
+ *   from { opacity:1; }
+ *   to { opacity:0; }
+ * }
+ * ```
+ *
+ * Feel free also mix transitions and keyframes together as well as any other CSS classes on the same element.
+ *
+ * ### CSS Class-based Animations
+ *
+ * Class-based animations (animations that are triggered via `ngClass`, `ngShow`, `ngHide` and some other directives) have a slightly different
+ * naming convention. Class-based animations are basic enough that a standard transition or keyframe can be referenced on the class being added
+ * and removed.
+ *
+ * For example if we wanted to do a CSS animation for `ngHide` then we place an animation on the `.ng-hide` CSS class:
+ *
+ * ```html
+ * <div ng-show="bool" class="fade">
+ *   Show and hide me
+ * </div>
+ * <button ng-click="bool=true">Toggle</button>
+ *
+ * <style>
+ * .fade.ng-hide {
+ *   transition:0.5s linear all;
+ *   opacity:0;
+ * }
+ * </style>
+ * ```
+ *
+ * All that is going on here with ngShow/ngHide behind the scenes is the `.ng-hide` class is added/removed (when the hidden state is valid). Since
+ * ngShow and ngHide are animation aware then we can match up a transition and ngAnimate handles the rest.
+ *
+ * In addition the addition and removal of the CSS class, ngAnimate also provides two helper methods that we can use to further decorate the animation
+ * with CSS styles.
+ *
+ * ```html
+ * <div ng-class="{on:onOff}" class="highlight">
+ *   Highlight this box
+ * </div>
+ * <button ng-click="onOff=!onOff">Toggle</button>
+ *
+ * <style>
+ * .highlight {
+ *   transition:0.5s linear all;
+ * }
+ * .highlight.on-add {
+ *   background:white;
+ * }
+ * .highlight.on {
+ *   background:yellow;
+ * }
+ * .highlight.on-remove {
+ *   background:black;
+ * }
+ * </style>
+ * ```
+ *
+ * We can also make use of CSS keyframes by placing them within the CSS classes.
+ *
+ *
+ * ### CSS Staggering Animations
+ * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
+ * curtain-like effect. The ngAnimate module (versions >=1.2) supports staggering animations and the stagger effect can be
+ * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
+ * the animation. The style property expected within the stagger class can either be a **transition-delay** or an
+ * **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
+ *
+ * ```css
+ * .my-animation.ng-enter {
+ *   /&#42; standard transition code &#42;/
+ *   transition: 1s linear all;
+ *   opacity:0;
+ * }
+ * .my-animation.ng-enter-stagger {
+ *   /&#42; this will have a 100ms delay between each successive leave animation &#42;/
+ *   transition-delay: 0.1s;
+ *
+ *   /&#42; As of 1.4.4, this must always be set: it signals ngAnimate
+ *     to not accidentally inherit a delay property from another CSS class &#42;/
+ *   transition-duration: 0s;
+ * }
+ * .my-animation.ng-enter.ng-enter-active {
+ *   /&#42; standard transition styles &#42;/
+ *   opacity:1;
+ * }
+ * ```
+ *
+ * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
+ * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
+ * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
+ * will also be reset if one or more animation frames have passed since the multiple calls to `$animate` were fired.
+ *
+ * The following code will issue the **ng-leave-stagger** event on the element provided:
+ *
+ * ```js
+ * var kids = parent.children();
+ *
+ * $animate.leave(kids[0]); //stagger index=0
+ * $animate.leave(kids[1]); //stagger index=1
+ * $animate.leave(kids[2]); //stagger index=2
+ * $animate.leave(kids[3]); //stagger index=3
+ * $animate.leave(kids[4]); //stagger index=4
+ *
+ * window.requestAnimationFrame(function() {
+ *   //stagger has reset itself
+ *   $animate.leave(kids[5]); //stagger index=0
+ *   $animate.leave(kids[6]); //stagger index=1
+ *
+ *   $scope.$digest();
+ * });
+ * ```
+ *
+ * Stagger animations are currently only supported within CSS-defined animations.
+ *
+ * ### The `ng-animate` CSS class
+ *
+ * When ngAnimate is animating an element it will apply the `ng-animate` CSS class to the element for the duration of the animation.
+ * This is a temporary CSS class and it will be removed once the animation is over (for both JavaScript and CSS-based animations).
+ *
+ * Therefore, animations can be applied to an element using this temporary class directly via CSS.
+ *
+ * ```css
+ * .zipper.ng-animate {
+ *   transition:0.5s linear all;
+ * }
+ * .zipper.ng-enter {
+ *   opacity:0;
+ * }
+ * .zipper.ng-enter.ng-enter-active {
+ *   opacity:1;
+ * }
+ * .zipper.ng-leave {
+ *   opacity:1;
+ * }
+ * .zipper.ng-leave.ng-leave-active {
+ *   opacity:0;
+ * }
+ * ```
+ *
+ * (Note that the `ng-animate` CSS class is reserved and it cannot be applied on an element directly since ngAnimate will always remove
+ * the CSS class once an animation has completed.)
+ *
+ *
+ * ## JavaScript-based Animations
+ *
+ * ngAnimate also allows for animations to be consumed by JavaScript code. The approach is similar to CSS-based animations (where there is a shared
+ * CSS class that is referenced in our HTML code) but in addition we need to register the JavaScript animation on the module. By making use of the
+ * `module.animation()` module function we can register the ainmation.
+ *
+ * Let's see an example of a enter/leave animation using `ngRepeat`:
+ *
+ * ```html
+ * <div ng-repeat="item in items" class="slide">
+ *   {{ item }}
+ * </div>
+ * ```
+ *
+ * See the **slide** CSS class? Let's use that class to define an animation that we'll structure in our module code by using `module.animation`:
+ *
+ * ```js
+ * myModule.animation('.slide', [function() {
+ *   return {
+ *     // make note that other events (like addClass/removeClass)
+ *     // have different function input parameters
+ *     enter: function(element, doneFn) {
+ *       jQuery(element).fadeIn(1000, doneFn);
+ *
+ *       // remember to call doneFn so that angular
+ *       // knows that the animation has concluded
+ *     },
+ *
+ *     move: function(element, doneFn) {
+ *       jQuery(element).fadeIn(1000, doneFn);
+ *     },
+ *
+ *     leave: function(element, doneFn) {
+ *       jQuery(element).fadeOut(1000, doneFn);
+ *     }
+ *   }
+ * }]
+ * ```
+ *
+ * The nice thing about JS-based animations is that we can inject other services and make use of advanced animation libraries such as
+ * greensock.js and velocity.js.
+ *
+ * If our animation code class-based (meaning that something like `ngClass`, `ngHide` and `ngShow` triggers it) then we can still define
+ * our animations inside of the same registered animation, however, the function input arguments are a bit different:
+ *
+ * ```html
+ * <div ng-class="color" class="colorful">
+ *   this box is moody
+ * </div>
+ * <button ng-click="color='red'">Change to red</button>
+ * <button ng-click="color='blue'">Change to blue</button>
+ * <button ng-click="color='green'">Change to green</button>
+ * ```
+ *
+ * ```js
+ * myModule.animation('.colorful', [function() {
+ *   return {
+ *     addClass: function(element, className, doneFn) {
+ *       // do some cool animation and call the doneFn
+ *     },
+ *     removeClass: function(element, className, doneFn) {
+ *       // do some cool animation and call the doneFn
+ *     },
+ *     setClass: function(element, addedClass, removedClass, doneFn) {
+ *       // do some cool animation and call the doneFn
+ *     }
+ *   }
+ * }]
+ * ```
+ *
+ * ## CSS + JS Animations Together
+ *
+ * AngularJS 1.4 and higher has taken steps to make the amalgamation of CSS and JS animations more flexible. However, unlike earlier versions of Angular,
+ * defining CSS and JS animations to work off of the same CSS class will not work anymore. Therefore the example below will only result in **JS animations taking
+ * charge of the animation**:
+ *
+ * ```html
+ * <div ng-if="bool" class="slide">
+ *   Slide in and out
+ * </div>
+ * ```
+ *
+ * ```js
+ * myModule.animation('.slide', [function() {
+ *   return {
+ *     enter: function(element, doneFn) {
+ *       jQuery(element).slideIn(1000, doneFn);
+ *     }
+ *   }
+ * }]
+ * ```
+ *
+ * ```css
+ * .slide.ng-enter {
+ *   transition:0.5s linear all;
+ *   transform:translateY(-100px);
+ * }
+ * .slide.ng-enter.ng-enter-active {
+ *   transform:translateY(0);
+ * }
+ * ```
+ *
+ * Does this mean that CSS and JS animations cannot be used together? Do JS-based animations always have higher priority? We can make up for the
+ * lack of CSS animations by using the `$animateCss` service to trigger our own tweaked-out, CSS-based animations directly from
+ * our own JS-based animation code:
+ *
+ * ```js
+ * myModule.animation('.slide', ['$animateCss', function($animateCss) {
+ *   return {
+ *     enter: function(element, doneFn) {
+*        // this will trigger `.slide.ng-enter` and `.slide.ng-enter-active`.
+ *       var runner = $animateCss(element, {
+ *         event: 'enter',
+ *         structural: true
+ *       }).start();
+*        runner.done(doneFn);
+ *     }
+ *   }
+ * }]
+ * ```
+ *
+ * The nice thing here is that we can save bandwidth by sticking to our CSS-based animation code and we don't need to rely on a 3rd-party animation framework.
+ *
+ * The `$animateCss` service is very powerful since we can feed in all kinds of extra properties that will be evaluated and fed into a CSS transition or
+ * keyframe animation. For example if we wanted to animate the height of an element while adding and removing classes then we can do so by providing that
+ * data into `$animateCss` directly:
+ *
+ * ```js
+ * myModule.animation('.slide', ['$animateCss', function($animateCss) {
+ *   return {
+ *     enter: function(element, doneFn) {
+ *       var runner = $animateCss(element, {
+ *         event: 'enter',
+ *         structural: true,
+ *         addClass: 'maroon-setting',
+ *         from: { height:0 },
+ *         to: { height: 200 }
+ *       }).start();
+ *
+ *       runner.done(doneFn);
+ *     }
+ *   }
+ * }]
+ * ```
+ *
+ * Now we can fill in the rest via our transition CSS code:
+ *
+ * ```css
+ * /&#42; the transition tells ngAnimate to make the animation happen &#42;/
+ * .slide.ng-enter { transition:0.5s linear all; }
+ *
+ * /&#42; this extra CSS class will be absorbed into the transition
+ * since the $animateCss code is adding the class &#42;/
+ * .maroon-setting { background:red; }
+ * ```
+ *
+ * And `$animateCss` will figure out the rest. Just make sure to have the `done()` callback fire the `doneFn` function to signal when the animation is over.
+ *
+ * To learn more about what's possible be sure to visit the {@link ngAnimate.$animateCss $animateCss service}.
+ *
+ * ## Animation Anchoring (via `ng-animate-ref`)
+ *
+ * ngAnimate in AngularJS 1.4 comes packed with the ability to cross-animate elements between
+ * structural areas of an application (like views) by pairing up elements using an attribute
+ * called `ng-animate-ref`.
+ *
+ * Let's say for example we have two views that are managed by `ng-view` and we want to show
+ * that there is a relationship between two components situated in within these views. By using the
+ * `ng-animate-ref` attribute we can identify that the two components are paired together and we
+ * can then attach an animation, which is triggered when the view changes.
+ *
+ * Say for example we have the following template code:
+ *
+ * ```html
+ * <!-- index.html -->
+ * <div ng-view class="view-animation">
+ * </div>
+ *
+ * <!-- home.html -->
+ * <a href="#/banner-page">
+ *   <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
+ * </a>
+ *
+ * <!-- banner-page.html -->
+ * <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
+ * ```
+ *
+ * Now, when the view changes (once the link is clicked), ngAnimate will examine the
+ * HTML contents to see if there is a match reference between any components in the view
+ * that is leaving and the view that is entering. It will scan both the view which is being
+ * removed (leave) and inserted (enter) to see if there are any paired DOM elements that
+ * contain a matching ref value.
+ *
+ * The two images match since they share the same ref value. ngAnimate will now create a
+ * transport element (which is a clone of the first image element) and it will then attempt
+ * to animate to the position of the second image element in the next view. For the animation to
+ * work a special CSS class called `ng-anchor` will be added to the transported element.
+ *
+ * We can now attach a transition onto the `.banner.ng-anchor` CSS class and then
+ * ngAnimate will handle the entire transition for us as well as the addition and removal of
+ * any changes of CSS classes between the elements:
+ *
+ * ```css
+ * .banner.ng-anchor {
+ *   /&#42; this animation will last for 1 second since there are
+ *          two phases to the animation (an `in` and an `out` phase) &#42;/
+ *   transition:0.5s linear all;
+ * }
+ * ```
+ *
+ * We also **must** include animations for the views that are being entered and removed
+ * (otherwise anchoring wouldn't be possible since the new view would be inserted right away).
+ *
+ * ```css
+ * .view-animation.ng-enter, .view-animation.ng-leave {
+ *   transition:0.5s linear all;
+ *   position:fixed;
+ *   left:0;
+ *   top:0;
+ *   width:100%;
+ * }
+ * .view-animation.ng-enter {
+ *   transform:translateX(100%);
+ * }
+ * .view-animation.ng-leave,
+ * .view-animation.ng-enter.ng-enter-active {
+ *   transform:translateX(0%);
+ * }
+ * .view-animation.ng-leave.ng-leave-active {
+ *   transform:translateX(-100%);
+ * }
+ * ```
+ *
+ * Now we can jump back to the anchor animation. When the animation happens, there are two stages that occur:
+ * an `out` and an `in` stage. The `out` stage happens first and that is when the element is animated away
+ * from its origin. Once that animation is over then the `in` stage occurs which animates the
+ * element to its destination. The reason why there are two animations is to give enough time
+ * for the enter animation on the new element to be ready.
+ *
+ * The example above sets up a transition for both the in and out phases, but we can also target the out or
+ * in phases directly via `ng-anchor-out` and `ng-anchor-in`.
+ *
+ * ```css
+ * .banner.ng-anchor-out {
+ *   transition: 0.5s linear all;
+ *
+ *   /&#42; the scale will be applied during the out animation,
+ *          but will be animated away when the in animation runs &#42;/
+ *   transform: scale(1.2);
+ * }
+ *
+ * .banner.ng-anchor-in {
+ *   transition: 1s linear all;
+ * }
+ * ```
+ *
+ *
+ *
+ *
+ * ### Anchoring Demo
+ *
+  <example module="anchoringExample"
+           name="anchoringExample"
+           id="anchoringExample"
+           deps="angular-animate.js;angular-route.js"
+           animations="true">
+    <file name="index.html">
+      <a href="#/">Home</a>
+      <hr />
+      <div class="view-container">
+        <div ng-view class="view"></div>
+      </div>
+    </file>
+    <file name="script.js">
+      angular.module('anchoringExample', ['ngAnimate', 'ngRoute'])
+        .config(['$routeProvider', function($routeProvider) {
+          $routeProvider.when('/', {
+            templateUrl: 'home.html',
+            controller: 'HomeController as home'
+          });
+          $routeProvider.when('/profile/:id', {
+            templateUrl: 'profile.html',
+            controller: 'ProfileController as profile'
+          });
+        }])
+        .run(['$rootScope', function($rootScope) {
+          $rootScope.records = [
+            { id:1, title: "Miss Beulah Roob" },
+            { id:2, title: "Trent Morissette" },
+            { id:3, title: "Miss Ava Pouros" },
+            { id:4, title: "Rod Pouros" },
+            { id:5, title: "Abdul Rice" },
+            { id:6, title: "Laurie Rutherford Sr." },
+            { id:7, title: "Nakia McLaughlin" },
+            { id:8, title: "Jordon Blanda DVM" },
+            { id:9, title: "Rhoda Hand" },
+            { id:10, title: "Alexandrea Sauer" }
+          ];
+        }])
+        .controller('HomeController', [function() {
+          //empty
+        }])
+        .controller('ProfileController', ['$rootScope', '$routeParams', function($rootScope, $routeParams) {
+          var index = parseInt($routeParams.id, 10);
+          var record = $rootScope.records[index - 1];
+
+          this.title = record.title;
+          this.id = record.id;
+        }]);
+    </file>
+    <file name="home.html">
+      <h2>Welcome to the home page</h1>
+      <p>Please click on an element</p>
+      <a class="record"
+         ng-href="#/profile/{{ record.id }}"
+         ng-animate-ref="{{ record.id }}"
+         ng-repeat="record in records">
+        {{ record.title }}
+      </a>
+    </file>
+    <file name="profile.html">
+      <div class="profile record" ng-animate-ref="{{ profile.id }}">
+        {{ profile.title }}
+      </div>
+    </file>
+    <file name="animations.css">
+      .record {
+        display:block;
+        font-size:20px;
+      }
+      .profile {
+        background:black;
+        color:white;
+        font-size:100px;
+      }
+      .view-container {
+        position:relative;
+      }
+      .view-container > .view.ng-animate {
+        position:absolute;
+        top:0;
+        left:0;
+        width:100%;
+        min-height:500px;
+      }
+      .view.ng-enter, .view.ng-leave,
+      .record.ng-anchor {
+        transition:0.5s linear all;
+      }
+      .view.ng-enter {
+        transform:translateX(100%);
+      }
+      .view.ng-enter.ng-enter-active, .view.ng-leave {
+        transform:translateX(0%);
+      }
+      .view.ng-leave.ng-leave-active {
+        transform:translateX(-100%);
+      }
+      .record.ng-anchor-out {
+        background:red;
+      }
+    </file>
+  </example>
+ *
+ * ### How is the element transported?
+ *
+ * When an anchor animation occurs, ngAnimate will clone the starting element and position it exactly where the starting
+ * element is located on screen via absolute positioning. The cloned element will be placed inside of the root element
+ * of the application (where ng-app was defined) and all of the CSS classes of the starting element will be applied. The
+ * element will then animate into the `out` and `in` animations and will eventually reach the coordinates and match
+ * the dimensions of the destination element. During the entire animation a CSS class of `.ng-animate-shim` will be applied
+ * to both the starting and destination elements in order to hide them from being visible (the CSS styling for the class
+ * is: `visibility:hidden`). Once the anchor reaches its destination then it will be removed and the destination element
+ * will become visible since the shim class will be removed.
+ *
+ * ### How is the morphing handled?
+ *
+ * CSS Anchoring relies on transitions and keyframes and the internal code is intelligent enough to figure out
+ * what CSS classes differ between the starting element and the destination element. These different CSS classes
+ * will be added/removed on the anchor element and a transition will be applied (the transition that is provided
+ * in the anchor class). Long story short, ngAnimate will figure out what classes to add and remove which will
+ * make the transition of the element as smooth and automatic as possible. Be sure to use simple CSS classes that
+ * do not rely on DOM nesting structure so that the anchor element appears the same as the starting element (since
+ * the cloned element is placed inside of root element which is likely close to the body element).
+ *
+ * Note that if the root element is on the `<html>` element then the cloned node will be placed inside of body.
+ *
+ *
+ * ## Using $animate in your directive code
+ *
+ * So far we've explored how to feed in animations into an Angular application, but how do we trigger animations within our own directives in our application?
+ * By injecting the `$animate` service into our directive code, we can trigger structural and class-based hooks which can then be consumed by animations. Let's
+ * imagine we have a greeting box that shows and hides itself when the data changes
+ *
+ * ```html
+ * <greeting-box active="onOrOff">Hi there</greeting-box>
+ * ```
+ *
+ * ```js
+ * ngModule.directive('greetingBox', ['$animate', function($animate) {
+ *   return function(scope, element, attrs) {
+ *     attrs.$observe('active', function(value) {
+ *       value ? $animate.addClass(element, 'on') : $animate.removeClass(element, 'on');
+ *     });
+ *   });
+ * }]);
+ * ```
+ *
+ * Now the `on` CSS class is added and removed on the greeting box component. Now if we add a CSS class on top of the greeting box element
+ * in our HTML code then we can trigger a CSS or JS animation to happen.
+ *
+ * ```css
+ * /&#42; normally we would create a CSS class to reference on the element &#42;/
+ * greeting-box.on { transition:0.5s linear all; background:green; color:white; }
+ * ```
+ *
+ * The `$animate` service contains a variety of other methods like `enter`, `leave`, `animate` and `setClass`. To learn more about what's
+ * possible be sure to visit the {@link ng.$animate $animate service API page}.
+ *
+ *
+ * ### Preventing Collisions With Third Party Libraries
+ *
+ * Some third-party frameworks place animation duration defaults across many element or className
+ * selectors in order to make their code small and reuseable. This can lead to issues with ngAnimate, which
+ * is expecting actual animations on these elements and has to wait for their completion.
+ *
+ * You can prevent this unwanted behavior by using a prefix on all your animation classes:
+ *
+ * ```css
+ * /&#42; prefixed with animate- &#42;/
+ * .animate-fade-add.animate-fade-add-active {
+ *   transition:1s linear all;
+ *   opacity:0;
+ * }
+ * ```
+ *
+ * You then configure `$animate` to enforce this prefix:
+ *
+ * ```js
+ * $animateProvider.classNameFilter(/animate-/);
+ * ```
+ *
+ * This also may provide your application with a speed boost since only specific elements containing CSS class prefix
+ * will be evaluated for animation when any DOM changes occur in the application.
+ *
+ * ## Callbacks and Promises
+ *
+ * When `$animate` is called it returns a promise that can be used to capture when the animation has ended. Therefore if we were to trigger
+ * an animation (within our directive code) then we can continue performing directive and scope related activities after the animation has
+ * ended by chaining onto the returned promise that animation method returns.
+ *
+ * ```js
+ * // somewhere within the depths of the directive
+ * $animate.enter(element, parent).then(function() {
+ *   //the animation has completed
+ * });
+ * ```
+ *
+ * (Note that earlier versions of Angular prior to v1.4 required the promise code to be wrapped using `$scope.$apply(...)`. This is not the case
+ * anymore.)
+ *
+ * In addition to the animation promise, we can also make use of animation-related callbacks within our directives and controller code by registering
+ * an event listener using the `$animate` service. Let's say for example that an animation was triggered on our view
+ * routing controller to hook into that:
+ *
+ * ```js
+ * ngModule.controller('HomePageController', ['$animate', function($animate) {
+ *   $animate.on('enter', ngViewElement, function(element) {
+ *     // the animation for this route has completed
+ *   }]);
+ * }])
+ * ```
+ *
+ * (Note that you will need to trigger a digest within the callback to get angular to notice any scope-related changes.)
+ */
+
+/**
+ * @ngdoc service
+ * @name $animate
+ * @kind object
+ *
+ * @description
+ * The ngAnimate `$animate` service documentation is the same for the core `$animate` service.
+ *
+ * Click here {@link ng.$animate to learn more about animations with `$animate`}.
+ */
+angular.module('ngAnimate', [])
+  .directive('ngAnimateChildren', $$AnimateChildrenDirective)
+  .factory('$$rAFScheduler', $$rAFSchedulerFactory)
+
+  .factory('$$AnimateRunner', $$AnimateRunnerFactory)
+  .factory('$$animateAsyncRun', $$AnimateAsyncRunFactory)
+
+  .provider('$$animateQueue', $$AnimateQueueProvider)
+  .provider('$$animation', $$AnimationProvider)
+
+  .provider('$animateCss', $AnimateCssProvider)
+  .provider('$$animateCssDriver', $$AnimateCssDriverProvider)
+
+  .provider('$$animateJs', $$AnimateJsProvider)
+  .provider('$$animateJsDriver', $$AnimateJsDriverProvider);
+
+
+})(window, window.angular);
diff --git a/xos/core/xoslib/static/js/xosApi.js b/xos/core/xoslib/static/js/xosApi.js
deleted file mode 100644
index 65d8820..0000000
--- a/xos/core/xoslib/static/js/xosApi.js
+++ /dev/null
@@ -1,51569 +0,0 @@
-/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.hpcapi', [])
-    .factory('hpcapi', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class hpcapi
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var hpcapi = (function() {
-            function hpcapi(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            hpcapi.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            hpcapi.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            hpcapi.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Api_Root_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Api_Root_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_List_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['resource_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['resource_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {choice} kind - 
-             * @param {string} resource_name - 
-             * @param {string} result_contains - 
-             * @param {integer} result_min_size - 
-             * @param {integer} result_max_size - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['resource_name'] !== undefined) {
-                    form['resource_name'] = parameters['resource_name'];
-                }
-
-                if (parameters['result_contains'] !== undefined) {
-                    form['result_contains'] = parameters['result_contains'];
-                }
-
-                if (parameters['result_min_size'] !== undefined) {
-                    form['result_min_size'] = parameters['result_min_size'];
-                }
-
-                if (parameters['result_max_size'] !== undefined) {
-                    form['result_max_size'] = parameters['result_max_size'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Health_Check_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Health_Check_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpchealthchecks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_List_GET
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {string} cmi_hostname - 
-             * @param {boolean} hpc_port80 - Enable port 80 for HPC
-             * @param {string} watcher_hpc_network - Network for hpc_watcher to contact hpc instance
-             * @param {string} watcher_dnsdemux_network - Network for hpc_watcher to contact dnsdemux instance
-             * @param {string} watcher_dnsredir_network - Network for hpc_watcher to contact dnsredir instance
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['cmi_hostname'] !== undefined) {
-                    form['cmi_hostname'] = parameters['cmi_hostname'];
-                }
-
-                if (parameters['hpc_port80'] !== undefined) {
-                    form['hpc_port80'] = parameters['hpc_port80'];
-                }
-
-                if (parameters['watcher_hpc_network'] !== undefined) {
-                    form['watcher_hpc_network'] = parameters['watcher_hpc_network'];
-                }
-
-                if (parameters['watcher_dnsdemux_network'] !== undefined) {
-                    form['watcher_dnsdemux_network'] = parameters['watcher_dnsdemux_network'];
-                }
-
-                if (parameters['watcher_dnsredir_network'] !== undefined) {
-                    form['watcher_dnsredir_network'] = parameters['watcher_dnsredir_network'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Hpc_Service_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Hpc_Service_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/hpcservices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_List_GET
-             * 
-             */
-            hpcapi.prototype.Origin_Server_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['protocol'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: protocol'));
-                    return deferred.promise;
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['protocol'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: protocol'));
-                    return deferred.promise;
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} origin_server_id - 
-             * @param {string} url - 
-             * @param {string} contentProvider - 
-             * @param {boolean} authenticated - Status for this Site
-             * @param {boolean} enabled - Status for this Site
-             * @param {choice} protocol - 
-             * @param {boolean} redirects - Indicates whether Origin Server redirects should be used for this Origin Server
-             * @param {string} description - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['origin_server_id'] !== undefined) {
-                    form['origin_server_id'] = parameters['origin_server_id'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['authenticated'] !== undefined) {
-                    form['authenticated'] = parameters['authenticated'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['protocol'] !== undefined) {
-                    form['protocol'] = parameters['protocol'];
-                }
-
-                if (parameters['redirects'] !== undefined) {
-                    form['redirects'] = parameters['redirects'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Origin_Server_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Origin_Server_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/originservers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_List_GET
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['prefix'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: prefix'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['prefix'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: prefix'));
-                    return deferred.promise;
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} cdn_prefix_id - 
-             * @param {string} prefix - Registered Prefix for Domain
-             * @param {string} contentProvider - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} defaultOriginServer - 
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['cdn_prefix_id'] !== undefined) {
-                    form['cdn_prefix_id'] = parameters['cdn_prefix_id'];
-                }
-
-                if (parameters['prefix'] !== undefined) {
-                    form['prefix'] = parameters['prefix'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['defaultOriginServer'] !== undefined) {
-                    form['defaultOriginServer'] = parameters['defaultOriginServer'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Cdn_Prefix_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Cdn_Prefix_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/cdnprefixs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_List_GET
-             * 
-             */
-            hpcapi.prototype.Service_Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['hpcService'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: hpcService'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['hpcService'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: hpcService'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} hpcService - 
-             * @param {integer} service_provider_id - 
-             * @param {string} name - Service Provider Name
-             * @param {string} description - Description of Service Provider
-             * @param {boolean} enabled - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['service_provider_id'] !== undefined) {
-                    form['service_provider_id'] = parameters['service_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Service_Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Service_Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/serviceproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_List_GET
-             * 
-             */
-            hpcapi.prototype.Content_Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['serviceProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['serviceProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {integer} content_provider_id - 
-             * @param {string} name - 
-             * @param {boolean} enabled - 
-             * @param {string} description - Description of Content Provider
-             * @param {string} serviceProvider - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['content_provider_id'] !== undefined) {
-                    form['content_provider_id'] = parameters['content_provider_id'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Content_Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Content_Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/contentproviders/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_List_GET
-             * 
-             */
-            hpcapi.prototype.Access_Map_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['contentProvider'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: contentProvider'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} name - Name of the Access Map
-             * @param {string} description - 
-             * @param {string} map - specifies which client requests are allowed
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Access_Map_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Access_Map_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/accessmaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_List_GET
-             * 
-             */
-            hpcapi.prototype.Site_Map_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: map'));
-                    return deferred.promise;
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} contentProvider - 
-             * @param {string} serviceProvider - 
-             * @param {string} cdnPrefix - 
-             * @param {string} hpcService - 
-             * @param {string} name - Name of the Site Map
-             * @param {string} description - 
-             * @param {string} map - specifies how to map requests to hpc instances
-             * @param {integer} map_id - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['contentProvider'] !== undefined) {
-                    form['contentProvider'] = parameters['contentProvider'];
-                }
-
-                if (parameters['serviceProvider'] !== undefined) {
-                    form['serviceProvider'] = parameters['serviceProvider'];
-                }
-
-                if (parameters['cdnPrefix'] !== undefined) {
-                    form['cdnPrefix'] = parameters['cdnPrefix'];
-                }
-
-                if (parameters['hpcService'] !== undefined) {
-                    form['hpcService'] = parameters['hpcService'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['map'] !== undefined) {
-                    form['map'] = parameters['map'];
-                }
-
-                if (parameters['map_id'] !== undefined) {
-                    form['map_id'] = parameters['map_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name hpcapi#Site_Map_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            hpcapi.prototype.Site_Map_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/hpcapi/sitemaps/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = hpcapi.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return hpcapi;
-        })();
-
-        return hpcapi;
-    }]);/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.xos', [])
-    .factory('xos', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class xos
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var xos = (function() {
-            function xos(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            xos.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            xos.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            xos.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name xos#Api_Root_GET
-             * 
-             */
-            xos.prototype.Api_Root_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_List_GET
-             * 
-             */
-            xos.prototype.Site_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/site_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_List_GET
-             * 
-             */
-            xos.prototype.Service_Attribute_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Attribute Name
-             * @param {string} value - Attribute Value
-             * @param {string} service - The Service this attribute is associated with
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Attribute_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Attribute_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceattributes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_List_GET
-             * 
-             */
-            xos.prototype.Controller_Images_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} controller - 
-             * @param {string} glance_image_id - Glance image id
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['glance_image_id'] !== undefined) {
-                    form['glance_image_id'] = parameters['glance_image_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Images_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Images_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerimages/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['site_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['site_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} site_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['site_privilege'] !== undefined) {
-                    form['site_privilege'] = parameters['site_privilege'];
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersiteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_List_GET
-             * 
-             */
-            xos.prototype.Image_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['disk_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: disk_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['container_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: container_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['disk_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: disk_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['container_format'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: container_format'));
-                    return deferred.promise;
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} disk_format - 
-             * @param {string} container_format - 
-             * @param {string} path - Path to image on local disk
-             * 
-             */
-            xos.prototype.Image_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['disk_format'] !== undefined) {
-                    form['disk_format'] = parameters['disk_format'];
-                }
-
-                if (parameters['container_format'] !== undefined) {
-                    form['container_format'] = parameters['container_format'];
-                }
-
-                if (parameters['path'] !== undefined) {
-                    form['path'] = parameters['path'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/images/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_List_GET
-             * 
-             */
-            xos.prototype.Network_Parameter_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['parameter'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: parameter'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['parameter'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: parameter'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} parameter - The type of the parameter
-             * @param {string} value - The value of this parameter
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['parameter'] !== undefined) {
-                    form['parameter'] = parameters['parameter'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparameters/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_List_GET
-             * 
-             */
-            xos.prototype.Site_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['location'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: location'));
-                    return deferred.promise;
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['login_base'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: login_base'));
-                    return deferred.promise;
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters['abbreviated_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: abbreviated_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['location'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: location'));
-                    return deferred.promise;
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['login_base'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: login_base'));
-                    return deferred.promise;
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters['abbreviated_name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: abbreviated_name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name for this Site
-             * @param {string} site_url - Site's Home URL Page
-             * @param {boolean} enabled - Status for this Site
-             * @param {boolean} hosts_nodes - Indicates whether or not the site host nodes
-             * @param {boolean} hosts_users - Indicates whether or not the site manages user accounts
-             * @param {string} location - 
-             * @param {number} longitude - 
-             * @param {number} latitude - 
-             * @param {string} login_base - Prefix for Slices associated with this Site
-             * @param {boolean} is_public - Indicates the visibility of this site to other members
-             * @param {string} abbreviated_name - 
-             * 
-             */
-            xos.prototype.Site_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['site_url'] !== undefined) {
-                    form['site_url'] = parameters['site_url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['hosts_nodes'] !== undefined) {
-                    form['hosts_nodes'] = parameters['hosts_nodes'];
-                }
-
-                if (parameters['hosts_users'] !== undefined) {
-                    form['hosts_users'] = parameters['hosts_users'];
-                }
-
-                if (parameters['location'] !== undefined) {
-                    form['location'] = parameters['location'];
-                }
-
-                if (parameters['longitude'] !== undefined) {
-                    form['longitude'] = parameters['longitude'];
-                }
-
-                if (parameters['latitude'] !== undefined) {
-                    form['latitude'] = parameters['latitude'];
-                }
-
-                if (parameters['login_base'] !== undefined) {
-                    form['login_base'] = parameters['login_base'];
-                }
-
-                if (parameters['is_public'] !== undefined) {
-                    form['is_public'] = parameters['is_public'];
-                }
-
-                if (parameters['abbreviated_name'] !== undefined) {
-                    form['abbreviated_name'] = parameters['abbreviated_name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_List_GET
-             * 
-             */
-            xos.prototype.Slice_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {choice} role - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_List_GET
-             * 
-             */
-            xos.prototype.Tag_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tag_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters['object_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} service - The Service this Tag is associated with
-             * @param {string} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * @param {string} content_type - 
-             * @param {integer} object_id - 
-             * 
-             */
-            xos.prototype.Tag_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['object_id'] !== undefined) {
-                    form['object_id'] = parameters['object_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tag_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tag_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_List_GET
-             * 
-             */
-            xos.prototype.Invoice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} date - 
-             * @param {string} account - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Invoice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Invoice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/invoices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Slice_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} slice - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slice_privileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_List_GET
-             * 
-             */
-            xos.prototype.Flavor_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Flavor_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - name of this flavor, as displayed to users
-             * @param {string} description - 
-             * @param {string} flavor - flavor string used to configure deployments
-             * @param {integer} order - used to order flavors when displayed in a list
-             * @param {boolean} default - make this a default flavor to use when creating new instances
-             * 
-             */
-            xos.prototype.Flavor_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['default'] !== undefined) {
-                    form['default'] = parameters['default'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Flavor_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Flavor_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/flavors/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_List_GET
-             * 
-             */
-            xos.prototype.Port_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Port_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} instance - 
-             * @param {string} ip - Instance ip address
-             * @param {string} port_id - Quantum port id
-             * @param {string} mac - MAC address associated with this port
-             * 
-             */
-            xos.prototype.Port_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['port_id'] !== undefined) {
-                    form['port_id'] = parameters['port_id'];
-                }
-
-                if (parameters['mac'] !== undefined) {
-                    form['mac'] = parameters['mac'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Port_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Port_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/ports/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_List_GET
-             * 
-             */
-            xos.prototype.Controller_Site_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} controller - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Site_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Site_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersites/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_List_GET
-             * 
-             */
-            xos.prototype.Project_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Project_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of Project
-             * 
-             */
-            xos.prototype.Project_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Project_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Project_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/projects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_List_GET
-             * 
-             */
-            xos.prototype.Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} default_flavor - 
-             * @param {string} default_image - 
-             * @param {string} mount_data_sets - 
-             * 
-             */
-            xos.prototype.Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_List_GET
-             * 
-             */
-            xos.prototype.Network_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['template'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: template'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['template'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: template'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} template - 
-             * @param {string} subnet - 
-             * @param {string} ports - 
-             * @param {string} labels - 
-             * @param {string} owner - Slice that owns control of this Network
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {boolean} permit_all_slices - 
-             * @param {string} topology_parameters - 
-             * @param {string} controller_url - 
-             * @param {string} controller_parameters - 
-             * @param {string} network_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {boolean} autoconnect - This network can be autoconnected to the slice that owns it
-             * 
-             */
-            xos.prototype.Network_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['template'] !== undefined) {
-                    form['template'] = parameters['template'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters['ports'] !== undefined) {
-                    form['ports'] = parameters['ports'];
-                }
-
-                if (parameters['labels'] !== undefined) {
-                    form['labels'] = parameters['labels'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['permit_all_slices'] !== undefined) {
-                    form['permit_all_slices'] = parameters['permit_all_slices'];
-                }
-
-                if (parameters['topology_parameters'] !== undefined) {
-                    form['topology_parameters'] = parameters['topology_parameters'];
-                }
-
-                if (parameters['controller_url'] !== undefined) {
-                    form['controller_url'] = parameters['controller_url'];
-                }
-
-                if (parameters['controller_parameters'] !== undefined) {
-                    form['controller_parameters'] = parameters['controller_parameters'];
-                }
-
-                if (parameters['network_id'] !== undefined) {
-                    form['network_id'] = parameters['network_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['autoconnect'] !== undefined) {
-                    form['autoconnect'] = parameters['autoconnect'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_List_GET
-             * 
-             */
-            xos.prototype.Service_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['versionNumber'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: versionNumber'));
-                    return deferred.promise;
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} description - Description of Service
-             * @param {boolean} enabled - 
-             * @param {string} kind - Kind of service
-             * @param {string} name - Service Name
-             * @param {string} versionNumber - Version of Service Definition
-             * @param {boolean} published - 
-             * @param {string} view_url - 
-             * @param {string} icon_url - 
-             * @param {string} public_key - Public key string
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * 
-             */
-            xos.prototype.Service_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['versionNumber'] !== undefined) {
-                    form['versionNumber'] = parameters['versionNumber'];
-                }
-
-                if (parameters['published'] !== undefined) {
-                    form['published'] = parameters['published'];
-                }
-
-                if (parameters['view_url'] !== undefined) {
-                    form['view_url'] = parameters['view_url'];
-                }
-
-                if (parameters['icon_url'] !== undefined) {
-                    form['icon_url'] = parameters['icon_url'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/services/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_List_GET
-             * 
-             */
-            xos.prototype.Service_Class_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['commitment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: commitment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFee'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFee'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['membershipFeeMonths'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFeeMonths'));
-                    return deferred.promise;
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['commitment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: commitment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFee'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFee'));
-                    return deferred.promise;
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['membershipFeeMonths'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: membershipFeeMonths'));
-                    return deferred.promise;
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} commitment - 
-             * @param {integer} membershipFee - 
-             * @param {integer} membershipFeeMonths - 
-             * @param {boolean} upgradeRequiresApproval - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['commitment'] !== undefined) {
-                    form['commitment'] = parameters['commitment'];
-                }
-
-                if (parameters['membershipFee'] !== undefined) {
-                    form['membershipFee'] = parameters['membershipFee'];
-                }
-
-                if (parameters['membershipFeeMonths'] !== undefined) {
-                    form['membershipFeeMonths'] = parameters['membershipFeeMonths'];
-                }
-
-                if (parameters['upgradeRequiresApproval'] !== undefined) {
-                    form['upgradeRequiresApproval'] = parameters['upgradeRequiresApproval'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Class_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Class_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceclasses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_List_GET
-             * 
-             */
-            xos.prototype.Payment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Payment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {number} amount - 
-             * @param {string} date - 
-             * 
-             */
-            xos.prototype.Payment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Payment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Payment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/payments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_List_GET
-             * 
-             */
-            xos.prototype.Subscriber_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Subscriber_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Subscriber_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/subscribers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_List_GET
-             * 
-             */
-            xos.prototype.Instance_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['node'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: node'));
-                    return deferred.promise;
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['numberCores'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: numberCores'));
-                    return deferred.promise;
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Instance_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['node'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: node'));
-                    return deferred.promise;
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['numberCores'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: numberCores'));
-                    return deferred.promise;
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['flavor'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: flavor'));
-                    return deferred.promise;
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance_id - Nova instance id
-             * @param {string} instance_uuid - Nova instance uuid
-             * @param {string} name - Instance name
-             * @param {string} instance_name - OpenStack generated name
-             * @param {string} ip - Instance ip address
-             * @param {string} image - 
-             * @param {string} creator - 
-             * @param {string} slice - 
-             * @param {string} deployment - 
-             * @param {string} node - 
-             * @param {integer} numberCores - Number of cores for instance
-             * @param {string} flavor - Flavor of this instance
-             * @param {string} userData - user_data passed to instance during creation
-             * 
-             */
-            xos.prototype.Instance_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance_id'] !== undefined) {
-                    form['instance_id'] = parameters['instance_id'];
-                }
-
-                if (parameters['instance_uuid'] !== undefined) {
-                    form['instance_uuid'] = parameters['instance_uuid'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['instance_name'] !== undefined) {
-                    form['instance_name'] = parameters['instance_name'];
-                }
-
-                if (parameters['ip'] !== undefined) {
-                    form['ip'] = parameters['ip'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['node'] !== undefined) {
-                    form['node'] = parameters['node'];
-                }
-
-                if (parameters['numberCores'] !== undefined) {
-                    form['numberCores'] = parameters['numberCores'];
-                }
-
-                if (parameters['flavor'] !== undefined) {
-                    form['flavor'] = parameters['flavor'];
-                }
-
-                if (parameters['userData'] !== undefined) {
-                    form['userData'] = parameters['userData'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Instance_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Instance_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/instances/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_List_GET
-             * 
-             */
-            xos.prototype.Charge_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['state'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: state'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['object'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['coreHours'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: coreHours'));
-                    return deferred.promise;
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Charge_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['account'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: account'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['state'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: state'));
-                    return deferred.promise;
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['date'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: date'));
-                    return deferred.promise;
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['object'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: object'));
-                    return deferred.promise;
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['amount'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: amount'));
-                    return deferred.promise;
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['coreHours'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: coreHours'));
-                    return deferred.promise;
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} account - 
-             * @param {string} slice - 
-             * @param {choice} kind - 
-             * @param {choice} state - 
-             * @param {string} date - 
-             * @param {string} object - 
-             * @param {number} amount - 
-             * @param {number} coreHours - 
-             * @param {string} invoice - 
-             * 
-             */
-            xos.prototype.Charge_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['account'] !== undefined) {
-                    form['account'] = parameters['account'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['state'] !== undefined) {
-                    form['state'] = parameters['state'];
-                }
-
-                if (parameters['date'] !== undefined) {
-                    form['date'] = parameters['date'];
-                }
-
-                if (parameters['object'] !== undefined) {
-                    form['object'] = parameters['object'];
-                }
-
-                if (parameters['amount'] !== undefined) {
-                    form['amount'] = parameters['amount'];
-                }
-
-                if (parameters['coreHours'] !== undefined) {
-                    form['coreHours'] = parameters['coreHours'];
-                }
-
-                if (parameters['invoice'] !== undefined) {
-                    form['invoice'] = parameters['invoice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Charge_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Charge_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/charges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_List_GET
-             * 
-             */
-            xos.prototype.Program_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Program_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Service Name
-             * @param {string} description - Description of Service
-
-             * @param {choice} command - Command to run
-             * @param {string} owner - 
-             * @param {string} contents - Contents of Program
-             * @param {string} output - Output of Program
-             * @param {string} messages - Debug messages
-             * @param {string} status - Status of program
-             * 
-             */
-            xos.prototype.Program_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                form['kind'] = 'tosca';
-
-                if (parameters['command'] !== undefined) {
-                    form['command'] = parameters['command'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['contents'] !== undefined) {
-                    form['contents'] = parameters['contents'];
-                }
-
-                if (parameters['output'] !== undefined) {
-                    form['output'] = parameters['output'];
-                }
-
-                if (parameters['messages'] !== undefined) {
-                    form['messages'] = parameters['messages'];
-                }
-
-                if (parameters['status'] !== undefined) {
-                    form['status'] = parameters['status'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Program_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Program_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/programs/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_List_GET
-             * 
-             */
-            xos.prototype.Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters['content_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: content_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} role_type - 
-             * @param {string} role - 
-             * @param {string} description - 
-             * @param {string} content_type - 
-             * 
-             */
-            xos.prototype.Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['role_type'] !== undefined) {
-                    form['role_type'] = parameters['role_type'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['content_type'] !== undefined) {
-                    form['content_type'] = parameters['content_type'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/roles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_List_GET
-             * 
-             */
-            xos.prototype.Usable_Object_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Usable_Object_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Usable_Object_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usableobjects/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_List_GET
-             * 
-             */
-            xos.prototype.Provider_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Provider_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Provider_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Provider_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Provider_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/providers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_List_GET
-             * 
-             */
-            xos.prototype.Slice_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_List_GET
-             * 
-             */
-            xos.prototype.Node_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site_deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Node_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site_deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site_deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Node
-             * @param {string} site_deployment - 
-             * @param {string} site - 
-             * 
-             */
-            xos.prototype.Node_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['site_deployment'] !== undefined) {
-                    form['site_deployment'] = parameters['site_deployment'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Node_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Node_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/nodes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the View
-             * @param {string} url - URL of Dashboard
-             * @param {boolean} enabled - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/dashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_List_GET
-             * 
-             */
-            xos.prototype.Controller_Network_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} controller - 
-             * @param {string} net_id - Quantum network
-             * @param {string} router_id - Quantum router id
-             * @param {string} subnet_id - Quantum subnet id
-             * @param {string} subnet - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['net_id'] !== undefined) {
-                    form['net_id'] = parameters['net_id'];
-                }
-
-                if (parameters['router_id'] !== undefined) {
-                    form['router_id'] = parameters['router_id'];
-                }
-
-                if (parameters['subnet_id'] !== undefined) {
-                    form['subnet_id'] = parameters['subnet_id'];
-                }
-
-                if (parameters['subnet'] !== undefined) {
-                    form['subnet'] = parameters['subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Network_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Network_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllernetworks/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_List_GET
-             * 
-             */
-            xos.prototype.Image_Deployments_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['image'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: image'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} image - 
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['image'] !== undefined) {
-                    form['image'] = parameters['image'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Image_Deployments_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Image_Deployments_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/imagedeploymentses/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_List_GET
-             * 
-             */
-            xos.prototype.Controller_User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} controller - 
-             * @param {string} kuser_id - Keystone user id
-             * 
-             */
-            xos.prototype.Controller_User_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['kuser_id'] !== undefined) {
-                    form['kuser_id'] = parameters['kuser_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerusers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_List_GET
-             * 
-             */
-            xos.prototype.Reserved_Resource_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['instance'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: instance'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['resource'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource'));
-                    return deferred.promise;
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['quantity'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: quantity'));
-                    return deferred.promise;
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters['reservationSet'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: reservationSet'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['instance'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: instance'));
-                    return deferred.promise;
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['resource'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: resource'));
-                    return deferred.promise;
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['quantity'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: quantity'));
-                    return deferred.promise;
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters['reservationSet'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: reservationSet'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} instance - 
-             * @param {string} resource - 
-             * @param {integer} quantity - 
-             * @param {string} reservationSet - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['instance'] !== undefined) {
-                    form['instance'] = parameters['instance'];
-                }
-
-                if (parameters['resource'] !== undefined) {
-                    form['resource'] = parameters['resource'];
-                }
-
-                if (parameters['quantity'] !== undefined) {
-                    form['quantity'] = parameters['quantity'];
-                }
-
-                if (parameters['reservationSet'] !== undefined) {
-                    form['reservationSet'] = parameters['reservationSet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reserved_Resource_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reserved_Resource_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservedresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_List_GET
-             * 
-             */
-            xos.prototype.Network_Template_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['visibility'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: visibility'));
-                    return deferred.promise;
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['translation'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: translation'));
-                    return deferred.promise;
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['topology_kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: topology_kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: guaranteed_bandwidth'));
-                    return deferred.promise;
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['visibility'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: visibility'));
-                    return deferred.promise;
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['translation'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: translation'));
-                    return deferred.promise;
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['topology_kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: topology_kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} description - 
-             * @param {integer} guaranteed_bandwidth - 
-             * @param {choice} visibility - 
-             * @param {choice} translation - 
-             * @param {string} shared_network_name - 
-             * @param {string} shared_network_id - Quantum network
-             * @param {choice} topology_kind - 
-             * @param {choice} controller_kind - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['guaranteed_bandwidth'] !== undefined) {
-                    form['guaranteed_bandwidth'] = parameters['guaranteed_bandwidth'];
-                }
-
-                if (parameters['visibility'] !== undefined) {
-                    form['visibility'] = parameters['visibility'];
-                }
-
-                if (parameters['translation'] !== undefined) {
-                    form['translation'] = parameters['translation'];
-                }
-
-                if (parameters['shared_network_name'] !== undefined) {
-                    form['shared_network_name'] = parameters['shared_network_name'];
-                }
-
-                if (parameters['shared_network_id'] !== undefined) {
-                    form['shared_network_id'] = parameters['shared_network_id'];
-                }
-
-                if (parameters['topology_kind'] !== undefined) {
-                    form['topology_kind'] = parameters['topology_kind'];
-                }
-
-                if (parameters['controller_kind'] !== undefined) {
-                    form['controller_kind'] = parameters['controller_kind'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Template_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Template_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networktemplates/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_List_GET
-             * 
-             */
-            xos.prototype.Network_Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['network'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: network'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} network - 
-             * @param {string} slice - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.User_Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters['order'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: order'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} dashboardView - 
-             * @param {integer} order - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['order'] !== undefined) {
-                    form['order'] = parameters['order'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/userdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_List_GET
-             * 
-             */
-            xos.prototype.Controller_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['backend_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['version'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: version'));
-                    return deferred.promise;
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['backend_type'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_type'));
-                    return deferred.promise;
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['version'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: version'));
-                    return deferred.promise;
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Controller
-             * @param {string} backend_type - Type of compute controller, e.g. EC2, OpenStack, or OpenStack version
-             * @param {string} version - Controller version
-             * @param {string} auth_url - Auth url for the compute controller
-             * @param {string} admin_user - Username of an admin user at this controller
-             * @param {string} admin_password - Password of theadmin user at this controller
-             * @param {string} admin_tenant - Name of the tenant the admin user belongs to
-             * @param {string} domain - Name of the domain this controller belongs to
-             * @param {string} rabbit_host - IP address of rabbitmq server at this controller
-             * @param {string} rabbit_user - Username of rabbitmq server at this controller
-             * @param {string} rabbit_password - Password of rabbitmq server at this controller
-             * @param {string} deployment - 
-             * 
-             */
-            xos.prototype.Controller_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['backend_type'] !== undefined) {
-                    form['backend_type'] = parameters['backend_type'];
-                }
-
-                if (parameters['version'] !== undefined) {
-                    form['version'] = parameters['version'];
-                }
-
-                if (parameters['auth_url'] !== undefined) {
-                    form['auth_url'] = parameters['auth_url'];
-                }
-
-                if (parameters['admin_user'] !== undefined) {
-                    form['admin_user'] = parameters['admin_user'];
-                }
-
-                if (parameters['admin_password'] !== undefined) {
-                    form['admin_password'] = parameters['admin_password'];
-                }
-
-                if (parameters['admin_tenant'] !== undefined) {
-                    form['admin_tenant'] = parameters['admin_tenant'];
-                }
-
-                if (parameters['domain'] !== undefined) {
-                    form['domain'] = parameters['domain'];
-                }
-
-                if (parameters['rabbit_host'] !== undefined) {
-                    form['rabbit_host'] = parameters['rabbit_host'];
-                }
-
-                if (parameters['rabbit_user'] !== undefined) {
-                    form['rabbit_user'] = parameters['rabbit_user'];
-                }
-
-                if (parameters['rabbit_password'] !== undefined) {
-                    form['rabbit_password'] = parameters['rabbit_password'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_List_GET
-             * 
-             */
-            xos.prototype.User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_List_POST
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['password'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: password'));
-                    return deferred.promise;
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['last_login'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: last_login'));
-                    return deferred.promise;
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['email'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: email'));
-                    return deferred.promise;
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['username'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: username'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['firstname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firstname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['lastname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: lastname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters['timezone'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: timezone'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['password'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: password'));
-                    return deferred.promise;
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['last_login'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: last_login'));
-                    return deferred.promise;
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['email'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: email'));
-                    return deferred.promise;
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['username'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: username'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['firstname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firstname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['lastname'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: lastname'));
-                    return deferred.promise;
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters['timezone'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: timezone'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} password - 
-             * @param {string} last_login - 
-             * @param {string} email - 
-             * @param {string} username - 
-             * @param {string} firstname - person's given name
-             * @param {string} lastname - person's surname
-             * @param {string} phone - phone number contact
-             * @param {string} user_url - 
-             * @param {string} site - Site this user will be homed too
-             * @param {string} public_key - Public key string
-             * @param {boolean} is_active - 
-             * @param {boolean} is_admin - 
-             * @param {boolean} is_staff - 
-             * @param {boolean} is_readonly - 
-             * @param {boolean} is_registering - 
-             * @param {boolean} is_appuser - 
-             * @param {string} login_page - send this user to a specific page on login
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {choice} timezone - 
-             * 
-             */
-            xos.prototype.User_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['password'] !== undefined) {
-                    form['password'] = parameters['password'];
-                }
-
-                if (parameters['last_login'] !== undefined) {
-                    form['last_login'] = parameters['last_login'];
-                }
-
-                if (parameters['email'] !== undefined) {
-                    form['email'] = parameters['email'];
-                }
-
-                if (parameters['username'] !== undefined) {
-                    form['username'] = parameters['username'];
-                }
-
-                if (parameters['firstname'] !== undefined) {
-                    form['firstname'] = parameters['firstname'];
-                }
-
-                if (parameters['lastname'] !== undefined) {
-                    form['lastname'] = parameters['lastname'];
-                }
-
-                if (parameters['phone'] !== undefined) {
-                    form['phone'] = parameters['phone'];
-                }
-
-                if (parameters['user_url'] !== undefined) {
-                    form['user_url'] = parameters['user_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['public_key'] !== undefined) {
-                    form['public_key'] = parameters['public_key'];
-                }
-
-                if (parameters['is_active'] !== undefined) {
-                    form['is_active'] = parameters['is_active'];
-                }
-
-                if (parameters['is_admin'] !== undefined) {
-                    form['is_admin'] = parameters['is_admin'];
-                }
-
-                if (parameters['is_staff'] !== undefined) {
-                    form['is_staff'] = parameters['is_staff'];
-                }
-
-                if (parameters['is_readonly'] !== undefined) {
-                    form['is_readonly'] = parameters['is_readonly'];
-                }
-
-                if (parameters['is_registering'] !== undefined) {
-                    form['is_registering'] = parameters['is_registering'];
-                }
-
-                if (parameters['is_appuser'] !== undefined) {
-                    form['is_appuser'] = parameters['is_appuser'];
-                }
-
-                if (parameters['login_page'] !== undefined) {
-                    form['login_page'] = parameters['login_page'];
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['timezone'] !== undefined) {
-                    form['timezone'] = parameters['timezone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/users/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_List_GET
-             * 
-             */
-            xos.prototype.Deployment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters['accessControl'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: accessControl'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters['accessControl'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: accessControl'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - Name of the Deployment
-             * @param {string} accessControl - Access control list that specifies which sites/users may use nodes in this deployment
-             * 
-             */
-            xos.prototype.Deployment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['accessControl'] !== undefined) {
-                    form['accessControl'] = parameters['accessControl'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_List_GET
-             * 
-             */
-            xos.prototype.Reservation_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['startTime'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: startTime'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters['duration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: duration'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['startTime'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: startTime'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters['duration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: duration'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} startTime - 
-             * @param {string} slice - 
-             * @param {integer} duration - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['startTime'] !== undefined) {
-                    form['startTime'] = parameters['startTime'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['duration'] !== undefined) {
-                    form['duration'] = parameters['duration'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Reservation_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Reservation_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/reservations/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Site_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} site - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/siteprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_List_GET
-             * 
-             */
-            xos.prototype.Controller_Slice_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice - 
-             * @param {string} tenant_id - Keystone tenant id
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['tenant_id'] !== undefined) {
-                    form['tenant_id'] = parameters['tenant_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerslices/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_List_GET
-             * 
-             */
-            xos.prototype.Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_List_GET
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['dashboardView'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: dashboardView'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters['url'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} dashboardView - 
-             * @param {boolean} enabled - 
-             * @param {string} url - URL of Dashboard
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['dashboardView'] !== undefined) {
-                    form['dashboardView'] = parameters['dashboardView'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['url'] !== undefined) {
-                    form['url'] = parameters['url'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Dashboard_View_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Dashboard_View_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerdashboardviews/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_List_GET
-             * 
-             */
-            xos.prototype.Account_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Account_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - Site for this account
-             * 
-             */
-            xos.prototype.Account_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Account_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Account_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/accounts/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} name - name
-             * @param {string} service_specific_attribute - 
-             * @param {string} service_specific_id - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantroots/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_List_GET
-             * 
-             */
-            xos.prototype.Controller_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllerroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_List_GET
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['description'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: description'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - The name of this parameter
-             * @param {string} description - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Network_Parameter_Type_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Network_Parameter_Type_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/networkparametertypes/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_List_GET
-             * 
-             */
-            xos.prototype.Site_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitecredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Deployment_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} deployment - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['slice_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['controller'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: controller'));
-                    return deferred.promise;
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['slice_privilege'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice_privilege'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} controller - 
-             * @param {string} slice_privilege - 
-             * @param {string} role_id - Keystone id
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['slice_privilege'] !== undefined) {
-                    form['slice_privilege'] = parameters['slice_privilege'];
-                }
-
-                if (parameters['role_id'] !== undefined) {
-                    form['role_id'] = parameters['role_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Controller_Slice_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Controller_Slice_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/controllersliceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_List_GET
-             * 
-             */
-            xos.prototype.Site_Deployment_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['deployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: deployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} site - 
-             * @param {string} deployment - 
-             * @param {string} controller - 
-             * @param {string} availability_zone - OpenStack availability zone
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['deployment'] !== undefined) {
-                    form['deployment'] = parameters['deployment'];
-                }
-
-                if (parameters['controller'] !== undefined) {
-                    form['controller'] = parameters['controller'];
-                }
-
-                if (parameters['availability_zone'] !== undefined) {
-                    form['availability_zone'] = parameters['availability_zone'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Site_Deployment_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Site_Deployment_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/sitedeployments/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_List_GET
-             * 
-             */
-            xos.prototype.Tenant_With_Container_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_With_Container_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_With_Container_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantwithcontainers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_List_GET
-             * 
-             */
-            xos.prototype.Deployment_Role_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                form['role'] = 'admin';
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Deployment_Role_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Deployment_Role_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/deploymentroles/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_List_GET
-             * 
-             */
-            xos.prototype.User_Credential_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Credential_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['key_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: key_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters['enc_value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: enc_value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - The User this credential is associated with
-             * @param {string} name - The credential type, e.g. ec2
-             * @param {string} key_id - The backend id of this credential
-             * @param {string} enc_value - The key value of this credential
-             * 
-             */
-            xos.prototype.User_Credential_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['key_id'] !== undefined) {
-                    form['key_id'] = parameters['key_id'];
-                }
-
-                if (parameters['enc_value'] !== undefined) {
-                    form['enc_value'] = parameters['enc_value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#User_Credential_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.User_Credential_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/usercredentials/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['tenant_root'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: tenant_root'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['tenant_root'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: tenant_root'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} tenant_root - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['tenant_root'] !== undefined) {
-                    form['tenant_root'] = parameters['tenant_root'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Tenant_Root_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Tenant_Root_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/tenantrootprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_List_GET
-             * 
-             */
-            xos.prototype.Slice_Tag_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['slice'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: slice'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters['value'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: value'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} slice - 
-             * @param {choice} name - The name of this tag
-             * @param {string} value - The value of this tag
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['slice'] !== undefined) {
-                    form['slice'] = parameters['slice'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['value'] !== undefined) {
-                    form['value'] = parameters['value'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Slice_Tag_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Slice_Tag_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/slicetags/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_List_GET
-             * 
-             */
-            xos.prototype.Coarse_Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['kind'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: kind'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters['connect_method'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: connect_method'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} kind - 
-             * @param {string} provider_service - 
-             * @param {string} subscriber_service - 
-             * @param {string} subscriber_tenant - 
-             * @param {string} subscriber_user - 
-             * @param {string} subscriber_root - 
-             * @param {string} service_specific_id - 
-             * @param {string} service_specific_attribute - 
-             * @param {choice} connect_method - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['kind'] !== undefined) {
-                    form['kind'] = parameters['kind'];
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['subscriber_service'] !== undefined) {
-                    form['subscriber_service'] = parameters['subscriber_service'];
-                }
-
-                if (parameters['subscriber_tenant'] !== undefined) {
-                    form['subscriber_tenant'] = parameters['subscriber_tenant'];
-                }
-
-                if (parameters['subscriber_user'] !== undefined) {
-                    form['subscriber_user'] = parameters['subscriber_user'];
-                }
-
-                if (parameters['subscriber_root'] !== undefined) {
-                    form['subscriber_root'] = parameters['subscriber_root'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_attribute'] !== undefined) {
-                    form['service_specific_attribute'] = parameters['service_specific_attribute'];
-                }
-
-                if (parameters['connect_method'] !== undefined) {
-                    form['connect_method'] = parameters['connect_method'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Coarse_Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Coarse_Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/coarsetenants/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_List_GET
-             * 
-             */
-            xos.prototype.Router_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Router_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters['owner'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: owner'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} name - 
-             * @param {string} owner - 
-             * 
-             */
-            xos.prototype.Router_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['owner'] !== undefined) {
-                    form['owner'] = parameters['owner'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Router_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Router_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/routers/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_List_GET
-             * 
-             */
-            xos.prototype.Service_Resource_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['serviceClass'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceClass'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsDeployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsDeployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxUnitsNode'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsNode'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['maxDuration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxDuration'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketInRate'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketInRate'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['bucketMaxSize'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketMaxSize'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['cost'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cost'));
-                    return deferred.promise;
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['serviceClass'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: serviceClass'));
-                    return deferred.promise;
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsDeployment'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsDeployment'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxUnitsNode'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxUnitsNode'));
-                    return deferred.promise;
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['maxDuration'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: maxDuration'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketInRate'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketInRate'));
-                    return deferred.promise;
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['bucketMaxSize'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: bucketMaxSize'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['cost'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cost'));
-                    return deferred.promise;
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} serviceClass - 
-             * @param {string} name - 
-             * @param {integer} maxUnitsDeployment - 
-             * @param {integer} maxUnitsNode - 
-             * @param {integer} maxDuration - 
-             * @param {integer} bucketInRate - 
-             * @param {integer} bucketMaxSize - 
-             * @param {integer} cost - 
-             * @param {boolean} calendarReservable - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['maxUnitsDeployment'] !== undefined) {
-                    form['maxUnitsDeployment'] = parameters['maxUnitsDeployment'];
-                }
-
-                if (parameters['maxUnitsNode'] !== undefined) {
-                    form['maxUnitsNode'] = parameters['maxUnitsNode'];
-                }
-
-                if (parameters['maxDuration'] !== undefined) {
-                    form['maxDuration'] = parameters['maxDuration'];
-                }
-
-                if (parameters['bucketInRate'] !== undefined) {
-                    form['bucketInRate'] = parameters['bucketInRate'];
-                }
-
-                if (parameters['bucketMaxSize'] !== undefined) {
-                    form['bucketMaxSize'] = parameters['bucketMaxSize'];
-                }
-
-                if (parameters['cost'] !== undefined) {
-                    form['cost'] = parameters['cost'];
-                }
-
-                if (parameters['calendarReservable'] !== undefined) {
-                    form['calendarReservable'] = parameters['calendarReservable'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Resource_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Resource_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceresources/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_List_GET
-             * 
-             */
-            xos.prototype.Service_Privilege_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_List_POST
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['backend_status'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: backend_status'));
-                    return deferred.promise;
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['user'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: user'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters['role'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: role'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} policed - 
-             * @param {string} backend_register - 
-             * @param {string} backend_status - 
-             * @param {boolean} deleted - 
-             * @param {boolean} write_protect - 
-             * @param {boolean} lazy_blocked - 
-             * @param {boolean} no_sync - 
-             * @param {string} user - 
-             * @param {string} service - 
-             * @param {string} role - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['policed'] !== undefined) {
-                    form['policed'] = parameters['policed'];
-                }
-
-                if (parameters['backend_register'] !== undefined) {
-                    form['backend_register'] = parameters['backend_register'];
-                }
-
-                if (parameters['backend_status'] !== undefined) {
-                    form['backend_status'] = parameters['backend_status'];
-                }
-
-                if (parameters['deleted'] !== undefined) {
-                    form['deleted'] = parameters['deleted'];
-                }
-
-                if (parameters['write_protect'] !== undefined) {
-                    form['write_protect'] = parameters['write_protect'];
-                }
-
-                if (parameters['lazy_blocked'] !== undefined) {
-                    form['lazy_blocked'] = parameters['lazy_blocked'];
-                }
-
-                if (parameters['no_sync'] !== undefined) {
-                    form['no_sync'] = parameters['no_sync'];
-                }
-
-                if (parameters['user'] !== undefined) {
-                    form['user'] = parameters['user'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['role'] !== undefined) {
-                    form['role'] = parameters['role'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xos#Service_Privilege_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xos.prototype.Service_Privilege_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xos/serviceprivileges/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xos.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return xos;
-        })();
-
-        return xos;
-    }]);/*jshint -W069 */
-/*global angular:false */
-angular.module('xos.xoslib', [])
-    .factory('xoslib', ['$q', '$http', '$rootScope', function($q, $http, $rootScope) {
-        'use strict';
-
-        /**
-         * 
-         * @class xoslib
-         * @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
-         * @param {string} [domainOrOptions.domain] - The project domain
-         * @param {string} [domainOrOptions.cache] - An angularjs cache implementation
-         * @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
-         * @param {string} [cache] - An angularjs cache implementation
-         */
-        var xoslib = (function() {
-            function xoslib(options, cache) {
-                var domain = (typeof options === 'object') ? options.domain : options;
-                this.domain = typeof(domain) === 'string' ? domain : 'http://localhost:9999';
-                cache = cache || ((typeof options === 'object') ? options.cache : cache);
-                this.cache = cache;
-            }
-
-            xoslib.prototype.$on = function($scope, path, handler) {
-                var url = domain + path;
-                $scope.$on(url, function() {
-                    handler();
-                });
-                return this;
-            };
-
-            xoslib.prototype.$broadcast = function(path) {
-                var url = domain + path;
-                //cache.remove(url);
-                $rootScope.$broadcast(url);
-                return this;
-            };
-
-            xoslib.transformRequest = function(obj) {
-                var str = [];
-                for (var p in obj) {
-                    var val = obj[p];
-                    if (angular.isArray(val)) {
-                        val.forEach(function(val) {
-                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                        });
-                    } else {
-                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(val));
-                    }
-                }
-                return str.join("&");
-            };
-
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_List_GET
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Monitoring_Channel_List_POST
-             * @param {string} provider_service - 
-             * 
-             */
-            xoslib.prototype.Monitoring_Channel_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/monitoringchannel/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Hpc_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Hpc_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/hpcview/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Hpc_List_GET
-             * 
-             */
-            xoslib.prototype.Hpc_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/hpcview/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/tenantview/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Tenant_List_GET
-             * 
-             */
-            xoslib.prototype.Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/tenantview/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Port_Forwarding_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Port_Forwarding_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/portforwarding/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Port_Forwarding_List_GET
-             * 
-             */
-            xoslib.prototype.Port_Forwarding_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/portforwarding/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Ssh_Key_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Ssh_Key_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/sshkeys/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Ssh_Key_List_GET
-             * 
-             */
-            xoslib.prototype.Ssh_Key_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/sshkeys/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Debug_get_vbng_dump
-             * 
-             */
-            xoslib.prototype.Cord_Debug_get_vbng_dump = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/cord_debug/vbng_dump/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_PUT
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_PATCH
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_List_GET
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_List_POST
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/cordsubscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_list
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_list = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_partial_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_partial_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_update
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_update = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_destroy
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_destroy = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_retrieve
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_retrieve = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_vcpe_synced
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_vcpe_synced = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/vcpe_synced/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_url_filter
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_url_filter = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/url_filter/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_set_url_filter
-             * @param {string} pk - 
-             * @param {string} level - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_set_url_filter = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/url_filter/{level}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{level}', parameters['level']);
-
-                if (parameters['level'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: level'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_services
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_services = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_enable_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_enable_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/true/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_disable_service
-             * @param {string} pk - 
-             * @param {string} service - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_disable_service = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/services/{service}/false/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{service}', parameters['service']);
-
-                if (parameters['service'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_users
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_clear_users
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_clear_users = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/clearusers/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/newuser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_create_user
-             * @param {string} pk - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_create_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/newuser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_delete_user
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_delete_user = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_user_level
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_user_level = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/url_filter/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_set_user_level
-             * @param {string} pk - 
-             * @param {string} uid - 
-             * @param {string} level - 
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_set_user_level = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/users/{uid}/url_filter/{level}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{uid}', parameters['uid']);
-
-                if (parameters['uid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: uid'));
-                    return deferred.promise;
-                }
-
-                path = path.replace('{level}', parameters['level']);
-
-                if (parameters['level'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: level'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_bbsdump
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_bbsdump = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subscriber/{pk}/bbsdump/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_initdemo
-             * @param {boolean} firewall_enable - 
-             * @param {string} firewall_rules - 
-             * @param {boolean} url_filter_enable - 
-             * @param {string} url_filter_rules - 
-             * @param {string} url_filter_level - 
-             * @param {boolean} vcpe_synced - 
-             * @param {boolean} cdn_enable - 
-             * @param {string} routeable_subnet - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_initdemo = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/initdemo/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['firewall_enable'] !== undefined) {
-                    form['firewall_enable'] = parameters['firewall_enable'];
-                }
-
-                if (parameters['firewall_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['firewall_rules'] !== undefined) {
-                    form['firewall_rules'] = parameters['firewall_rules'];
-                }
-
-                if (parameters['firewall_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: firewall_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_enable'] !== undefined) {
-                    form['url_filter_enable'] = parameters['url_filter_enable'];
-                }
-
-                if (parameters['url_filter_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_rules'] !== undefined) {
-                    form['url_filter_rules'] = parameters['url_filter_rules'];
-                }
-
-                if (parameters['url_filter_rules'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: url_filter_rules'));
-                    return deferred.promise;
-                }
-
-                if (parameters['url_filter_level'] !== undefined) {
-                    form['url_filter_level'] = parameters['url_filter_level'];
-                }
-
-                if (parameters['vcpe_synced'] !== undefined) {
-                    form['vcpe_synced'] = parameters['vcpe_synced'];
-                }
-
-                if (parameters['vcpe_synced'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vcpe_synced'));
-                    return deferred.promise;
-                }
-
-                if (parameters['cdn_enable'] !== undefined) {
-                    form['cdn_enable'] = parameters['cdn_enable'];
-                }
-
-                if (parameters['cdn_enable'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: cdn_enable'));
-                    return deferred.promise;
-                }
-
-                if (parameters['routeable_subnet'] !== undefined) {
-                    form['routeable_subnet'] = parameters['routeable_subnet'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_initdemo
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_initdemo = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/initdemo/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_ssiddetail
-             * @param {string} ssid - 
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_ssiddetail = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subidlookup/{ssid}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{ssid}', parameters['ssid']);
-
-                if (parameters['ssid'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: ssid'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_ssidlist
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_ssidlist = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/subidlookup/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_Subscriber_get_vbng_mapping
-             * 
-             */
-            xoslib.prototype.Cord_Subscriber_get_vbng_mapping = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/rs/vbng_mapping/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_PUT
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Cord_User_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_List_GET
-             * 
-             */
-            xoslib.prototype.Cord_User_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Cord_User_List_POST
-             * 
-             */
-            xoslib.prototype.Cord_User_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/corduser/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service_specific_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters['vlan_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vlan_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_List_GET
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Volt_Tenant_List_POST
-             * @param {string} provider_service - 
-             * @param {string} service_specific_id - 
-             * @param {string} vlan_id - 
-             * 
-             */
-            xoslib.prototype.Volt_Tenant_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/volttenant/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['provider_service'] !== undefined) {
-                    form['provider_service'] = parameters['provider_service'];
-                }
-
-                if (parameters['provider_service'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: provider_service'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service_specific_id'] !== undefined) {
-                    form['service_specific_id'] = parameters['service_specific_id'];
-                }
-
-                if (parameters['service_specific_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: service_specific_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters['vlan_id'] !== undefined) {
-                    form['vlan_id'] = parameters['vlan_id'];
-                }
-
-                if (parameters['vlan_id'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: vlan_id'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_GET
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_PUT
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_PUT = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PUT',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_PATCH
-             * @param {string} pk - 
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_PATCH = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'PATCH',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_Detail_DELETE
-             * @param {string} pk - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_Detail_DELETE = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/{pk}/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                path = path.replace('{pk}', parameters['pk']);
-
-                if (parameters['pk'] === undefined) {
-                    deferred.reject(new Error('Missing required path parameter: pk'));
-                    return deferred.promise;
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'DELETE',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_List_GET
-             * 
-             */
-            xoslib.prototype.Slice_Plus_List_GET = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var cached = parameters.$cache && parameters.$cache.get(url);
-                if (cached !== undefined && parameters.$refresh !== true) {
-                    deferred.resolve(cached);
-                    return deferred.promise;
-                }
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'GET',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-            /**
-             * 
-             * @method
-             * @name xoslib#Slice_Plus_List_POST
-             * @param {string} enacted - 
-             * @param {string} name - The Name of the Slice
-             * @param {boolean} enabled - Status for this Slice
-             * @param {boolean} omf_friendly - 
-             * @param {string} description - High level description of the slice and expected activities
-             * @param {string} slice_url - 
-             * @param {string} site - The Site this Slice belongs to
-             * @param {integer} max_instances - 
-             * @param {string} service - 
-             * @param {string} network - 
-             * @param {string} mount_data_sets - 
-             * @param {string} default_image - 
-             * @param {string} default_flavor - 
-             * @param {string} serviceClass - 
-             * @param {string} creator - 
-             * @param {string} network_ports - 
-             * @param {string} site_allocation - 
-             * @param {string} site_ready - 
-             * @param {string} users - 
-             * @param {string} user_names - 
-             * 
-             */
-            xoslib.prototype.Slice_Plus_List_POST = function(parameters) {
-                if (parameters === undefined) {
-                    parameters = {};
-                }
-                var deferred = $q.defer();
-
-                var domain = this.domain;
-                var path = '/xoslib/slicesplus/';
-
-                var body;
-                var queryParameters = {};
-                var headers = {};
-                var form = {};
-
-                if (parameters['enacted'] !== undefined) {
-                    form['enacted'] = parameters['enacted'];
-                }
-
-                if (parameters['name'] !== undefined) {
-                    form['name'] = parameters['name'];
-                }
-
-                if (parameters['name'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: name'));
-                    return deferred.promise;
-                }
-
-                if (parameters['enabled'] !== undefined) {
-                    form['enabled'] = parameters['enabled'];
-                }
-
-                if (parameters['omf_friendly'] !== undefined) {
-                    form['omf_friendly'] = parameters['omf_friendly'];
-                }
-
-                if (parameters['description'] !== undefined) {
-                    form['description'] = parameters['description'];
-                }
-
-                if (parameters['slice_url'] !== undefined) {
-                    form['slice_url'] = parameters['slice_url'];
-                }
-
-                if (parameters['site'] !== undefined) {
-                    form['site'] = parameters['site'];
-                }
-
-                if (parameters['site'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: site'));
-                    return deferred.promise;
-                }
-
-                if (parameters['max_instances'] !== undefined) {
-                    form['max_instances'] = parameters['max_instances'];
-                }
-
-                if (parameters['max_instances'] === undefined) {
-                    deferred.reject(new Error('Missing required form parameter: max_instances'));
-                    return deferred.promise;
-                }
-
-                if (parameters['service'] !== undefined) {
-                    form['service'] = parameters['service'];
-                }
-
-                if (parameters['network'] !== undefined) {
-                    form['network'] = parameters['network'];
-                }
-
-                if (parameters['mount_data_sets'] !== undefined) {
-                    form['mount_data_sets'] = parameters['mount_data_sets'];
-                }
-
-                if (parameters['default_image'] !== undefined) {
-                    form['default_image'] = parameters['default_image'];
-                }
-
-                if (parameters['default_flavor'] !== undefined) {
-                    form['default_flavor'] = parameters['default_flavor'];
-                }
-
-                if (parameters['serviceClass'] !== undefined) {
-                    form['serviceClass'] = parameters['serviceClass'];
-                }
-
-                if (parameters['creator'] !== undefined) {
-                    form['creator'] = parameters['creator'];
-                }
-
-                if (parameters['network_ports'] !== undefined) {
-                    form['network_ports'] = parameters['network_ports'];
-                }
-
-                if (parameters['site_allocation'] !== undefined) {
-                    form['site_allocation'] = parameters['site_allocation'];
-                }
-
-                if (parameters['site_ready'] !== undefined) {
-                    form['site_ready'] = parameters['site_ready'];
-                }
-
-                if (parameters['users'] !== undefined) {
-                    form['users'] = parameters['users'];
-                }
-
-                if (parameters['user_names'] !== undefined) {
-                    form['user_names'] = parameters['user_names'];
-                }
-
-                if (parameters.$queryParameters) {
-                    Object.keys(parameters.$queryParameters)
-                        .forEach(function(parameterName) {
-                            var parameter = parameters.$queryParameters[parameterName];
-                            queryParameters[parameterName] = parameter;
-                        });
-                }
-
-                var url = domain + path;
-                var options = {
-                    timeout: parameters.$timeout,
-                    method: 'POST',
-                    url: url,
-                    params: queryParameters,
-                    data: body,
-                    headers: headers
-                };
-                if (Object.keys(form).length > 0) {
-                    options.data = form;
-                    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
-                    options.transformRequest = xoslib.transformRequest;
-                }
-                $http(options)
-                    .success(function(data, status, headers, config) {
-                        deferred.resolve(data);
-                        if (parameters.$cache !== undefined) {
-                            parameters.$cache.put(url, data, parameters.$cacheItemOpts ? parameters.$cacheItemOpts : {});
-                        }
-                    })
-                    .error(function(data, status, headers, config) {
-                        deferred.reject({
-                            status: status,
-                            headers: headers,
-                            config: config,
-                            body: data
-                        });
-                    });
-
-                return deferred.promise;
-            };
-
-            return xoslib;
-        })();
-
-        return xoslib;
-    }]);
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xosDiagnostic.js b/xos/core/xoslib/static/js/xosDiagnostic.js
index 4e4def0..6214de7 100644
--- a/xos/core/xoslib/static/js/xosDiagnostic.js
+++ b/xos/core/xoslib/static/js/xosDiagnostic.js
@@ -1,2018 +1,2 @@
-//Autogenerated, do not edit!!!
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic', ['ngResource', 'ngCookies', 'ngLodash', 'ngAnimate', 'ui.router', 'xos.helpers']).config(["$stateProvider", function ($stateProvider) {
-    $stateProvider.state('home', {
-      url: '/',
-      template: '<diagnostic-container></diagnostic-container>'
-    });
-  }]).config(["$httpProvider", function ($httpProvider) {
-    $httpProvider.interceptors.push('NoHyperlinks');
-  }]).run(["$log", function ($log) {
-    $log.info('Diagnostic Started');
-  }]);
-})();
-angular.module("xos.diagnostic").run(["$templateCache", function($templateCache) {$templateCache.put("templates/diagnostic.tpl.html","<div class=\"container-fluid\">\n  <div ng-hide=\"vm.error && vm.loader\" style=\"height: 900px\">\n    <div class=\"onethird-height\">\n      <div class=\"well\">\n        Services Graph\n      </div>\n      <div class=\"well pull-right\" ng-click=\"vm.reloadGlobalScope()\" ng-show=\"vm.selectedSubscriber\">\n        Reset subscriber\n      </div>\n      <service-topology service-chain=\"vm.serviceChain\"></service-topology>\n    </div>\n    <div class=\"twothird-height\">\n      <div class=\"well\">\n        Logical Resources\n      </div>\n      <logic-topology ng-if=\"vm.subscribers\" subscribers=\"vm.subscribers\" selected=\"vm.selectedSubscriber\"></logic-topology>\n    </div>\n  </div>\n  <div class=\"row\" ng-if=\"vm.error\">\n    <div class=\"col-xs-12\">\n      <div class=\"alert alert-danger\">\n        {{vm.error}}\n      </div>\n    </div>\n  </div>\n  <div class=\"row\" ng-if=\"vm.loader\">\n    <div class=\"col-xs-12\">\n      <div class=\"loader\">Loading</div>\n    </div>\n  </div>\n</div>");
-$templateCache.put("templates/logicTopology.tpl.html","<select-subscriber-modal open=\"vm.openSelectSubscriberModal\" subscribers=\"vm.subscribers\"></select-subscriber-modal>\n<subscriber-status-modal open=\"vm.openSubscriberStatusModal\" subscriber=\"vm.currentSubscriber\"></subscriber-status-modal>\n<div class=\"alert alert-danger animate\" ng-hide=\"!vm.error\">\n  {{vm.error}}\n</div>\n<!-- <div class=\"instances-stats animate\" ng-hide=\"vm.hideInstanceStats\">\n  <div class=\"row\">\n    <div class=\"col-sm-3 col-sm-offset-8\">\n      <div class=\"panel panel-primary\" ng-repeat=\"instance in vm.selectedInstances\">\n        <div class=\"panel-heading\">\n          {{instance.humanReadableName}}\n        </div>\n          <ul class=\"list-group\">\n            <li class=\"list-group-item\">Backend Status: {{instance.backend_status}}</li>\n            <li class=\"list-group-item\">IP Address: {{instance.ip}}</li>\n          </ul>\n          <ul class=\"list-group\">\n            <li class=\"list-group-item\" ng-repeat=\"stat in instance.stats\">\n              <span class=\"badge\">{{stat.value}}</span>\n              {{stat.meter}}\n            </li>\n          </ul>\n        </div>\n      </div>  \n    </div>\n  </div>\n</div> -->");
-$templateCache.put("templates/select-subscriber-modal.tpl.html","<div class=\"modal fade\" ng-class=\"{in: vm.open}\" tabindex=\"-1\" role=\"dialog\">\n  <div class=\"modal-dialog modal-sm\">\n    <div class=\"modal-content\">\n      <div class=\"modal-header\">\n        <button ng-click=\"vm.close()\"  type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\n        <h4 class=\"modal-title\">Select a subscriber:</h4>\n      </div>\n      <div class=\"modal-body\">\n        <select class=\"form-control\" ng-options=\"s as s.humanReadableName for s in vm.subscribers\" ng-model=\"vm.selected\"></select>\n      </div>\n      <div class=\"modal-footer\">\n        <button ng-click=\"vm.close()\" type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n        <button ng-click=\"vm.select(vm.selected)\" type=\"button\" class=\"btn btn-primary\">Select</button>\n      </div>\n    </div><!-- /.modal-content -->\n  </div><!-- /.modal-dialog -->\n</div><!-- /.modal -->");
-$templateCache.put("templates/subscriber-status-modal.tpl.html","<div class=\"modal fade\" ng-class=\"{in: vm.open}\" tabindex=\"-1\" role=\"dialog\">\n  <div class=\"modal-dialog modal-sm\">\n    <div class=\"modal-content\">\n      <div class=\"modal-header\">\n        <button ng-click=\"vm.close()\"  type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\n        <h4 class=\"modal-title\">Manage subscriber:</h4>\n      </div>\n      <form name=\"vm.subscriber-detail\">\n        <div class=\"modal-body\">\n          <div class=\"row\">\n            <div class=\"col-xs-12\">\n              <label>Status</label>\n            </div>\n            <div class=\"col-xs-6\">\n              <a ng-click=\"vm.subscriber.status = \'enabled\'\"\n                class=\"btn btn-block\"\n                ng-class=\"{\'btn-primary\': vm.subscriber.status === \'enabled\' ,\'btn-default\': vm.subscriber.status !== \'enabled\'}\"\n                >Enabled</a>\n            </div>\n            <div class=\"col-xs-6\">\n              <a ng-click=\"vm.subscriber.status = \'suspended\'\"\n                class=\"btn btn-block\"\n                ng-class=\"{\'btn-primary\': vm.subscriber.status === \'suspended\' ,\'btn-default\': vm.subscriber.status !== \'suspended\'}\"\n                >Suspended</a>\n            </div>\n          </div>\n          <div class=\"row\">\n            <div class=\"col-xs-6\">\n              <a ng-click=\"vm.subscriber.status = \'delinquent\'\"\n                class=\"btn btn-block\"\n                ng-class=\"{\'btn-primary\': vm.subscriber.status === \'delinquent\' ,\'btn-default\': vm.subscriber.status !== \'delinquent\'}\"\n                >Delinquent <br> payment</a>\n            </div>\n            <div class=\"col-xs-6\">\n              <a ng-click=\"vm.subscriber.status = \'copyrightviolation\'\"\n                class=\"btn btn-block\"\n                ng-class=\"{\'btn-primary\': vm.subscriber.status === \'copyrightviolation\' ,\'btn-default\': vm.subscriber.status !== \'copyrightviolation\'}\"\n                >Copyright <br> violation</a>\n            </div>\n          </div>\n          <div class=\"row\">\n            <div class=\"col-xs-6\">\n              <label>Uplink Speed</label>\n              <div class=\"input-group\">\n                <input type=\"number\" class=\"form-control small-padding\" ng-model=\"vm.subscriber.uplink_speed\"/>\n                <span class=\"input-group-addon\">Mbps</span>\n              </div>\n            </div>\n            <div class=\"col-xs-6\">\n              <label>Downlink Speed</label>\n              <div class=\"input-group\">\n                <input type=\"number\" class=\"form-control small-padding\" ng-model=\"vm.subscriber.downlink_speed\"/>\n                <span class=\"input-group-addon\">Mbps</span>\n              </div>\n            </div>\n          </div>\n          <div class=\"row\">\n            <div class=\"col-xs-6\">\n              <label>Enable Internet</label>\n            </div>\n            <div class=\"col-xs-6\">\n              <a \n                ng-click=\"vm.subscriber.enable_uverse = !vm.subscriber.enable_uverse\" \n                ng-class=\"{\'btn-success\': vm.subscriber.enable_uverse, \'btn-danger\': !vm.subscriber.enable_uverse}\"\n                class=\"btn btn-block\">\n                <span ng-show=\"vm.subscriber.enable_uverse === true\">Enabled</span>\n                <span ng-show=\"vm.subscriber.enable_uverse !== true\">Disabled</span>\n              </a>\n            </div>\n          </div>\n        </div>\n        <div class=\"modal-footer\" ng-show=\"vm.success || vm.formError\">\n          <div class=\"alert alert-success\" ng-show=\"vm.success\">\n            {{vm.success}}\n          </div>\n          <div class=\"alert alert-danger\" ng-show=\"vm.formError\">\n            {{vm.formError}}\n          </div>\n        </div>\n        <div class=\"modal-footer\">\n          <button ng-click=\"vm.close()\" type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n          <button ng-click=\"vm.updateSubscriber(vm.subscriber)\" type=\"button\" class=\"btn btn-primary\">Save</button>\n        </div>\n      </form>\n    </div><!-- /.modal-content -->\n  </div><!-- /.modal-dialog -->\n</div><!-- /.modal -->");}]);
-'use strict';
-
-(function () {
-  'use strict';
-  angular.module('xos.diagnostic').directive('selectSubscriberModal', function () {
-    return {
-      scope: {
-        subscribers: '=',
-        open: '='
-      },
-      bindToController: true,
-      restrict: 'E',
-      templateUrl: 'templates/select-subscriber-modal.tpl.html',
-      controllerAs: 'vm',
-      controller: ["$rootScope", function controller($rootScope) {
-        var _this = this;
-
-        this.close = function () {
-          _this.open = false;
-        };
-
-        this.select = function (subscriber) {
-          $rootScope.$emit('subscriber.selected', subscriber);
-          _this.close();
-        };
-      }]
-    };
-  }).directive('subscriberStatusModal', function () {
-    return {
-      scope: {
-        open: '=',
-        subscriber: '='
-      },
-      bindToController: true,
-      restrict: 'E',
-      templateUrl: 'templates/subscriber-status-modal.tpl.html',
-      controllerAs: 'vm',
-      controller: ["$log", "$timeout", "$scope", "Subscribers", function controller($log, $timeout, $scope, Subscribers) {
-        var _this2 = this;
-
-        var mb = 1000000;
-
-        $scope.$watch(function () {
-          return _this2.open;
-        }, function () {
-          _this2.success = null;
-          _this2.formError = null;
-        });
-
-        $scope.$watch(function () {
-          return _this2.subscriber;
-        }, function (newVal, oldVal) {
-          if (!_this2.subscriber) {
-            return;
-          }
-          console.log(newVal, oldVal);
-          console.log('subscriber change', newVal === oldVal);
-          _this2.subscriber.uplink_speed = parseInt(_this2.subscriber.uplink_speed, 10) / mb;
-          _this2.subscriber.downlink_speed = parseInt(_this2.subscriber.downlink_speed, 10) / mb;
-        });
-
-        this.close = function () {
-          _this2.open = false;
-        };
-
-        this.updateSubscriber = function (subscriber) {
-
-          // TODO Copy the subscriber, this will update the GUI also and we don't want
-          // TODO Change GBps to MBps
-
-          var body = angular.copy(subscriber, body);
-
-          body.uplink_speed = body.uplink_speed * mb;
-          body.downlink_speed = body.downlink_speed * mb;
-
-          Subscribers.update(body).$promise.then(function (res) {
-            _this2.success = 'Subscriber successfully updated!';
-          })['catch'](function (e) {
-            _this2.formError = e;
-          })['finally'](function () {
-            $timeout(function () {
-              _this2.close();
-            }, 1500);
-          });
-        };
-      }]
-    };
-  });
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').service('ServiceTopologyHelper', ["$rootScope", "$window", "$log", "lodash", "ServiceRelation", "serviceTopologyConfig", "d3", function ($rootScope, $window, $log, lodash, ServiceRelation, serviceTopologyConfig, d3) {
-
-    var _svg, _layout, _source, _el;
-
-    var i = 0;
-
-    // given a canvas, a layout and a data source, draw a tree layout
-    var updateTree = function updateTree(svg, layout, source) {
-      var el = arguments.length <= 3 || arguments[3] === undefined ? _el : arguments[3];
-
-      if (el) {
-        _el = el;
-      }
-
-      var targetWidth = _el.clientWidth - serviceTopologyConfig.widthMargin * 2;
-
-      //cache data
-      _svg = svg;
-      _layout = layout;
-      _source = source;
-
-      var maxDepth = ServiceRelation.depthOf(source);
-
-      var diagonal = d3.svg.diagonal().projection(function (d) {
-        return [d.y, d.x];
-      });
-
-      // Compute the new tree layout.
-      var nodes = layout.nodes(source).reverse(),
-          links = layout.links(nodes);
-
-      // Normalize for fixed-depth.
-      nodes.forEach(function (d) {
-        // position the child node horizontally
-        var step = (targetWidth - serviceTopologyConfig.widthMargin * 2) / (maxDepth - 1);
-        d.y = d.depth * step;
-      });
-
-      // Update the nodes…
-      var node = svg.selectAll('g.node').data(nodes, function (d) {
-        return d.id || (d.id = ++i);
-      });
-
-      // Enter any new nodes at the parent's previous position.
-      var nodeEnter = node.enter().append('g').attr({
-        'class': function _class(d) {
-          return 'node ' + d.type;
-        },
-        transform: function transform(d) {
-          return d.x && d.y ? 'translate(' + d.y + ', ' + d.x + ')' : 'translate(' + source.y0 + ', ' + source.x0 + ')';
-        }
-      });
-
-      var subscriberNodes = nodeEnter.filter('.subscriber');
-      var internetNodes = nodeEnter.filter('.router');
-      var serviceNodes = nodeEnter.filter('.service');
-
-      subscriberNodes.append('rect').attr(serviceTopologyConfig.square)
-      // add event listener to subscriber
-      .on('click', function () {
-        $rootScope.$emit('subscriber.modal.open');
-      });
-
-      internetNodes.append('rect').attr(serviceTopologyConfig.square);
-
-      serviceNodes.append('circle').attr('r', 1e-6).style('fill', function (d) {
-        return d._children ? 'lightsteelblue' : '#fff';
-      }).on('click', serviceClick);
-
-      nodeEnter.append('text').attr({
-        x: function x(d) {
-          return d.children ? -serviceTopologyConfig.circle.selectedRadius - 5 : serviceTopologyConfig.circle.selectedRadius + 5;
-        },
-        dy: '.35em',
-        y: function y(d) {
-          if (d.children && d.parent) {
-            return '-5';
-          }
-        },
-        transform: function transform(d) {
-          if (d.children && d.parent) {
-            if (d.parent.x < d.x) {
-              return 'rotate(-30)';
-            }
-            return 'rotate(30)';
-          }
-        },
-        'text-anchor': function textAnchor(d) {
-          return d.children ? 'end' : 'start';
-        }
-      }).text(function (d) {
-        return d.name;
-      }).style('fill-opacity', 1e-6);
-
-      // Transition nodes to their new position.
-      var nodeUpdate = node.transition().duration(serviceTopologyConfig.duration).attr({
-        'transform': function transform(d) {
-          return 'translate(' + d.y + ',' + d.x + ')';
-        }
-      });
-
-      nodeUpdate.select('circle').attr('r', function (d) {
-        return d.selected ? serviceTopologyConfig.circle.selectedRadius : serviceTopologyConfig.circle.radius;
-      }).style('fill', function (d) {
-        return d.selected ? 'lightsteelblue' : '#fff';
-      });
-
-      nodeUpdate.select('text').style('fill-opacity', 1);
-
-      // Transition exiting nodes to the parent's new position.
-      var nodeExit = node.exit().transition().duration(serviceTopologyConfig.duration).remove();
-
-      nodeExit.select('circle').attr('r', 1e-6);
-
-      nodeExit.select('text').style('fill-opacity', 1e-6);
-
-      // Update the links…
-      var link = svg.selectAll('path.link').data(links, function (d) {
-        return d.target.id;
-      });
-
-      // Enter any new links at the parent's previous position.
-      link.enter().insert('path', 'g').attr('class', function (d) {
-        return 'link ' + d.target.type + ' ' + (d.target.active ? '' : 'active');
-      }).attr('d', function (d) {
-        var o = { x: source.x0, y: source.y0 };
-        return diagonal({ source: o, target: o });
-      });
-
-      // Transition links to their new position.
-      link.transition().duration(serviceTopologyConfig.duration).attr('d', diagonal);
-
-      // Transition exiting nodes to the parent's new position.
-      link.exit().transition().duration(serviceTopologyConfig.duration).attr('d', function (d) {
-        var o = { x: source.x, y: source.y };
-        return diagonal({ source: o, target: o });
-      }).remove();
-
-      // Stash the old positions for transition.
-      nodes.forEach(function (d) {
-        d.x0 = d.x;
-        d.y0 = d.y;
-      });
-    };
-
-    var serviceClick = function serviceClick(d) {
-
-      // if was selected
-      if (d.selected) {
-        d.selected = !d.selected;
-        $rootScope.$emit('instance.detail.hide', {});
-        return updateTree(_svg, _layout, _source);
-      }
-
-      $rootScope.$emit('instance.detail', { name: d.name, service: d.service, tenant: d.tenant });
-
-      // unselect all
-      _svg.selectAll('circle').each(function (d) {
-        return d.selected = false;
-      });
-
-      // toggling selected status
-      d.selected = !d.selected;
-
-      updateTree(_svg, _layout, _source);
-    };
-
-    this.updateTree = updateTree;
-  }]);
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').directive('serviceTopology', function () {
-    return {
-      restrict: 'E',
-      scope: {
-        serviceChain: '='
-      },
-      bindToController: true,
-      controllerAs: 'vm',
-      template: '',
-      controller: ["$element", "$window", "$scope", "d3", "serviceTopologyConfig", "ServiceRelation", "Slice", "Instances", "Subscribers", "ServiceTopologyHelper", function controller($element, $window, $scope, d3, serviceTopologyConfig, ServiceRelation, Slice, Instances, Subscribers, ServiceTopologyHelper) {
-        var _this = this;
-
-        var el = $element[0];
-
-        d3.select(window).on('resize.service', function () {
-          draw(_this.serviceChain);
-        });
-
-        var root, svg;
-
-        var draw = function draw(tree) {
-
-          if (!tree) {
-            console.error('Tree is missing');
-            return;
-          }
-
-          // TODO update instead clear and redraw
-
-          // clean
-          d3.select($element[0]).select('svg').remove();
-
-          var width = el.clientWidth - serviceTopologyConfig.widthMargin * 2;
-          var height = el.clientHeight - serviceTopologyConfig.heightMargin * 2;
-
-          var treeLayout = d3.layout.tree().size([height, width]);
-
-          svg = d3.select($element[0]).append('svg').style('width', el.clientWidth + 'px').style('height', el.clientHeight + 'px');
-
-          var treeContainer = svg.append('g').attr('transform', 'translate(' + serviceTopologyConfig.widthMargin * 2 + ',' + serviceTopologyConfig.heightMargin + ')');
-
-          root = tree;
-          root.x0 = height / 2;
-          root.y0 = width / 2;
-
-          // ServiceTopologyHelper.drawLegend(svg);
-          ServiceTopologyHelper.updateTree(treeContainer, treeLayout, root, el);
-        };
-
-        $scope.$watch(function () {
-          return _this.serviceChain;
-        }, function (chain) {
-          if (angular.isDefined(chain)) {
-            draw(chain);
-          }
-        });
-      }]
-    };
-  });
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').service('Services', ["$resource", function ($resource) {
-    return $resource('/xos/services/:id', { id: '@id' });
-  }]).service('Tenant', ["$resource", function ($resource) {
-    return $resource('/xos/tenants', { id: '@id' }, {
-      queryVsgInstances: {
-        method: 'GET',
-        isArray: true,
-        interceptor: {
-          response: function response(res) {
-
-            // NOTE
-            // Note that VCPETenant is now VSGTenant.
-
-            var instances = [];
-
-            angular.forEach(res.data, function (tenant) {
-              var info = JSON.parse(tenant.service_specific_attribute);
-              if (info && info.instance_id) {
-                instances.push(info.instance_id);
-              }
-            });
-
-            return instances;
-          }
-        }
-      },
-      getSubscriberTag: {
-        method: 'GET',
-        isArray: true,
-        interceptor: {
-          response: function response(res) {
-            // NOTE we should receive only one vOLT tenant here
-            return JSON.parse(res.data[0].service_specific_attribute);
-          }
-        }
-      }
-    });
-  }]).service('Ceilometer', ["$http", "$q", "Instances", function ($http, $q, Instances) {
-    var _this = this;
-
-    /**
-    * Get stats for a single instance
-    */
-    this.getInstanceStats = function (instanceUuid) {
-      var deferred = $q.defer();
-
-      $http.get('/xoslib/xos-instance-statistics', { params: { 'instance-uuid': instanceUuid } }).then(function (res) {
-        deferred.resolve(res.data);
-      })['catch'](function (e) {
-        deferred.reject(e);
-      });
-
-      return deferred.promise;
-    };
-
-    /**
-    * Collect stats for an array of instances
-    */
-    this.getInstancesStats = function (instances) {
-      var deferred = $q.defer();
-      var instancePromises = [];
-      var instanceList = [];
-
-      // retrieve instance details
-      instances.forEach(function (instanceId) {
-        instancePromises.push(Instances.get({ id: instanceId }).$promise);
-      });
-
-      // get all instance data
-      $q.all(instancePromises).then(function (_instanceList) {
-        instanceList = _instanceList;
-        var promises = [];
-        // foreach instance query stats
-        instanceList.forEach(function (instance) {
-          promises.push(_this.getInstanceStats(instance.instance_uuid));
-        });
-        return $q.all(promises);
-      }).then(function (stats) {
-        // augment instance with stats information
-        instanceList.map(function (instance, i) {
-          instance.stats = stats[i];
-        });
-        deferred.resolve(instanceList);
-      })['catch'](deferred.reject);
-
-      return deferred.promise;
-    };
-
-    this.getContainerStats = function (containerName) {
-      var deferred = $q.defer();
-
-      var res = {};
-
-      $http.get('/xoslib/meterstatistics', { params: { 'resource': containerName } }).then(function (containerStats) {
-        res.stats = containerStats.data;
-        return $http.get('/xoslib/meterstatistics', { params: { 'resource': containerName + '-eth0' } });
-      }).then(function (portStats) {
-        res.port = {
-          eth0: portStats.data
-        };
-        return $http.get('/xoslib/meterstatistics', { params: { 'resource': containerName + '-eth1' } });
-      }).then(function (portStats) {
-        res.port.eth1 = portStats.data;
-        deferred.resolve(res);
-      })['catch'](function (e) {
-        deferred.reject(e);
-      });
-
-      return deferred.promise;
-    };
-  }]).service('Slice', ["$resource", function ($resource) {
-    return $resource('/xos/slices', { id: '@id' });
-  }]).service('Instances', ["$resource", function ($resource) {
-    return $resource('/xos/instances/:id', { id: '@id' });
-  }]).service('Node', ["$resource", "$q", "Instances", function ($resource, $q, Instances) {
-    return $resource('/xos/nodes', { id: '@id' }, {
-      queryWithInstances: {
-        method: 'GET',
-        isArray: true,
-        interceptor: {
-          response: function response(res) {
-
-            // TODO update the API to include instances in nodes
-            // http://stackoverflow.com/questions/14573102/how-do-i-include-related-model-fields-using-django-rest-framework
-
-            var deferred = $q.defer();
-
-            var requests = [];
-
-            angular.forEach(res.data, function (node) {
-              requests.push(Instances.query({ node: node.id }).$promise);
-            });
-
-            $q.all(requests).then(function (list) {
-              res.data.map(function (node, i) {
-                node.instances = list[i];
-                return node;
-              });
-              deferred.resolve(res.data);
-            });
-
-            return deferred.promise;
-          }
-        }
-      }
-    });
-  }]).service('Subscribers', ["$resource", "$q", "SubscriberDevice", function ($resource, $q, SubscriberDevice) {
-    return $resource('/xoslib/cordsubscriber/:id', { id: '@id' }, {
-      update: {
-        method: 'PUT',
-        isArray: false
-      },
-      queryWithDevices: {
-        method: 'GET',
-        isArray: true,
-        interceptor: {
-          response: function response(res) {
-
-            /**
-            * For each subscriber retrieve devices and append them
-            */
-
-            var deferred = $q.defer();
-
-            var requests = [];
-
-            angular.forEach(res.data, function (subscriber) {
-              requests.push(SubscriberDevice.query({ id: subscriber.id }).$promise);
-            });
-
-            $q.all(requests).then(function (list) {
-
-              // adding devices
-
-              res.data.map(function (subscriber, i) {
-                subscriber.devices = list[i];
-                subscriber.type = 'subscriber';
-
-                subscriber.devices.map(function (d) {
-                  return d.type = 'device';
-                });
-
-                return subscriber;
-              });
-
-              // faking to have 2 subscriber
-              // res.data.push(angular.copy(res.data[0]));
-
-              deferred.resolve(res.data);
-            });
-
-            return deferred.promise;
-          }
-        }
-      },
-      getWithDevices: {
-        method: 'GET',
-        isArray: false,
-        interceptor: {
-          response: function response(res) {
-            var d = $q.defer();
-
-            SubscriberDevice.query({ id: res.data.id }).$promise.then(function (devices) {
-              devices.map(function (d) {
-                return d.type = 'device';
-              });
-              res.data.devices = devices;
-              res.data.type = 'subscriber';
-              d.resolve(res.data);
-            })['catch'](function (err) {
-              d.reject(err);
-            });
-
-            return d.promise;
-          }
-        }
-      }
-    });
-  }]).service('SubscriberDevice', ["$resource", function ($resource) {
-    return $resource('/xoslib/rs/subscriber/:id/users/', { id: '@id' });
-  }]).service('ServiceRelation', ["$q", "lodash", "Services", "Tenant", "Slice", "Instances", function ($q, lodash, Services, Tenant, Slice, Instances) {
-
-    // count the mas depth of an object
-    var depthOf = function depthOf(obj) {
-      var depth = 0;
-      if (obj.children) {
-        obj.children.forEach(function (d) {
-          var tmpDepth = depthOf(d);
-          if (tmpDepth > depth) {
-            depth = tmpDepth;
-          }
-        });
-      }
-      return 1 + depth;
-    };
-
-    // find all the relation defined for a given root
-    var findLevelRelation = function findLevelRelation(tenants, rootId) {
-      return lodash.filter(tenants, function (service) {
-        return service.subscriber_service === rootId;
-      });
-    };
-
-    var findSpecificInformation = function findSpecificInformation(tenants, rootId) {
-      var tenants = lodash.filter(tenants, function (service) {
-        return service.provider_service === rootId && service.subscriber_tenant;
-      });
-
-      var info;
-
-      tenants.forEach(function (tenant) {
-        if (tenant.service_specific_attribute) {
-          info = JSON.parse(tenant.service_specific_attribute);
-        }
-      });
-
-      return info;
-    };
-
-    // find all the service defined by a given array of relations
-    var findLevelServices = function findLevelServices(relations, services) {
-      var levelServices = [];
-      lodash.forEach(relations, function (tenant) {
-        var service = lodash.find(services, { id: tenant.provider_service });
-        levelServices.push(service);
-      });
-      return levelServices;
-    };
-
-    var buildLevel = function buildLevel(tenants, services, rootService, rootTenant) {
-      var parentName = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4];
-
-      // build an array of unlinked services
-      // these are the services that should still placed in the tree
-      var unlinkedServices = lodash.difference(services, [rootService]);
-
-      // find all relations relative to this rootElement
-      var levelRelation = findLevelRelation(tenants, rootService.id);
-      // find all items related to rootElement
-      var levelServices = findLevelServices(levelRelation, services);
-
-      // remove this item from the list (performance
-      unlinkedServices = lodash.difference(unlinkedServices, levelServices);
-
-      rootService.service_specific_attribute = findSpecificInformation(tenants, rootService.id);
-
-      if (rootService.humanReadableName === 'service_vbng') {
-        rootService.humanReadableName = 'service_vrouter';
-      }
-
-      var tree = {
-        name: rootService.humanReadableName,
-        parent: parentName,
-        type: 'service',
-        service: rootService,
-        tenant: rootTenant,
-        children: []
-      };
-
-      lodash.forEach(levelServices, function (service) {
-        if (service.humanReadableName === 'service_ONOS_vBNG' || service.humanReadableName === 'service_ONOS_vOLT') {
-          // remove ONOSes from service chart
-          return;
-        }
-        var tenant = lodash.find(tenants, { subscriber_tenant: rootTenant.id, provider_service: service.id });
-        tree.children.push(buildLevel(tenants, unlinkedServices, service, tenant, rootService.humanReadableName));
-      });
-
-      // if it is the last element append internet
-      if (tree.children.length === 0) {
-        tree.children.push({
-          name: 'Router',
-          type: 'router',
-          children: []
-        });
-      }
-
-      return tree;
-    };
-
-    var buildSubscriberServiceTree = function buildSubscriberServiceTree(services, tenants) {
-      var subscriber = arguments.length <= 2 || arguments[2] === undefined ? { id: 1, name: 'fakeSubs' } : arguments[2];
-
-      // find the root service
-      // it is the one attached to subsriber_root
-      // as now we have only one root so this can work
-      var rootTenant = lodash.find(tenants, { subscriber_root: subscriber.id });
-      var rootService = lodash.find(services, { id: rootTenant.provider_service });
-
-      var serviceTree = buildLevel(tenants, services, rootService, rootTenant);
-
-      return {
-        name: subscriber.name || subscriber.humanReadableName,
-        parent: null,
-        type: 'subscriber',
-        children: [serviceTree]
-      };
-    };
-
-    // applying domain knowledge to build the global service tree
-    var buildServiceTree = function buildServiceTree(services, tenants) {
-
-      // TODO refactor
-      var buildChild = function buildChild(services, tenants, currentService) {
-
-        if (currentService.humanReadableName === 'service_vbng') {
-          currentService.humanReadableName = 'service_vrouter';
-        }
-
-        var response = {
-          type: 'service',
-          name: currentService.humanReadableName,
-          service: currentService
-        };
-
-        var tenant = lodash.find(tenants, { subscriber_service: currentService.id });
-        if (tenant) {
-          var next = lodash.find(services, { id: tenant.provider_service });
-          response.children = [buildChild(services, tenants, next)];
-        } else {
-          response.children = [{
-            name: 'Router',
-            type: 'router',
-            children: []
-          }];
-        }
-        delete currentService.id; // conflict with d3
-        return response;
-      };
-
-      var baseService = lodash.find(services, { id: 3 });
-
-      if (!angular.isDefined(baseService)) {
-        console.error('Missing Base service!');
-        return;
-      }
-
-      var baseData = {
-        name: 'Subscriber',
-        type: 'subscriber',
-        parent: null,
-        children: [buildChild(services, tenants, baseService)]
-      };
-      return baseData;
-    };
-
-    var getBySubscriber = function getBySubscriber(subscriber) {
-      var deferred = $q.defer();
-      var services, tenants;
-      Services.query().$promise.then(function (res) {
-        services = res;
-        return Tenant.query().$promise;
-      }).then(function (res) {
-        tenants = res;
-        deferred.resolve(buildSubscriberServiceTree(services, tenants, subscriber));
-      })['catch'](function (e) {
-        throw new Error(e);
-      });
-
-      return deferred.promise;
-    };
-
-    var get = function get() {
-      var deferred = $q.defer();
-      var services, tenants;
-      Services.query().$promise.then(function (res) {
-        services = res;
-        return Tenant.query({ kind: 'coarse' }).$promise;
-      }).then(function (res) {
-        tenants = res;
-        deferred.resolve(buildServiceTree(services, tenants));
-      })['catch'](function (e) {
-        throw new Error(e);
-      });
-
-      return deferred.promise;
-    };
-
-    // export APIs
-    return {
-      get: get,
-      buildServiceTree: buildServiceTree,
-      getBySubscriber: getBySubscriber,
-      buildLevel: buildLevel,
-      buildSubscriberServiceTree: buildSubscriberServiceTree,
-      findLevelRelation: findLevelRelation,
-      findLevelServices: findLevelServices,
-      depthOf: depthOf,
-      findSpecificInformation: findSpecificInformation
-    };
-  }]);
-})();
-'use strict';
-
-var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
-
-(function () {
-  angular.module('xos.diagnostic').service('RackHelper', ["serviceTopologyConfig", "lodash", function (serviceTopologyConfig, lodash) {
-    var _this = this;
-
-    this.getComputeNodeLabelSize = function () {
-      return serviceTopologyConfig.computeNode.labelHeight + serviceTopologyConfig.instance.margin * 2;
-    };
-
-    /**
-    * Given a list of instance should get the Compute Node size.
-    * They are placed in rows of 2 with 5px margin on each side.
-    */
-
-    this.getComputeNodeSize = lodash.memoize(function (instances) {
-      var width = serviceTopologyConfig.instance.margin * 3 + serviceTopologyConfig.instance.width * 2;
-
-      var rows = Math.round(instances.length / 2);
-
-      var labelSpace = _this.getComputeNodeLabelSize();
-
-      var height = serviceTopologyConfig.instance.height * rows + serviceTopologyConfig.instance.margin * (rows + 1) + labelSpace;
-
-      return [width, height];
-    });
-
-    /**
-    * Give a list on Compute Node should calculate the Rack Size.
-    * Compute nodes are placed in a single column with 5px margin on each side.
-    */
-    this.getRackSize = function (nodes) {
-
-      var width = 0;
-      var height = serviceTopologyConfig.computeNode.margin;
-
-      lodash.forEach(nodes, function (node) {
-        var _getComputeNodeSize = _this.getComputeNodeSize(node.instances);
-
-        var _getComputeNodeSize2 = _slicedToArray(_getComputeNodeSize, 2);
-
-        var nodeWidth = _getComputeNodeSize2[0];
-        var nodeHeight = _getComputeNodeSize2[1];
-
-        width = nodeWidth + serviceTopologyConfig.computeNode.margin * 2;
-        height += nodeHeight + serviceTopologyConfig.computeNode.margin;
-      });
-
-      return [width, height];
-    };
-
-    /**
-    * Given an instance index, return the coordinates
-    */
-
-    this.getInstancePosition = function (position) {
-      var row = Math.floor(position / 2);
-      var column = position % 2 ? 1 : 0;
-
-      // add ComputeNode label size
-      var labelSpace = _this.getComputeNodeLabelSize();
-
-      // x = margin + (width * column) + ( maring * column)
-      var x = serviceTopologyConfig.instance.margin + serviceTopologyConfig.instance.width * column + serviceTopologyConfig.instance.margin * column;
-
-      // y = label + margin + (height * row) + ( maring * row)
-      var y = labelSpace + serviceTopologyConfig.instance.margin + serviceTopologyConfig.instance.height * row + serviceTopologyConfig.instance.margin * row;
-      return [x, y];
-    };
-
-    /**
-    * Given an Compute Node index, return the coordinates
-    */
-
-    this.getComputeNodePosition = function (nodes, position) {
-
-      var x = serviceTopologyConfig.computeNode.margin;
-
-      var previousElEight = lodash.reduce(nodes.slice(0, position), function (val, node) {
-        return val + _this.getComputeNodeSize(node.instances)[1];
-      }, 0);
-
-      var y = serviceTopologyConfig.computeNode.margin + serviceTopologyConfig.computeNode.margin * position + previousElEight;
-
-      return [x, y];
-    };
-  }]);
-})();
-'use strict';
-
-var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
-
-(function () {
-  'use strict';
-
-  var shapes = {
-    cloud: ' M 79.72 49.60 C 86.00 37.29 98.57 29.01 111.96 26.42 C 124.27 24.11 137.53 26.15 148.18 32.90 C 158.08 38.78 165.39 48.87 167.65 60.20 C 176.20 57.90 185.14 56.01 194.00 57.73 C 206.08 59.59 217.92 66.01 224.37 76.66 C 227.51 81.54 228.85 87.33 229.23 93.06 C 237.59 93.33 246.22 95.10 253.04 100.19 C 256.69 103.13 259.87 107.67 258.91 112.59 C 257.95 118.43 252.78 122.38 247.78 124.82 C 235.27 130.43 220.23 130.09 207.98 123.93 C 199.33 127.88 189.76 129.43 180.30 128.57 C 173.70 139.92 161.70 147.65 148.86 149.93 C 133.10 153.26 116.06 148.15 104.42 137.08 C 92.98 143.04 78.96 143.87 66.97 139.04 C 57.75 135.41 49.70 128.00 46.60 118.43 C 43.87 109.95 45.81 100.29 51.30 93.32 C 57.38 85.18 67.10 80.44 76.99 78.89 C 74.38 69.20 74.87 58.52 79.72 49.60 Z'
-  };
-
-  var computeNodeId = 0;
-  var instanceId = 0;
-
-  angular.module('xos.diagnostic').service('NodeDrawer', ["d3", "serviceTopologyConfig", "RackHelper", "lodash", function (d3, serviceTopologyConfig, RackHelper, lodash) {
-    var _this2 = this;
-
-    var _this = this;
-
-    this.addNetworks = function (nodes) {
-
-      // clean childs
-      nodes.selectAll('*').remove();
-
-      nodes.append('path').attr({
-        d: shapes.cloud,
-        transform: 'translate(-100, -72), scale(0.7)',
-        'class': 'cloud'
-      });
-
-      nodes.append('text').attr({
-        'text-anchor': 'middle',
-        y: -5,
-        x: 5
-      }).text(function (d) {
-        return d.name;
-      });
-
-      nodes.append('text').attr({
-        'text-anchor': 'middle',
-        y: 8,
-        x: 5,
-        'class': 'small'
-      }).text(function (d) {
-        return d.subtitle;
-      });
-
-      nodes.each(function (n) {
-        var currentNode = d3.select(this);
-        // cicle trouch node to add Tags and Public IP
-        if (n.name === 'LAN-Side' && angular.isDefined(n.subscriberTag)) {
-          currentNode.append('text').attr({
-            'text-anchor': 'middle',
-            y: 50
-          }).text(function () {
-            return 'C-Tag: ' + n.subscriberTag.cTag;
-          });
-
-          currentNode.append('text').attr({
-            'text-anchor': 'middle',
-            y: 70
-          }).text(function () {
-            return 'S-Tag: ' + n.subscriberTag.sTag;
-          });
-        }
-
-        if (n.name === 'WAN-Side' && angular.isDefined(n.subscriberIP)) {
-          currentNode.append('text').attr({
-            'text-anchor': 'middle',
-            y: 50
-          }).text(function () {
-            return 'Public IP: ' + n.subscriberIP;
-          });
-        }
-      });
-    };
-
-    this.addRack = function (nodes) {
-
-      // loop because of D3
-      // rack will be only one
-      nodes.each(function (d) {
-        var _RackHelper$getRackSize = RackHelper.getRackSize(d.computeNodes);
-
-        var _RackHelper$getRackSize2 = _slicedToArray(_RackHelper$getRackSize, 2);
-
-        var w = _RackHelper$getRackSize2[0];
-        var h = _RackHelper$getRackSize2[1];
-
-        // TODO update instead of delete and redraw
-        nodes.select('g').remove();
-
-        var rack = nodes.append('g');
-
-        rack.attr({
-          transform: 'translate(0,0)'
-        }).transition().duration(serviceTopologyConfig.duration).attr({
-          transform: function transform() {
-            return 'translate(' + -(w / 2) + ', ' + -(h / 2) + ')';
-          }
-        });
-
-        rack.append('rect').attr({
-          width: 0,
-          height: 0
-        }).transition().duration(serviceTopologyConfig.duration).attr({
-          width: w,
-          height: h
-        });
-
-        rack.append('text').attr({
-          'text-anchor': 'middle',
-          y: -10,
-          x: w / 2,
-          opacity: 0
-        }).text(function (d) {
-          return d.name;
-        }).transition().duration(serviceTopologyConfig.duration).attr({
-          opacity: 1
-        });
-
-        _this2.drawComputeNodes(rack, d.computeNodes);
-      });
-    };
-
-    this.drawComputeNodes = function (container, nodes) {
-
-      var elements = container.selectAll('.compute-nodes').data(nodes, function (d) {
-        if (!angular.isString(d.d3Id)) {
-          d.d3Id = 'compute-node-' + ++computeNodeId;
-        }
-        return d.d3Id;
-      });
-
-      var _container$node$getBoundingClientRect = container.node().getBoundingClientRect();
-
-      var width = _container$node$getBoundingClientRect.width;
-      var height = _container$node$getBoundingClientRect.height;
-
-      var nodeContainer = elements.enter().append('g');
-
-      nodeContainer.attr({
-        transform: 'translate(' + width / 2 + ', ' + height / 2 + ')',
-        'class': 'compute-node'
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        transform: function transform(d) {
-          return 'translate(' + RackHelper.getComputeNodePosition(nodes, d.d3Id.replace('compute-node-', '') - 1) + ')';
-        }
-      });
-
-      nodeContainer.append('rect').attr({
-        width: 0,
-        height: 0
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        width: function width(d) {
-          return RackHelper.getComputeNodeSize(d.instances)[0];
-        },
-        height: function height(d) {
-          return RackHelper.getComputeNodeSize(d.instances)[1];
-        }
-      });
-
-      nodeContainer.append('text').attr({
-        'text-anchor': 'start',
-        y: 17, //FIXME
-        x: 10, //FIXME
-        opacity: 0
-      }).text(function (d) {
-        return d.humanReadableName.split('.')[0];
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      // if there are Compute Nodes
-      if (nodeContainer.length > 0) {
-        // draw instances for each compute node
-        nodeContainer.each(function (a) {
-          _this.drawInstances(d3.select(this), a.instances);
-        });
-      }
-    };
-
-    // NOTE Stripping unuseful names to shorten labels.
-    // This is not elegant
-    var formatInstanceName = function formatInstanceName(name) {
-      return name.replace('app_', '').replace('service_', '')
-      // .replace('ovs_', '')
-      .replace('mysite_', '').replace('_instance', '');
-    };
-
-    var getInstanceStatusColor = function getInstanceStatusColor(instance) {
-      function startWith(val, string) {
-        return string.substring(0, val.length) === val;
-      }
-
-      if (startWith('0 - ', instance.backend_status)) {
-        return 'provisioning';
-      }
-      if (startWith('1 - ', instance.backend_status)) {
-        return 'good';
-      }
-      if (startWith('2 - ', instance.backend_status)) {
-        return 'bad';
-      } else {
-        return '';
-      }
-    };
-
-    var drawContainer = function drawContainer(container, docker) {
-
-      var containerBox = container.append('g').attr({
-        'class': 'container',
-        transform: 'translate(' + serviceTopologyConfig.instance.margin + ', 115)'
-      });
-
-      containerBox.append('rect').attr({
-        width: 250 - serviceTopologyConfig.container.margin * 2,
-        height: serviceTopologyConfig.container.height
-      });
-
-      containerBox.append('text').attr({
-        y: 20,
-        x: serviceTopologyConfig.instance.margin,
-        'class': 'name'
-      }).text(docker.name);
-
-      // add stats
-      var interestingMeters = ['memory', 'memory.usage', 'cpu_util'];
-
-      interestingMeters.forEach(function (m, i) {
-        var meter = lodash.find(docker.stats, { meter: m });
-        // if there is no meter stats skip rendering
-        if (!angular.isDefined(meter)) {
-          return;
-        }
-        containerBox.append('text').attr({
-          y: 40 + i * 15,
-          x: serviceTopologyConfig.instance.margin,
-          opacity: 0
-        }).text(meter.description + ': ' + Math.round(meter.value) + ' ' + meter.unit).transition().duration(serviceTopologyConfig.duration).attr({
-          opacity: 1
-        });
-      });
-
-      // add port stats
-      var ports = ['eth0', 'eth1'];
-      var interestingPortMeters = [{
-        meter: 'network.incoming.bytes.rate',
-        label: 'Incoming'
-      }, {
-        meter: 'network.outgoing.bytes.rate',
-        label: 'Outgoing'
-      }];
-
-      ports.forEach(function (p, j) {
-
-        // if there are no port stats skip rendering
-        if (docker.port[p].length === 0) {
-          return;
-        }
-
-        containerBox.append('text').attr({
-          y: 90,
-          x: serviceTopologyConfig.instance.margin + 120 * j,
-          'class': 'name'
-        }).text(docker.name + '-' + p);
-
-        interestingPortMeters.forEach(function (m, i) {
-
-          var meter = lodash.find(docker.port[p], { meter: m.meter });
-          // if there is no meter stats skip rendering
-          if (!angular.isDefined(meter)) {
-            return;
-          }
-          containerBox.append('text').attr({
-            y: 105 + i * 15,
-            x: serviceTopologyConfig.instance.margin + 120 * j,
-            opacity: 0
-          }).text(m.label + ': ' + Math.round(meter.value) + ' ' + meter.unit).transition().duration(serviceTopologyConfig.duration).attr({
-            opacity: 1
-          });
-        });
-      });
-    };
-
-    var showInstanceStats = function showInstanceStats(container, instance) {
-
-      // NOTE this should be dinamically positioned
-      // base on the number of element present
-
-      // fake the position
-      var translation = {
-        'mysite_vsg-1': '200, -120',
-        'mysite_vsg-2': '-300, 30',
-        'mysite_vsg-3': '-300, -250'
-      };
-
-      var statsContainer = container.append('g').attr({
-        transform: 'translate(' + (translation[instance.humanReadableName] || translation['mysite_vsg-1']) + ')',
-        'class': 'stats-container'
-      }).on('click', function (d) {
-        // toggling visisbility
-        d.fade = !d.fade;
-        var opacity = undefined;
-        if (d.fade) {
-          opacity = 0.1;
-        } else {
-          opacity = 1;
-        }
-
-        d3.select(this).transition().duration(serviceTopologyConfig.duration).attr({
-          opacity: opacity
-        });
-      });
-
-      var lines = {
-        'mysite_vsg-1': {
-          x1: -160,
-          y1: 120,
-          x2: 0,
-          y2: 50
-        },
-        'mysite_vsg-2': {
-          x1: 250,
-          y1: 50,
-          x2: 300,
-          y2: -10
-        },
-        'mysite_vsg-3': {
-          x1: 250,
-          y1: 50,
-          x2: 300,
-          y2: 270
-        }
-      };
-
-      statsContainer.append('line').attr({
-        x1: function x1(d) {
-          return lines[d.humanReadableName].x1 || lines['mysite_vsg-1'].x1;
-        },
-        y1: function y1(d) {
-          return lines[d.humanReadableName].y1 || lines['mysite_vsg-1'].y1;
-        },
-        x2: function x2(d) {
-          return lines[d.humanReadableName].x2 || lines['mysite_vsg-1'].x2;
-        },
-        y2: function y2(d) {
-          return lines[d.humanReadableName].y2 || lines['mysite_vsg-1'].y2;
-        },
-        stroke: 'black',
-        opacity: 0
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      // NOTE rect should be dinamically sized base on the presence of a container
-      var statsHeight = 110;
-      var statsWidth = 250;
-
-      if (instance.container) {
-        statsHeight += serviceTopologyConfig.container.height + serviceTopologyConfig.container.margin * 2;
-      }
-
-      var statsVignette = statsContainer.append('rect').attr({
-        width: statsWidth,
-        height: statsHeight,
-        opacity: 0
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      // add instance info
-      statsContainer.append('text').attr({
-        y: 15,
-        x: serviceTopologyConfig.instance.margin,
-        'class': 'name',
-        opacity: 0
-      }).text(instance.humanReadableName).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      statsContainer.append('text').attr({
-        y: 30,
-        x: serviceTopologyConfig.instance.margin,
-        'class': 'ip',
-        opacity: 0
-      }).text(instance.ip).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      // add stats
-      var interestingMeters = ['memory', 'memory.usage', 'cpu', 'cpu_util'];
-
-      interestingMeters.forEach(function (m, i) {
-        var meter = lodash.find(instance.stats, { meter: m });
-
-        if (meter) {
-
-          statsContainer.append('text').attr({
-            y: 55 + i * 15,
-            x: serviceTopologyConfig.instance.margin,
-            opacity: 0
-          }).text(meter.description + ': ' + Math.round(meter.value) + ' ' + meter.unit).transition().duration(serviceTopologyConfig.duration).attr({
-            opacity: 1
-          });
-        }
-      });
-
-      if (instance.container) {
-        // draw container
-        drawContainer(statsContainer, instance.container);
-      }
-    };
-
-    this.drawInstances = function (container, instances) {
-
-      // TODO check for stats field in instance and draw popup
-
-      var _container$node$getBoundingClientRect2 = container.node().getBoundingClientRect();
-
-      var width = _container$node$getBoundingClientRect2.width;
-      var height = _container$node$getBoundingClientRect2.height;
-
-      var elements = container.selectAll('.instances').data(instances, function (d) {
-        return angular.isString(d.d3Id) ? d.d3Id : d.d3Id = 'instance-' + ++instanceId;
-      });
-
-      var instanceContainer = elements.enter().append('g');
-
-      instanceContainer.attr({
-        transform: 'translate(' + width / 2 + ', ' + height / 2 + ')',
-        'class': function _class(d) {
-          return 'instance ' + (d.selected ? 'active' : '') + ' ' + getInstanceStatusColor(d);
-        }
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        transform: function transform(d, i) {
-          return 'translate(' + RackHelper.getInstancePosition(i) + ')';
-        }
-      });
-
-      instanceContainer.append('rect').attr({
-        width: 0,
-        height: 0
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        width: serviceTopologyConfig.instance.width,
-        height: serviceTopologyConfig.instance.height
-      });
-
-      instanceContainer.append('text').attr({
-        'text-anchor': 'middle',
-        y: 23, //FIXME
-        x: 40, //FIXME
-        opacity: 0
-      }).text(function (d) {
-        return formatInstanceName(d.humanReadableName);
-      }).transition().duration(serviceTopologyConfig.duration).attr({
-        opacity: 1
-      });
-
-      // if stats are attached and instance is active,
-      // draw stats
-      instanceContainer.each(function (instance, i) {
-
-        var container = d3.select(this);
-
-        if (angular.isDefined(instance.stats) && instance.selected) {
-          showInstanceStats(container, instance, i);
-        }
-      });
-
-      // instanceContainer
-      // .on('click', function(d){
-      //   console.log(`Draw vignette with stats for instance: ${d.name}`);
-      // });
-    };
-
-    this.addPhisical = function (nodes) {
-
-      nodes.select('rect').remove();
-      nodes.select('text').remove();
-
-      nodes.append('rect').attr(serviceTopologyConfig.square);
-
-      nodes.append('text').attr({
-        'text-anchor': 'middle',
-        y: serviceTopologyConfig.square.y - 10
-      }).text(function (d) {
-        return d.name || d.humanReadableName;
-      });
-    };
-
-    this.addDevice = function (nodes) {
-      nodes.append('circle').attr(serviceTopologyConfig.circle);
-
-      nodes.append('text').attr({
-        'text-anchor': 'end',
-        x: -serviceTopologyConfig.circle.r - 10,
-        y: serviceTopologyConfig.circle.r / 2
-      }).text(function (d) {
-        return d.name || d.mac;
-      });
-    };
-  }]);
-})();
-'use strict';
-
-var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').service('LogicTopologyHelper', ["$window", "$log", "$rootScope", "lodash", "serviceTopologyConfig", "NodeDrawer", "ChartData", function ($window, $log, $rootScope, lodash, serviceTopologyConfig, NodeDrawer, ChartData) {
-    var _this = this;
-
-    var diagonal,
-        nodes,
-        links,
-        i = 0,
-        svgWidth,
-        svgHeight,
-        layout;
-
-    var baseData = ChartData.logicTopologyData;
-
-    /**
-     * Calculate the horizontal position for each element.
-     * subsrcribers, devices and routers have the same fixed width 20
-     * network have a fixed width 104
-     * rack have a fixed width 105
-     * build and array of 6 elements representing the position of each element in the svg
-     * to equally space them
-     */
-
-    this.computeElementPosition = function (svgWidth) {
-
-      var xPos = [];
-
-      var totalElWidth = lodash.reduce(serviceTopologyConfig.elWidths, function (el, val) {
-        return val + el;
-      }, 0);
-
-      var remainingSpace = svgWidth - totalElWidth - serviceTopologyConfig.widthMargin * 2;
-
-      var step = remainingSpace / (serviceTopologyConfig.elWidths.length - 1);
-
-      lodash.forEach(serviceTopologyConfig.elWidths, function (el, i) {
-
-        // get half of the previous elements width
-        var previousElWidth = 0;
-        if (i !== 0) {
-          previousElWidth = lodash.reduce(serviceTopologyConfig.elWidths.slice(0, i), function (el, val) {
-            return val + el;
-          }, 0);
-        }
-
-        var elPos = serviceTopologyConfig.widthMargin // right margin
-         + step * i // space between elements
-         + el / 2 // this el width
-         + previousElWidth; // previous elements width
-
-        xPos.push(svgWidth - elPos);
-      });
-
-      return xPos;
-    };
-
-    /**
-    * from a nested data structure,
-    * create nodes and links for a D3 Tree Layout
-    */
-    var computeLayout = function computeLayout(data) {
-      var nodes = layout.nodes(data);
-
-      // Normalize for fixed-depth.
-      nodes.forEach(function (d) {
-        // position the child node horizontally
-        d.y = _this.computeElementPosition(svgWidth)[d.depth];
-      });
-
-      var links = layout.links(nodes);
-
-      return [nodes, links];
-    };
-
-    /**
-    * Draw the containing group for any node or update the existing one
-    */
-    var drawNodes = function drawNodes(svg, nodes) {
-      // Update the nodes…
-      var node = svg.selectAll('g.node').data(nodes, function (d) {
-        if (!angular.isString(d.d3Id)) {
-          d.d3Id = 'tree-' + ++i;
-        }
-        return d.d3Id;
-      });
-
-      // Enter any new nodes
-      var nodeEnter = node.enter().append('g').attr({
-        'class': function _class(d) {
-          return 'node ' + d.type;
-        },
-        transform: 'translate(' + svgWidth / 2 + ', ' + svgHeight / 2 + ')'
-      });
-
-      // create Nodes
-      NodeDrawer.addNetworks(node.filter('.network'));
-      NodeDrawer.addRack(node.filter('.rack'));
-      NodeDrawer.addPhisical(node.filter('.router'));
-      NodeDrawer.addPhisical(node.filter('.subscriber'));
-      NodeDrawer.addDevice(node.filter('.device'));
-
-      // add event listener to subscriber
-      node.filter('.subscriber').on('click', function () {
-        $rootScope.$emit('subscriber.modal.open');
-      });
-
-      //update nodes
-      // TODO if data change, only update them
-      // NodeDrawer.updateRack(node.filter('.rack'));
-
-      // Transition nodes to their new position.
-      var nodeUpdate = node.transition().duration(serviceTopologyConfig.duration).attr({
-        'transform': function transform(d) {
-          return 'translate(' + d.y + ',' + d.x + ')';
-        }
-      });
-
-      // TODO handle node remove
-      var nodeExit = node.exit().remove();
-    };
-
-    /**
-    * Handle links in the tree layout
-    */
-    var drawLinks = function drawLinks(svg, links) {
-
-      diagonal = d3.svg.diagonal().projection(function (d) {
-        return [d.y, d.x];
-      });
-
-      // Update the links…
-      var link = svg.selectAll('path.link').data(links, function (d) {
-        return d.target.d3Id;
-      });
-
-      // Enter any new links at the parent's previous position.
-      link.enter().insert('path', 'g').attr('class', function (d) {
-        return 'link ' + d.target.type;
-      }).attr('d', function (d) {
-        var o = { x: svgHeight / 2, y: svgWidth / 2 };
-        return diagonal({ source: o, target: o });
-      });
-
-      // Transition links to their new position.
-      link.transition().duration(serviceTopologyConfig.duration).attr('d', diagonal);
-
-      link.exit().remove();
-    };
-
-    /**
-    * Calculate the svg size and setup tree layout
-    */
-    this.setupTree = function (svg) {
-
-      svgWidth = svg.node().getBoundingClientRect().width;
-      svgHeight = svg.node().getBoundingClientRect().height;
-
-      var width = svgWidth - serviceTopologyConfig.widthMargin * 2;
-      var height = svgHeight - serviceTopologyConfig.heightMargin * 2;
-
-      layout = d3.layout.tree().size([height, width]);
-    };
-
-    /**
-    * Update the tree layout
-    */
-
-    this.updateTree = function (svg) {
-
-      // console.log(baseData);
-
-      var _computeLayout = computeLayout(baseData);
-
-      // Compute the new tree layout.
-
-      var _computeLayout2 = _slicedToArray(_computeLayout, 2);
-
-      nodes = _computeLayout2[0];
-      links = _computeLayout2[1];
-      drawNodes(svg, nodes);
-      drawLinks(svg, links);
-    };
-  }]);
-})();
-'use strict';
-
-(function () {
-  'use strict';
-  angular.module('xos.diagnostic').directive('logicTopology', function () {
-    return {
-      restrict: 'E',
-      scope: {
-        subscribers: '=',
-        selected: '='
-      },
-      bindToController: true,
-      controllerAs: 'vm',
-      templateUrl: 'templates/logicTopology.tpl.html',
-      controller: ["$element", "$log", "$scope", "$rootScope", "$timeout", "d3", "LogicTopologyHelper", "Node", "Tenant", "Ceilometer", "serviceTopologyConfig", "ChartData", function controller($element, $log, $scope, $rootScope, $timeout, d3, LogicTopologyHelper, Node, Tenant, Ceilometer, serviceTopologyConfig, ChartData) {
-        var _this2 = this;
-
-        $log.info('Logic Plane');
-
-        var svg;
-        this.selectedInstances = [];
-        this.hideInstanceStats = true;
-        var _this = this;
-
-        var handleSvg = function handleSvg(el) {
-
-          d3.select($element[0]).select('svg').remove();
-
-          svg = d3.select(el).append('svg').style('width', el.clientWidth + 'px').style('height', el.clientHeight + 'px');
-        };
-
-        var loadGlobalScope = function loadGlobalScope() {
-          ChartData.getLogicTree().then(function (tree) {
-            LogicTopologyHelper.updateTree(svg);
-          });
-        };
-        loadGlobalScope();
-
-        $scope.$watch(function () {
-          return _this2.selected;
-        }, function (selected) {
-          if (selected) {
-            ChartData.selectSubscriber(selected);
-            LogicTopologyHelper.updateTree(svg);
-          } else {
-            ChartData.removeSubscriber();
-            LogicTopologyHelper.updateTree(svg);
-          }
-        });
-
-        $rootScope.$on('instance.detail.hide', function () {
-          _this2.hideInstanceStats = true;
-          $timeout(function () {
-            _this2.selectedInstances = [];
-            ChartData.highlightInstances([]);
-            LogicTopologyHelper.updateTree(svg);
-          }, 500);
-        });
-
-        $rootScope.$on('instance.detail', function (evt, service) {
-          ChartData.getInstanceStatus(service).then(function (instances) {
-            LogicTopologyHelper.updateTree(svg);
-          })['catch'](function (e) {
-            _this.error = 'Service statistics are not available at this time. Please try again later.';
-            $timeout(function () {
-              _this.error = null;
-            }, 2000);
-          });
-        });
-
-        d3.select(window).on('resize.logic', function () {
-          handleSvg($element[0]);
-          LogicTopologyHelper.setupTree(svg);
-          LogicTopologyHelper.updateTree(svg);
-        });
-
-        handleSvg($element[0]);
-        LogicTopologyHelper.setupTree(svg);
-
-        this.selectSubscriberModal = function () {
-          _this2.openSelectSubscriberModal = true;
-          $scope.$apply();
-        };
-
-        this.subscriberStatusModal = function () {
-          _this2.openSubscriberStatusModal = true;
-          $scope.$apply();
-        };
-
-        // listen for subscriber modal event
-        $rootScope.$on('subscriber.modal.open', function () {
-
-          if (ChartData.currentSubscriber) {
-            _this2.subscriberStatusModal();
-          } else {
-            _this2.selectSubscriberModal();
-          }
-        });
-
-        // listen for subscriber modal event
-        $rootScope.$on('subscriber.modal.open', function () {
-
-          if (ChartData.currentSubscriber) {
-            _this2.currentSubscriber = ChartData.currentSubscriber;
-            _this2.subscriberStatusModal();
-          } else {
-            _this2.selectSubscriberModal();
-          }
-        });
-      }]
-    };
-  });
-})();
-'use strict';
-
-(function () {
-  'use strict';
-  angular.module('xos.diagnostic').directive('diagnosticContainer', function () {
-    return {
-      restrict: 'E',
-      templateUrl: 'templates/diagnostic.tpl.html',
-      controllerAs: 'vm',
-      controller: ["ChartData", "Subscribers", "ServiceRelation", "$rootScope", "$log", function controller(ChartData, Subscribers, ServiceRelation, $rootScope, $log) {
-        var _this = this;
-
-        this.loader = true;
-        this.error = false;
-
-        var loadGlobalScope = function loadGlobalScope() {
-          Subscribers.query().$promise.then(function (subscribers) {
-            _this.subscribers = subscribers;
-            return ServiceRelation.get();
-          }).then(function (serviceChain) {
-            _this.serviceChain = serviceChain;
-            // debug helper
-            // loadSubscriber(this.subscribers[0]);
-          })['catch'](function (e) {
-            throw new Error(e);
-            _this.error = e;
-          })['finally'](function () {
-            _this.loader = false;
-          });
-        };
-
-        loadGlobalScope();
-
-        this.reloadGlobalScope = function () {
-          _this.selectedSubscriber = null;
-          loadGlobalScope();
-        };
-
-        var loadSubscriber = function loadSubscriber(subscriber) {
-          ServiceRelation.getBySubscriber(subscriber).then(function (serviceChain) {
-            _this.serviceChain = serviceChain;
-            ChartData.currentServiceChain = serviceChain;
-            return Subscribers.getWithDevices({ id: subscriber.id }).$promise;
-          }).then(function (subscriber) {
-            _this.selectedSubscriber = subscriber;
-            ChartData.currentSubscriber = subscriber;
-          });
-        };
-
-        $rootScope.$on('subscriber.selected', function (evt, subscriber) {
-          loadSubscriber(subscriber);
-        });
-      }]
-    };
-  });
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').factory('d3', ["$window", function ($window) {
-    return $window.d3;
-  }]);
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').constant('serviceTopologyConfig', {
-    widthMargin: 60,
-    heightMargin: 30,
-    duration: 750,
-    elWidths: [20, 104, 105, 104, 20], //this is not true
-    circle: {
-      radius: 10,
-      r: 10,
-      selectedRadius: 15
-    },
-    square: {
-      width: 20,
-      height: 20,
-      x: -10,
-      y: -10
-    },
-    rack: {
-      width: 105,
-      height: 50,
-      x: -30,
-      y: -25
-    },
-    computeNode: {
-      width: 50,
-      height: 20,
-      margin: 5,
-      labelHeight: 10,
-      x: -25,
-      y: -10
-    },
-    instance: {
-      width: 80,
-      height: 36,
-      margin: 5,
-      x: -40,
-      y: -18
-    },
-    container: {
-      width: 60,
-      height: 130,
-      margin: 5,
-      x: -30,
-      y: -15
-    }
-  });
-})();
-'use strict';
-
-(function () {
-  'use strict';
-
-  angular.module('xos.diagnostic').service('ChartData', ["$rootScope", "$q", "lodash", "Tenant", "Node", "serviceTopologyConfig", "Ceilometer", "Instances", function ($rootScope, $q, lodash, Tenant, Node, serviceTopologyConfig, Ceilometer, Instances) {
-    var _this = this;
-
-    this.currentSubscriber = null;
-    this.currentServiceChain = null;
-
-    this.logicTopologyData = {
-      name: 'Router',
-      type: 'router',
-      children: [{
-        name: 'WAN-Side',
-        subtitle: 'Virtual Network',
-        type: 'network',
-        children: [{
-          name: 'Compute Servers',
-          type: 'rack',
-          computeNodes: [],
-          children: [{
-            name: 'LAN-Side',
-            subtitle: 'Virtual Network',
-            type: 'network',
-            children: [{
-              name: 'Subscriber',
-              type: 'subscriber'
-            }] //subscribers goes here
-          }]
-        }]
-      }]
-    };
-
-    this.getLogicTree = function () {
-      var deferred = $q.defer();
-
-      Node.queryWithInstances().$promise.then(function (computeNodes) {
-        _this.logicTopologyData.children[0].children[0].computeNodes = computeNodes;
-        // LogicTopologyHelper.updateTree(svg);
-        deferred.resolve(_this.logicTopologyData);
-      });
-
-      return deferred.promise;
-    };
-
-    /**
-    * Add Subscriber tag to LAN Network
-    */
-    this.addSubscriberTag = function (tags) {
-      _this.logicTopologyData.children[0].children[0].children[0].subscriberTag = {
-        cTag: tags.cTag,
-        sTag: tags.sTag
-      };
-    };
-
-    /**
-    * Add Subscribers to the tree
-    */
-    this.addSubscriber = function (subscriber) {
-      subscriber.children = subscriber.devices;
-
-      // add subscriber to data tree
-      _this.logicTopologyData.children[0].children[0].children[0].children = [subscriber];
-      return _this.logicTopologyData;
-    };
-
-    /**
-    * Remove a subscriber from the tree
-    */
-
-    this.removeSubscriber = function () {
-      _this.logicTopologyData.children[0].children[0].children[0].children[0].humanReadableName = 'Subscriber';
-      _this.currentSubscriber = null;
-      if (serviceTopologyConfig.elWidths[serviceTopologyConfig.elWidths.length - 1] === 160) {
-        serviceTopologyConfig.elWidths.pop();
-      }
-
-      //remove tags and ip
-      delete _this.logicTopologyData.children[0].children[0].children[0].subscriberTag;
-      delete _this.logicTopologyData.children[0].subscriberIP;
-
-      _this.highlightInstances([]);
-      delete _this.logicTopologyData.children[0].children[0].children[0].children[0].children;
-    };
-
-    this.getSubscriberTag = function (subscriber) {
-      var tags = {
-        cTag: subscriber.c_tag,
-        sTag: subscriber.s_tag
-      };
-
-      _this.addSubscriberTag(tags);
-      // add tags info to current subscriber
-      _this.currentSubscriber.tags = tags;
-    };
-
-    this.getSubscriberIP = function (subscriber) {
-      // const ip = JSON.parse(this.currentServiceChain.children[0].children[0].tenant.service_specific_attribute).wan_container_ip;
-      // const ip = this.currentServiceChain.children[0].children[0].tenant.wan_container_ip;
-      _this.logicTopologyData.children[0].subscriberIP = subscriber.wan_container_ip;
-    };
-
-    this.selectSubscriber = function (subscriber) {
-      // append the device with to config settings
-      serviceTopologyConfig.elWidths.push(160);
-
-      _this.addSubscriber(angular.copy(subscriber));
-
-      //clean selected instances
-      _this.highlightInstances([]);
-
-      _this.getSubscriberTag(subscriber);
-      _this.getSubscriberIP(subscriber);
-    };
-
-    this.highlightInstances = function (instances) {
-
-      var computeNodes = _this.logicTopologyData.children[0].children[0].computeNodes;
-
-      // unselect all
-      computeNodes.map(function (node) {
-        node.instances.map(function (instance) {
-          instance.selected = false;
-          return instance;
-        });
-      });
-
-      lodash.forEach(instances, function (instance) {
-        computeNodes.map(function (node) {
-          node.instances.map(function (d3instance) {
-            if (d3instance.id === instance.id) {
-              // console.log(d3instance, instance);
-              d3instance.selected = true;
-              d3instance.stats = instance.stats; //add stats to d3 node
-              d3instance.container = instance.container; // container info to d3 node
-            }
-            return d3instance;
-          });
-        });
-      });
-    };
-
-    this.getInstanceStatus = function (service) {
-      var deferred = $q.defer();
-
-      var p = undefined;
-
-      // subscriber specific
-      if (_this.currentSubscriber) {
-
-        var attr = undefined;
-        try {
-          attr = JSON.parse(service.tenant.service_specific_attribute);
-        } catch (e) {
-          attr = null;
-        }
-
-        // if no instances are associated to the subscriber
-        if (!attr || !attr.instance_id) {
-          var d = $q.defer();
-          d.resolve([]);
-          p = d.promise;
-        }
-        // if ther is an instance
-        else {
-            (function () {
-              var instance = {};
-              p = Instances.get({ id: attr.instance_id }).$promise.then(function (_instance) {
-                instance = _instance;
-                return Ceilometer.getInstanceStats(instance.instance_uuid);
-              }).then(function (stats) {
-                instance.stats = stats;
-                var containerName = 'vcpe-' + _this.currentSubscriber.tags.sTag + '-' + _this.currentSubscriber.tags.cTag;
-                // append containers
-                instance.container = {
-                  name: containerName
-                };
-
-                // TODO fetch container stats
-                return Ceilometer.getContainerStats(containerName);
-              }).then(function (containerStats) {
-                instance.container.stats = containerStats.stats;
-                instance.container.port = containerStats.port;
-                return [instance];
-              });
-            })();
-          }
-      }
-      // global scope
-      else {
-          var param = {
-            'service_vsg': { kind: 'vCPE' },
-            'service_vbng': { kind: 'vBNG' },
-            'service_volt': { kind: 'vOLT' }
-          };
-
-          p = Tenant.queryVsgInstances(param[service.name]).$promise.then(function (instances) {
-            return Ceilometer.getInstancesStats(lodash.uniq(instances));
-          });
-        }
-
-      p.then(function (instances) {
-        _this.highlightInstances(instances);
-        deferred.resolve(instances);
-      })['catch'](function (e) {
-        deferred.reject(e);
-      });
-
-      return deferred.promise;
-    };
-  }]);
-})();
-angular.module('xos.diagnostic').run(function($location){
-  $location.path('/')
-});
-angular.bootstrap(angular.element('#xosDiagnostic'), ['xos.diagnostic']);
\ No newline at end of file
+"use strict";!function(){angular.module("xos.diagnostic",["ngResource","ngCookies","ngLodash","ngAnimate","ui.router","xos.helpers"]).config(["$stateProvider",function(e){e.state("home",{url:"/",template:"<diagnostic-container></diagnostic-container>"})}]).config(["$httpProvider",function(e){e.interceptors.push("NoHyperlinks")}]).run(["$log",function(e){e.info("Diagnostic Started")}])}(),angular.module("xos.diagnostic").run(["$templateCache",function(e){e.put("templates/diagnostic.tpl.html",'<div class="container-fluid">\n  <div ng-hide="vm.error && vm.loader" style="height: 900px">\n    <div class="onethird-height">\n      <div class="well">\n        Services Graph\n      </div>\n      <div class="well pull-right" ng-click="vm.reloadGlobalScope()" ng-show="vm.selectedSubscriber">\n        Reset subscriber\n      </div>\n      <service-topology service-chain="vm.serviceChain"></service-topology>\n    </div>\n    <div class="twothird-height">\n      <div class="well">\n        Logical Resources\n      </div>\n      <logic-topology ng-if="vm.subscribers" subscribers="vm.subscribers" selected="vm.selectedSubscriber"></logic-topology>\n    </div>\n  </div>\n  <div class="row" ng-if="vm.error">\n    <div class="col-xs-12">\n      <div class="alert alert-danger">\n        {{vm.error}}\n      </div>\n    </div>\n  </div>\n  <div class="row" ng-if="vm.loader">\n    <div class="col-xs-12">\n      <div class="loader">Loading</div>\n    </div>\n  </div>\n</div>'),e.put("templates/logicTopology.tpl.html",'<select-subscriber-modal open="vm.openSelectSubscriberModal" subscribers="vm.subscribers"></select-subscriber-modal>\n<subscriber-status-modal open="vm.openSubscriberStatusModal" subscriber="vm.currentSubscriber"></subscriber-status-modal>\n<div class="alert alert-danger animate" ng-hide="!vm.error">\n  {{vm.error}}\n</div>\n<!-- <div class="instances-stats animate" ng-hide="vm.hideInstanceStats">\n  <div class="row">\n    <div class="col-sm-3 col-sm-offset-8">\n      <div class="panel panel-primary" ng-repeat="instance in vm.selectedInstances">\n        <div class="panel-heading">\n          {{instance.humanReadableName}}\n        </div>\n          <ul class="list-group">\n            <li class="list-group-item">Backend Status: {{instance.backend_status}}</li>\n            <li class="list-group-item">IP Address: {{instance.ip}}</li>\n          </ul>\n          <ul class="list-group">\n            <li class="list-group-item" ng-repeat="stat in instance.stats">\n              <span class="badge">{{stat.value}}</span>\n              {{stat.meter}}\n            </li>\n          </ul>\n        </div>\n      </div>  \n    </div>\n  </div>\n</div> -->'),e.put("templates/select-subscriber-modal.tpl.html",'<div class="modal fade" ng-class="{in: vm.open}" tabindex="-1" role="dialog">\n  <div class="modal-dialog modal-sm">\n    <div class="modal-content">\n      <div class="modal-header">\n        <button ng-click="vm.close()"  type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n        <h4 class="modal-title">Select a subscriber:</h4>\n      </div>\n      <div class="modal-body">\n        <select class="form-control" ng-options="s as s.humanReadableName for s in vm.subscribers" ng-model="vm.selected"></select>\n      </div>\n      <div class="modal-footer">\n        <button ng-click="vm.close()" type="button" class="btn btn-default" data-dismiss="modal">Close</button>\n        <button ng-click="vm.select(vm.selected)" type="button" class="btn btn-primary">Select</button>\n      </div>\n    </div><!-- /.modal-content -->\n  </div><!-- /.modal-dialog -->\n</div><!-- /.modal -->'),e.put("templates/subscriber-status-modal.tpl.html",'<div class="modal fade" ng-class="{in: vm.open}" tabindex="-1" role="dialog">\n  <div class="modal-dialog modal-sm">\n    <div class="modal-content">\n      <div class="modal-header">\n        <button ng-click="vm.close()"  type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n        <h4 class="modal-title">Manage subscriber:</h4>\n      </div>\n      <form name="vm.subscriber-detail">\n        <div class="modal-body">\n          <div class="row">\n            <div class="col-xs-12">\n              <label>Status</label>\n            </div>\n            <div class="col-xs-6">\n              <a ng-click="vm.subscriber.status = \'enabled\'"\n                class="btn btn-block"\n                ng-class="{\'btn-primary\': vm.subscriber.status === \'enabled\' ,\'btn-default\': vm.subscriber.status !== \'enabled\'}"\n                >Enabled</a>\n            </div>\n            <div class="col-xs-6">\n              <a ng-click="vm.subscriber.status = \'suspended\'"\n                class="btn btn-block"\n                ng-class="{\'btn-primary\': vm.subscriber.status === \'suspended\' ,\'btn-default\': vm.subscriber.status !== \'suspended\'}"\n                >Suspended</a>\n            </div>\n          </div>\n          <div class="row">\n            <div class="col-xs-6">\n              <a ng-click="vm.subscriber.status = \'delinquent\'"\n                class="btn btn-block"\n                ng-class="{\'btn-primary\': vm.subscriber.status === \'delinquent\' ,\'btn-default\': vm.subscriber.status !== \'delinquent\'}"\n                >Delinquent <br> payment</a>\n            </div>\n            <div class="col-xs-6">\n              <a ng-click="vm.subscriber.status = \'copyrightviolation\'"\n                class="btn btn-block"\n                ng-class="{\'btn-primary\': vm.subscriber.status === \'copyrightviolation\' ,\'btn-default\': vm.subscriber.status !== \'copyrightviolation\'}"\n                >Copyright <br> violation</a>\n            </div>\n          </div>\n          <div class="row">\n            <div class="col-xs-6">\n              <label>Uplink Speed</label>\n              <div class="input-group">\n                <input type="number" class="form-control small-padding" ng-model="vm.subscriber.uplink_speed"/>\n                <span class="input-group-addon">Mbps</span>\n              </div>\n            </div>\n            <div class="col-xs-6">\n              <label>Downlink Speed</label>\n              <div class="input-group">\n                <input type="number" class="form-control small-padding" ng-model="vm.subscriber.downlink_speed"/>\n                <span class="input-group-addon">Mbps</span>\n              </div>\n            </div>\n          </div>\n          <div class="row">\n            <div class="col-xs-6">\n              <label>Enable Internet</label>\n            </div>\n            <div class="col-xs-6">\n              <a \n                ng-click="vm.subscriber.enable_uverse = !vm.subscriber.enable_uverse" \n                ng-class="{\'btn-success\': vm.subscriber.enable_uverse, \'btn-danger\': !vm.subscriber.enable_uverse}"\n                class="btn btn-block">\n                <span ng-show="vm.subscriber.enable_uverse === true">Enabled</span>\n                <span ng-show="vm.subscriber.enable_uverse !== true">Disabled</span>\n              </a>\n            </div>\n          </div>\n        </div>\n        <div class="modal-footer" ng-show="vm.success || vm.formError">\n          <div class="alert alert-success" ng-show="vm.success">\n            {{vm.success}}\n          </div>\n          <div class="alert alert-danger" ng-show="vm.formError">\n            {{vm.formError}}\n          </div>\n        </div>\n        <div class="modal-footer">\n          <button ng-click="vm.close()" type="button" class="btn btn-default" data-dismiss="modal">Close</button>\n          <button ng-click="vm.updateSubscriber(vm.subscriber)" type="button" class="btn btn-primary">Save</button>\n        </div>\n      </form>\n    </div><!-- /.modal-content -->\n  </div><!-- /.modal-dialog -->\n</div><!-- /.modal -->')}]),function(){angular.module("xos.diagnostic").directive("selectSubscriberModal",function(){return{scope:{subscribers:"=",open:"="},bindToController:!0,restrict:"E",templateUrl:"templates/select-subscriber-modal.tpl.html",controllerAs:"vm",controller:["$rootScope",function(e){var t=this;this.close=function(){t.open=!1},this.select=function(n){e.$emit("subscriber.selected",n),t.close()}}]}}).directive("subscriberStatusModal",function(){return{scope:{open:"=",subscriber:"="},bindToController:!0,restrict:"E",templateUrl:"templates/subscriber-status-modal.tpl.html",controllerAs:"vm",controller:["$log","$timeout","$scope","Subscribers",function(e,t,n,r){var i=this,a=1e6;n.$watch(function(){return i.open},function(){i.success=null,i.formError=null}),n.$watch(function(){return i.subscriber},function(e,t){i.subscriber&&(console.log(e,t),console.log("subscriber change",e===t),i.subscriber.uplink_speed=parseInt(i.subscriber.uplink_speed,10)/a,i.subscriber.downlink_speed=parseInt(i.subscriber.downlink_speed,10)/a)}),this.close=function(){i.open=!1},this.updateSubscriber=function(e){var n=angular.copy(e,n);n.uplink_speed=n.uplink_speed*a,n.downlink_speed=n.downlink_speed*a,r.update(n).$promise.then(function(e){i.success="Subscriber successfully updated!"})["catch"](function(e){i.formError=e})["finally"](function(){t(function(){i.close()},1500)})}}]}})}(),function(){angular.module("xos.diagnostic").service("ServiceTopologyHelper",["$rootScope","$window","$log","lodash","ServiceRelation","serviceTopologyConfig","d3",function(e,t,n,r,i,a,s){var c,o,u,l,d=0,p=function(t,n,r){var p=arguments.length<=3||void 0===arguments[3]?l:arguments[3];p&&(l=p);var h=l.clientWidth-2*a.widthMargin;c=t,o=n,u=r;var m=i.depthOf(r),b=s.svg.diagonal().projection(function(e){return[e.y,e.x]}),g=n.nodes(r).reverse(),f=n.links(g);g.forEach(function(e){var t=(h-2*a.widthMargin)/(m-1);e.y=e.depth*t});var y=t.selectAll("g.node").data(g,function(e){return e.id||(e.id=++d)}),x=y.enter().append("g").attr({"class":function(e){return"node "+e.type},transform:function(e){return e.x&&e.y?"translate("+e.y+", "+e.x+")":"translate("+r.y0+", "+r.x0+")"}}),S=x.filter(".subscriber"),w=x.filter(".router"),T=x.filter(".service");S.append("rect").attr(a.square).on("click",function(){e.$emit("subscriber.modal.open")}),w.append("rect").attr(a.square),T.append("circle").attr("r",1e-6).style("fill",function(e){return e._children?"lightsteelblue":"#fff"}).on("click",v),x.append("text").attr({x:function(e){return e.children?-a.circle.selectedRadius-5:a.circle.selectedRadius+5},dy:".35em",y:function(e){return e.children&&e.parent?"-5":void 0},transform:function(e){return e.children&&e.parent?e.parent.x<e.x?"rotate(-30)":"rotate(30)":void 0},"text-anchor":function(e){return e.children?"end":"start"}}).text(function(e){return e.name}).style("fill-opacity",1e-6);var _=y.transition().duration(a.duration).attr({transform:function(e){return"translate("+e.y+","+e.x+")"}});_.select("circle").attr("r",function(e){return e.selected?a.circle.selectedRadius:a.circle.radius}).style("fill",function(e){return e.selected?"lightsteelblue":"#fff"}),_.select("text").style("fill-opacity",1);var C=y.exit().transition().duration(a.duration).remove();C.select("circle").attr("r",1e-6),C.select("text").style("fill-opacity",1e-6);var k=t.selectAll("path.link").data(f,function(e){return e.target.id});k.enter().insert("path","g").attr("class",function(e){return"link "+e.target.type+" "+(e.target.active?"":"active")}).attr("d",function(e){var t={x:r.x0,y:r.y0};return b({source:t,target:t})}),k.transition().duration(a.duration).attr("d",b),k.exit().transition().duration(a.duration).attr("d",function(e){var t={x:r.x,y:r.y};return b({source:t,target:t})}).remove(),g.forEach(function(e){e.x0=e.x,e.y0=e.y})},v=function(t){return t.selected?(t.selected=!t.selected,e.$emit("instance.detail.hide",{}),p(c,o,u)):(e.$emit("instance.detail",{name:t.name,service:t.service,tenant:t.tenant}),c.selectAll("circle").each(function(e){return e.selected=!1}),t.selected=!t.selected,void p(c,o,u))};this.updateTree=p}])}(),function(){angular.module("xos.diagnostic").directive("serviceTopology",function(){return{restrict:"E",scope:{serviceChain:"="},bindToController:!0,controllerAs:"vm",template:"",controller:["$element","$window","$scope","d3","serviceTopologyConfig","ServiceRelation","Slice","Instances","Subscribers","ServiceTopologyHelper",function(e,t,n,r,i,a,s,c,o,u){var l=this,d=e[0];r.select(window).on("resize.service",function(){h(l.serviceChain)});var p,v,h=function(t){if(!t)return void console.error("Tree is missing");r.select(e[0]).select("svg").remove();var n=d.clientWidth-2*i.widthMargin,a=d.clientHeight-2*i.heightMargin,s=r.layout.tree().size([a,n]);v=r.select(e[0]).append("svg").style("width",d.clientWidth+"px").style("height",d.clientHeight+"px");var c=v.append("g").attr("transform","translate("+2*i.widthMargin+","+i.heightMargin+")");p=t,p.x0=a/2,p.y0=n/2,u.updateTree(c,s,p,d)};n.$watch(function(){return l.serviceChain},function(e){angular.isDefined(e)&&h(e)})}]}})}(),function(){angular.module("xos.diagnostic").service("Services",["$resource",function(e){return e("/xos/services/:id",{id:"@id"})}]).service("Tenant",["$resource",function(e){return e("/xos/tenants",{id:"@id"},{queryVsgInstances:{method:"GET",isArray:!0,interceptor:{response:function(e){var t=[];return angular.forEach(e.data,function(e){var n=JSON.parse(e.service_specific_attribute);n&&n.instance_id&&t.push(n.instance_id)}),t}}},getSubscriberTag:{method:"GET",isArray:!0,interceptor:{response:function(e){return JSON.parse(e.data[0].service_specific_attribute)}}}})}]).service("Ceilometer",["$http","$q","Instances",function(e,t,n){var r=this;this.getInstanceStats=function(n){var r=t.defer();return e.get("/xoslib/xos-instance-statistics",{params:{"instance-uuid":n}}).then(function(e){r.resolve(e.data)})["catch"](function(e){r.reject(e)}),r.promise},this.getInstancesStats=function(e){var i=t.defer(),a=[],s=[];return e.forEach(function(e){a.push(n.get({id:e}).$promise)}),t.all(a).then(function(e){s=e;var n=[];return s.forEach(function(e){n.push(r.getInstanceStats(e.instance_uuid))}),t.all(n)}).then(function(e){s.map(function(t,n){t.stats=e[n]}),i.resolve(s)})["catch"](i.reject),i.promise},this.getContainerStats=function(n){var r=t.defer(),i={};return e.get("/xoslib/meterstatistics",{params:{resource:n}}).then(function(t){return i.stats=t.data,e.get("/xoslib/meterstatistics",{params:{resource:n+"-eth0"}})}).then(function(t){return i.port={eth0:t.data},e.get("/xoslib/meterstatistics",{params:{resource:n+"-eth1"}})}).then(function(e){i.port.eth1=e.data,r.resolve(i)})["catch"](function(e){r.reject(e)}),r.promise}}]).service("Slice",["$resource",function(e){return e("/xos/slices",{id:"@id"})}]).service("Instances",["$resource",function(e){return e("/xos/instances/:id",{id:"@id"})}]).service("Node",["$resource","$q","Instances",function(e,t,n){return e("/xos/nodes",{id:"@id"},{queryWithInstances:{method:"GET",isArray:!0,interceptor:{response:function(e){var r=t.defer(),i=[];return angular.forEach(e.data,function(e){i.push(n.query({node:e.id}).$promise)}),t.all(i).then(function(t){e.data.map(function(e,n){return e.instances=t[n],e}),r.resolve(e.data)}),r.promise}}}})}]).service("Subscribers",["$resource","$q","SubscriberDevice",function(e,t,n){return e("/xoslib/cordsubscriber/:id",{id:"@id"},{update:{method:"PUT",isArray:!1},queryWithDevices:{method:"GET",isArray:!0,interceptor:{response:function(e){var r=t.defer(),i=[];return angular.forEach(e.data,function(e){i.push(n.query({id:e.id}).$promise)}),t.all(i).then(function(t){e.data.map(function(e,n){return e.devices=t[n],e.type="subscriber",e.devices.map(function(e){return e.type="device"}),e}),r.resolve(e.data)}),r.promise}}},getWithDevices:{method:"GET",isArray:!1,interceptor:{response:function(e){var r=t.defer();return n.query({id:e.data.id}).$promise.then(function(t){t.map(function(e){return e.type="device"}),e.data.devices=t,e.data.type="subscriber",r.resolve(e.data)})["catch"](function(e){r.reject(e)}),r.promise}}}})}]).service("SubscriberDevice",["$resource",function(e){return e("/xoslib/rs/subscriber/:id/users/",{id:"@id"})}]).service("ServiceRelation",["$q","lodash","Services","Tenant","Slice","Instances",function(e,t,n,r,i,a){var s=function m(e){var t=0;return e.children&&e.children.forEach(function(e){var n=m(e);n>t&&(t=n)}),1+t},c=function(e,n){return t.filter(e,function(e){return e.subscriber_service===n})},o=function(e,n){var r,e=t.filter(e,function(e){return e.provider_service===n&&e.subscriber_tenant});return e.forEach(function(e){e.service_specific_attribute&&(r=JSON.parse(e.service_specific_attribute))}),r},u=function(e,n){var r=[];return t.forEach(e,function(e){var i=t.find(n,{id:e.provider_service});r.push(i)}),r},l=function b(e,n,r,i){var a=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=t.difference(n,[r]),l=c(e,r.id),d=u(l,n);s=t.difference(s,d),r.service_specific_attribute=o(e,r.id),"service_vbng"===r.humanReadableName&&(r.humanReadableName="service_vrouter");var p={name:r.humanReadableName,parent:a,type:"service",service:r,tenant:i,children:[]};return t.forEach(d,function(n){if("service_ONOS_vBNG"!==n.humanReadableName&&"service_ONOS_vOLT"!==n.humanReadableName){var a=t.find(e,{subscriber_tenant:i.id,provider_service:n.id});p.children.push(b(e,s,n,a,r.humanReadableName))}}),0===p.children.length&&p.children.push({name:"Router",type:"router",children:[]}),p},d=function(e,n){var r=arguments.length<=2||void 0===arguments[2]?{id:1,name:"fakeSubs"}:arguments[2],i=t.find(n,{subscriber_root:r.id}),a=t.find(e,{id:i.provider_service}),s=l(n,e,a,i);return{name:r.name||r.humanReadableName,parent:null,type:"subscriber",children:[s]}},p=function(e,n){var r=function s(e,n,r){"service_vbng"===r.humanReadableName&&(r.humanReadableName="service_vrouter");var i={type:"service",name:r.humanReadableName,service:r},a=t.find(n,{subscriber_service:r.id});if(a){var c=t.find(e,{id:a.provider_service});i.children=[s(e,n,c)]}else i.children=[{name:"Router",type:"router",children:[]}];return delete r.id,i},i=t.find(e,{id:3});if(!angular.isDefined(i))return void console.error("Missing Base service!");var a={name:"Subscriber",type:"subscriber",parent:null,children:[r(e,n,i)]};return a},v=function(t){var i,a,s=e.defer();return n.query().$promise.then(function(e){return i=e,r.query().$promise}).then(function(e){a=e,s.resolve(d(i,a,t))})["catch"](function(e){throw new Error(e)}),s.promise},h=function(){var t,i,a=e.defer();return n.query().$promise.then(function(e){return t=e,r.query({kind:"coarse"}).$promise}).then(function(e){i=e,a.resolve(p(t,i))})["catch"](function(e){throw new Error(e)}),a.promise};return{get:h,buildServiceTree:p,getBySubscriber:v,buildLevel:l,buildSubscriberServiceTree:d,findLevelRelation:c,findLevelServices:u,depthOf:s,findSpecificInformation:o}}])}();var _slicedToArray=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(o){i=!0,a=o}finally{try{!r&&c["return"]&&c["return"]()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(){angular.module("xos.diagnostic").service("RackHelper",["serviceTopologyConfig","lodash",function(e,t){var n=this;this.getComputeNodeLabelSize=function(){return e.computeNode.labelHeight+2*e.instance.margin},this.getComputeNodeSize=t.memoize(function(t){var r=3*e.instance.margin+2*e.instance.width,i=Math.round(t.length/2),a=n.getComputeNodeLabelSize(),s=e.instance.height*i+e.instance.margin*(i+1)+a;return[r,s]}),this.getRackSize=function(r){var i=0,a=e.computeNode.margin;return t.forEach(r,function(t){var r=n.getComputeNodeSize(t.instances),s=_slicedToArray(r,2),c=s[0],o=s[1];i=c+2*e.computeNode.margin,a+=o+e.computeNode.margin}),[i,a]},this.getInstancePosition=function(t){var r=Math.floor(t/2),i=t%2?1:0,a=n.getComputeNodeLabelSize(),s=e.instance.margin+e.instance.width*i+e.instance.margin*i,c=a+e.instance.margin+e.instance.height*r+e.instance.margin*r;return[s,c]},this.getComputeNodePosition=function(r,i){var a=e.computeNode.margin,s=t.reduce(r.slice(0,i),function(e,t){return e+n.getComputeNodeSize(t.instances)[1]},0),c=e.computeNode.margin+e.computeNode.margin*i+s;return[a,c]}}])}();var _slicedToArray=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(o){i=!0,a=o}finally{try{!r&&c["return"]&&c["return"]()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(){var e={cloud:" M 79.72 49.60 C 86.00 37.29 98.57 29.01 111.96 26.42 C 124.27 24.11 137.53 26.15 148.18 32.90 C 158.08 38.78 165.39 48.87 167.65 60.20 C 176.20 57.90 185.14 56.01 194.00 57.73 C 206.08 59.59 217.92 66.01 224.37 76.66 C 227.51 81.54 228.85 87.33 229.23 93.06 C 237.59 93.33 246.22 95.10 253.04 100.19 C 256.69 103.13 259.87 107.67 258.91 112.59 C 257.95 118.43 252.78 122.38 247.78 124.82 C 235.27 130.43 220.23 130.09 207.98 123.93 C 199.33 127.88 189.76 129.43 180.30 128.57 C 173.70 139.92 161.70 147.65 148.86 149.93 C 133.10 153.26 116.06 148.15 104.42 137.08 C 92.98 143.04 78.96 143.87 66.97 139.04 C 57.75 135.41 49.70 128.00 46.60 118.43 C 43.87 109.95 45.81 100.29 51.30 93.32 C 57.38 85.18 67.10 80.44 76.99 78.89 C 74.38 69.20 74.87 58.52 79.72 49.60 Z"},t=0,n=0;angular.module("xos.diagnostic").service("NodeDrawer",["d3","serviceTopologyConfig","RackHelper","lodash",function(r,i,a,s){var c=this,o=this;this.addNetworks=function(t){t.selectAll("*").remove(),t.append("path").attr({d:e.cloud,transform:"translate(-100, -72), scale(0.7)","class":"cloud"}),t.append("text").attr({"text-anchor":"middle",y:-5,x:5}).text(function(e){return e.name}),t.append("text").attr({"text-anchor":"middle",y:8,x:5,"class":"small"}).text(function(e){return e.subtitle}),t.each(function(e){var t=r.select(this);"LAN-Side"===e.name&&angular.isDefined(e.subscriberTag)&&(t.append("text").attr({"text-anchor":"middle",y:50}).text(function(){return"C-Tag: "+e.subscriberTag.cTag}),t.append("text").attr({"text-anchor":"middle",y:70}).text(function(){return"S-Tag: "+e.subscriberTag.sTag})),"WAN-Side"===e.name&&angular.isDefined(e.subscriberIP)&&t.append("text").attr({"text-anchor":"middle",y:50}).text(function(){return"Public IP: "+e.subscriberIP})})},this.addRack=function(e){e.each(function(t){var n=a.getRackSize(t.computeNodes),r=_slicedToArray(n,2),s=r[0],o=r[1];e.select("g").remove();var u=e.append("g");u.attr({transform:"translate(0,0)"}).transition().duration(i.duration).attr({transform:function(){return"translate("+-(s/2)+", "+-(o/2)+")"}}),u.append("rect").attr({width:0,height:0}).transition().duration(i.duration).attr({width:s,height:o}),u.append("text").attr({"text-anchor":"middle",y:-10,x:s/2,opacity:0}).text(function(e){return e.name}).transition().duration(i.duration).attr({opacity:1}),c.drawComputeNodes(u,t.computeNodes)})},this.drawComputeNodes=function(e,n){var s=e.selectAll(".compute-nodes").data(n,function(e){return angular.isString(e.d3Id)||(e.d3Id="compute-node-"+ ++t),e.d3Id}),c=e.node().getBoundingClientRect(),u=c.width,l=c.height,d=s.enter().append("g");d.attr({transform:"translate("+u/2+", "+l/2+")","class":"compute-node"}).transition().duration(i.duration).attr({transform:function(e){return"translate("+a.getComputeNodePosition(n,e.d3Id.replace("compute-node-","")-1)+")"}}),d.append("rect").attr({width:0,height:0}).transition().duration(i.duration).attr({width:function(e){return a.getComputeNodeSize(e.instances)[0]},height:function(e){return a.getComputeNodeSize(e.instances)[1]}}),d.append("text").attr({"text-anchor":"start",y:17,x:10,opacity:0}).text(function(e){return e.humanReadableName.split(".")[0]}).transition().duration(i.duration).attr({opacity:1}),d.length>0&&d.each(function(e){o.drawInstances(r.select(this),e.instances)})};var u=function(e){return e.replace("app_","").replace("service_","").replace("mysite_","").replace("_instance","")},l=function(e){function t(e,t){return t.substring(0,e.length)===e}return t("0 - ",e.backend_status)?"provisioning":t("1 - ",e.backend_status)?"good":t("2 - ",e.backend_status)?"bad":""},d=function(e,t){var n=e.append("g").attr({"class":"container",transform:"translate("+i.instance.margin+", 115)"});n.append("rect").attr({width:250-2*i.container.margin,height:i.container.height}),n.append("text").attr({y:20,x:i.instance.margin,"class":"name"}).text(t.name);var r=["memory","memory.usage","cpu_util"];r.forEach(function(e,r){var a=s.find(t.stats,{meter:e});angular.isDefined(a)&&n.append("text").attr({y:40+15*r,x:i.instance.margin,opacity:0}).text(a.description+": "+Math.round(a.value)+" "+a.unit).transition().duration(i.duration).attr({opacity:1})});var a=["eth0","eth1"],c=[{meter:"network.incoming.bytes.rate",label:"Incoming"},{meter:"network.outgoing.bytes.rate",label:"Outgoing"}];a.forEach(function(e,r){0!==t.port[e].length&&(n.append("text").attr({y:90,x:i.instance.margin+120*r,"class":"name"}).text(t.name+"-"+e),c.forEach(function(a,c){var o=s.find(t.port[e],{meter:a.meter});angular.isDefined(o)&&n.append("text").attr({y:105+15*c,x:i.instance.margin+120*r,opacity:0}).text(a.label+": "+Math.round(o.value)+" "+o.unit).transition().duration(i.duration).attr({opacity:1})}))})},p=function(e,t){var n={"mysite_vsg-1":"200, -120","mysite_vsg-2":"-300, 30","mysite_vsg-3":"-300, -250"},a=e.append("g").attr({transform:"translate("+(n[t.humanReadableName]||n["mysite_vsg-1"])+")","class":"stats-container"}).on("click",function(e){e.fade=!e.fade;var t=void 0;t=e.fade?.1:1,r.select(this).transition().duration(i.duration).attr({opacity:t})}),c={"mysite_vsg-1":{x1:-160,y1:120,x2:0,y2:50},"mysite_vsg-2":{x1:250,y1:50,x2:300,y2:-10},"mysite_vsg-3":{x1:250,y1:50,x2:300,y2:270}};a.append("line").attr({x1:function(e){return c[e.humanReadableName].x1||c["mysite_vsg-1"].x1},y1:function(e){return c[e.humanReadableName].y1||c["mysite_vsg-1"].y1},x2:function(e){return c[e.humanReadableName].x2||c["mysite_vsg-1"].x2},y2:function(e){return c[e.humanReadableName].y2||c["mysite_vsg-1"].y2},stroke:"black",opacity:0}).transition().duration(i.duration).attr({opacity:1});var o=110,u=250;t.container&&(o+=i.container.height+2*i.container.margin);a.append("rect").attr({width:u,height:o,opacity:0}).transition().duration(i.duration).attr({opacity:1});a.append("text").attr({y:15,x:i.instance.margin,"class":"name",opacity:0}).text(t.humanReadableName).transition().duration(i.duration).attr({opacity:1}),a.append("text").attr({y:30,x:i.instance.margin,"class":"ip",opacity:0}).text(t.ip).transition().duration(i.duration).attr({opacity:1});var l=["memory","memory.usage","cpu","cpu_util"];l.forEach(function(e,n){var r=s.find(t.stats,{meter:e});r&&a.append("text").attr({y:55+15*n,x:i.instance.margin,opacity:0}).text(r.description+": "+Math.round(r.value)+" "+r.unit).transition().duration(i.duration).attr({opacity:1})}),t.container&&d(a,t.container)};this.drawInstances=function(e,t){var s=e.node().getBoundingClientRect(),c=s.width,o=s.height,d=e.selectAll(".instances").data(t,function(e){return angular.isString(e.d3Id)?e.d3Id:e.d3Id="instance-"+ ++n}),v=d.enter().append("g");v.attr({transform:"translate("+c/2+", "+o/2+")","class":function(e){return"instance "+(e.selected?"active":"")+" "+l(e)}}).transition().duration(i.duration).attr({transform:function(e,t){return"translate("+a.getInstancePosition(t)+")"}}),v.append("rect").attr({width:0,height:0}).transition().duration(i.duration).attr({width:i.instance.width,height:i.instance.height}),v.append("text").attr({"text-anchor":"middle",y:23,x:40,opacity:0}).text(function(e){return u(e.humanReadableName)}).transition().duration(i.duration).attr({opacity:1}),v.each(function(e,t){var n=r.select(this);angular.isDefined(e.stats)&&e.selected&&p(n,e,t)})},this.addPhisical=function(e){e.select("rect").remove(),e.select("text").remove(),e.append("rect").attr(i.square),e.append("text").attr({"text-anchor":"middle",y:i.square.y-10}).text(function(e){return e.name||e.humanReadableName})},this.addDevice=function(e){e.append("circle").attr(i.circle),e.append("text").attr({"text-anchor":"end",x:-i.circle.r-10,y:i.circle.r/2}).text(function(e){return e.name||e.mac})}}])}();var _slicedToArray=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(o){i=!0,a=o}finally{try{!r&&c["return"]&&c["return"]()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(){angular.module("xos.diagnostic").service("LogicTopologyHelper",["$window","$log","$rootScope","lodash","serviceTopologyConfig","NodeDrawer","ChartData",function(e,t,n,r,i,a,s){var c,o,u,l,d,p,v=this,h=0,m=s.logicTopologyData;this.computeElementPosition=function(e){var t=[],n=r.reduce(i.elWidths,function(e,t){return t+e},0),a=e-n-2*i.widthMargin,s=a/(i.elWidths.length-1);return r.forEach(i.elWidths,function(n,a){var c=0;0!==a&&(c=r.reduce(i.elWidths.slice(0,a),function(e,t){return t+e},0));var o=i.widthMargin+s*a+n/2+c;t.push(e-o)}),t};var b=function(e){var t=p.nodes(e);t.forEach(function(e){e.y=v.computeElementPosition(l)[e.depth]});var n=p.links(t);return[t,n]},g=function(e,t){var r=e.selectAll("g.node").data(t,function(e){return angular.isString(e.d3Id)||(e.d3Id="tree-"+ ++h),e.d3Id});r.enter().append("g").attr({"class":function(e){return"node "+e.type},transform:"translate("+l/2+", "+d/2+")"});a.addNetworks(r.filter(".network")),a.addRack(r.filter(".rack")),a.addPhisical(r.filter(".router")),a.addPhisical(r.filter(".subscriber")),a.addDevice(r.filter(".device")),r.filter(".subscriber").on("click",function(){n.$emit("subscriber.modal.open")});r.transition().duration(i.duration).attr({transform:function(e){return"translate("+e.y+","+e.x+")"}}),r.exit().remove()},f=function(e,t){c=d3.svg.diagonal().projection(function(e){return[e.y,e.x]});var n=e.selectAll("path.link").data(t,function(e){return e.target.d3Id});n.enter().insert("path","g").attr("class",function(e){return"link "+e.target.type}).attr("d",function(e){var t={x:d/2,y:l/2};return c({source:t,target:t})}),n.transition().duration(i.duration).attr("d",c),n.exit().remove()};this.setupTree=function(e){l=e.node().getBoundingClientRect().width,d=e.node().getBoundingClientRect().height;var t=l-2*i.widthMargin,n=d-2*i.heightMargin;p=d3.layout.tree().size([n,t])},this.updateTree=function(e){var t=b(m),n=_slicedToArray(t,2);o=n[0],u=n[1],g(e,o),f(e,u)}}])}(),function(){angular.module("xos.diagnostic").directive("logicTopology",function(){return{restrict:"E",scope:{subscribers:"=",selected:"="},bindToController:!0,controllerAs:"vm",templateUrl:"templates/logicTopology.tpl.html",controller:["$element","$log","$scope","$rootScope","$timeout","d3","LogicTopologyHelper","Node","Tenant","Ceilometer","serviceTopologyConfig","ChartData",function(e,t,n,r,i,a,s,c,o,u,l,d){var p=this;t.info("Logic Plane");var v;this.selectedInstances=[],this.hideInstanceStats=!0;var h=this,m=function(t){a.select(e[0]).select("svg").remove(),v=a.select(t).append("svg").style("width",t.clientWidth+"px").style("height",t.clientHeight+"px")},b=function(){d.getLogicTree().then(function(e){s.updateTree(v)})};b(),n.$watch(function(){return p.selected},function(e){e?(d.selectSubscriber(e),s.updateTree(v)):(d.removeSubscriber(),s.updateTree(v))}),r.$on("instance.detail.hide",function(){p.hideInstanceStats=!0,i(function(){p.selectedInstances=[],d.highlightInstances([]),s.updateTree(v)},500)}),r.$on("instance.detail",function(e,t){d.getInstanceStatus(t).then(function(e){s.updateTree(v)})["catch"](function(e){
+h.error="Service statistics are not available at this time. Please try again later.",i(function(){h.error=null},2e3)})}),a.select(window).on("resize.logic",function(){m(e[0]),s.setupTree(v),s.updateTree(v)}),m(e[0]),s.setupTree(v),this.selectSubscriberModal=function(){p.openSelectSubscriberModal=!0,n.$apply()},this.subscriberStatusModal=function(){p.openSubscriberStatusModal=!0,n.$apply()},r.$on("subscriber.modal.open",function(){d.currentSubscriber?p.subscriberStatusModal():p.selectSubscriberModal()}),r.$on("subscriber.modal.open",function(){d.currentSubscriber?(p.currentSubscriber=d.currentSubscriber,p.subscriberStatusModal()):p.selectSubscriberModal()})}]}})}(),function(){angular.module("xos.diagnostic").directive("diagnosticContainer",function(){return{restrict:"E",templateUrl:"templates/diagnostic.tpl.html",controllerAs:"vm",controller:["ChartData","Subscribers","ServiceRelation","$rootScope","$log",function(e,t,n,r,i){var a=this;this.loader=!0,this.error=!1;var s=function(){t.query().$promise.then(function(e){return a.subscribers=e,n.get()}).then(function(e){a.serviceChain=e})["catch"](function(e){throw new Error(e)})["finally"](function(){a.loader=!1})};s(),this.reloadGlobalScope=function(){a.selectedSubscriber=null,s()};var c=function(r){n.getBySubscriber(r).then(function(n){return a.serviceChain=n,e.currentServiceChain=n,t.getWithDevices({id:r.id}).$promise}).then(function(t){a.selectedSubscriber=t,e.currentSubscriber=t})};r.$on("subscriber.selected",function(e,t){c(t)})}]}})}(),function(){angular.module("xos.diagnostic").factory("d3",["$window",function(e){return e.d3}])}(),function(){angular.module("xos.diagnostic").constant("serviceTopologyConfig",{widthMargin:60,heightMargin:30,duration:750,elWidths:[20,104,105,104,20],circle:{radius:10,r:10,selectedRadius:15},square:{width:20,height:20,x:-10,y:-10},rack:{width:105,height:50,x:-30,y:-25},computeNode:{width:50,height:20,margin:5,labelHeight:10,x:-25,y:-10},instance:{width:80,height:36,margin:5,x:-40,y:-18},container:{width:60,height:130,margin:5,x:-30,y:-15}})}(),function(){angular.module("xos.diagnostic").service("ChartData",["$rootScope","$q","lodash","Tenant","Node","serviceTopologyConfig","Ceilometer","Instances",function(e,t,n,r,i,a,s,c){var o=this;this.currentSubscriber=null,this.currentServiceChain=null,this.logicTopologyData={name:"Router",type:"router",children:[{name:"WAN-Side",subtitle:"Virtual Network",type:"network",children:[{name:"Compute Servers",type:"rack",computeNodes:[],children:[{name:"LAN-Side",subtitle:"Virtual Network",type:"network",children:[{name:"Subscriber",type:"subscriber"}]}]}]}]},this.getLogicTree=function(){var e=t.defer();return i.queryWithInstances().$promise.then(function(t){o.logicTopologyData.children[0].children[0].computeNodes=t,e.resolve(o.logicTopologyData)}),e.promise},this.addSubscriberTag=function(e){o.logicTopologyData.children[0].children[0].children[0].subscriberTag={cTag:e.cTag,sTag:e.sTag}},this.addSubscriber=function(e){return e.children=e.devices,o.logicTopologyData.children[0].children[0].children[0].children=[e],o.logicTopologyData},this.removeSubscriber=function(){o.logicTopologyData.children[0].children[0].children[0].children[0].humanReadableName="Subscriber",o.currentSubscriber=null,160===a.elWidths[a.elWidths.length-1]&&a.elWidths.pop(),delete o.logicTopologyData.children[0].children[0].children[0].subscriberTag,delete o.logicTopologyData.children[0].subscriberIP,o.highlightInstances([]),delete o.logicTopologyData.children[0].children[0].children[0].children[0].children},this.getSubscriberTag=function(e){var t={cTag:e.c_tag,sTag:e.s_tag};o.addSubscriberTag(t),o.currentSubscriber.tags=t},this.getSubscriberIP=function(e){o.logicTopologyData.children[0].subscriberIP=e.wan_container_ip},this.selectSubscriber=function(e){a.elWidths.push(160),o.addSubscriber(angular.copy(e)),o.highlightInstances([]),o.getSubscriberTag(e),o.getSubscriberIP(e)},this.highlightInstances=function(e){var t=o.logicTopologyData.children[0].children[0].computeNodes;t.map(function(e){e.instances.map(function(e){return e.selected=!1,e})}),n.forEach(e,function(e){t.map(function(t){t.instances.map(function(t){return t.id===e.id&&(t.selected=!0,t.stats=e.stats,t.container=e.container),t})})})},this.getInstanceStatus=function(e){var i=t.defer(),a=void 0;if(o.currentSubscriber){var u=void 0;try{u=JSON.parse(e.tenant.service_specific_attribute)}catch(l){u=null}if(u&&u.instance_id)!function(){var e={};a=c.get({id:u.instance_id}).$promise.then(function(t){return e=t,s.getInstanceStats(e.instance_uuid)}).then(function(t){e.stats=t;var n="vcpe-"+o.currentSubscriber.tags.sTag+"-"+o.currentSubscriber.tags.cTag;return e.container={name:n},s.getContainerStats(n)}).then(function(t){return e.container.stats=t.stats,e.container.port=t.port,[e]})}();else{var d=t.defer();d.resolve([]),a=d.promise}}else{var p={service_vsg:{kind:"vCPE"},service_vbng:{kind:"vBNG"},service_volt:{kind:"vOLT"}};a=r.queryVsgInstances(p[e.name]).$promise.then(function(e){return s.getInstancesStats(n.uniq(e))})}return a.then(function(e){o.highlightInstances(e),i.resolve(e)})["catch"](function(e){i.reject(e)}),i.promise}}])}(),angular.module("xos.diagnostic").run(["$location",function(e){e.path("/")}]);
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xosSampleView.js b/xos/core/xoslib/static/js/xosSampleView.js
index 69ec0bc..9c05349 100644
--- a/xos/core/xoslib/static/js/xosSampleView.js
+++ b/xos/core/xoslib/static/js/xosSampleView.js
@@ -1 +1 @@
-"use strict";angular.module("xos.sampleView",["ngResource","ngCookies","ngLodash","ui.router","xos.helpers"]).config(["$stateProvider",function(s){s.state("user-list",{url:"/",template:"<users-list></users-list>"})}]).config(["$httpProvider",function(s){s.interceptors.push("NoHyperlinks")}]).directive("usersList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/users-list.tpl.html",controller:["XosApi",function(s){var e=this;s.User_List_GET().then(function(s){e.users=s})["catch"](function(s){throw new Error(s)})}]}}),angular.module("xos.sampleView").run(["$templateCache",function(s){s.put("templates/users-list.tpl.html",'<div class="row">\n  <h1>Users List</h1>\n  <p>This is only an example view.</p>\n</div>\n<div class="row">\n  <div class="span4">Email</div>\n  <div class="span4">First Name</div>\n  <div class="span4">Last Name</div>\n</div>  \n<div class="row" ng-repeat="user in vm.users">\n  <div class="span4">{{user.email}}</div>\n  <div class="span4">{{user.firstname}}</div>\n  <div class="span4">{{user.lastname}}</div>\n</div>  ')}]),angular.bootstrap(angular.element("#xosSampleView"),["xos.sampleView"]);
\ No newline at end of file
+"use strict";angular.module("xos.sampleView",["ngResource","ngCookies","ngLodash","ui.router","xos.helpers"]).config(["$stateProvider",function(s){s.state("user-list",{url:"/",template:"<users-list></users-list>"})}]).config(["$httpProvider",function(s){s.interceptors.push("NoHyperlinks")}]).directive("usersList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/users-list.tpl.html",controller:["Users",function(s){var e=this;s.query().$promise.then(function(s){e.users=s})["catch"](function(s){throw new Error(s)})}]}}),angular.module("xos.sampleView").run(["$templateCache",function(s){s.put("templates/users-list.tpl.html",'<div class="row">\n  <h1>Users List</h1>\n  <p>This is only an example view.</p>\n</div>\n<div class="row">\n  <div class="col-xs-4">Email</div>\n  <div class="col-xs-4">First Name</div>\n  <div class="col-xs-4">Last Name</div>\n</div>  \n<div class="row" ng-repeat="user in vm.users">\n  <div class="col-xs-4">{{user.email}}</div>\n  <div class="col-xs-4">{{user.firstname}}</div>\n  <div class="col-xs-4">{{user.lastname}}</div>\n</div>  ')}]),angular.module("xos.sampleView").run(["$location",function(s){s.path("/")}]);
\ No newline at end of file
diff --git a/xos/services/cord/admin.py b/xos/services/cord/admin.py
index 3cccc6c..e7704d3 100644
--- a/xos/services/cord/admin.py
+++ b/xos/services/cord/admin.py
@@ -104,9 +104,6 @@
     bbs_server = forms.CharField(required=False)
     backend_network_label = forms.CharField(required=False)
     bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False)
-    wan_container_gateway_ip = forms.CharField(required=False)
-    wan_container_gateway_mac = forms.CharField(required=False)
-    wan_container_netbits = forms.CharField(required=False)
     dns_servers = forms.CharField(required=False)
     url_filter_kind = forms.ChoiceField(choices=VSGService.URL_FILTER_KIND_CHOICES, required=False)
     node_label = forms.CharField(required=False)
@@ -119,9 +116,6 @@
             self.fields['bbs_server'].initial = self.instance.bbs_server
             self.fields['backend_network_label'].initial = self.instance.backend_network_label
             self.fields['bbs_slice'].initial = self.instance.bbs_slice
-            self.fields['wan_container_gateway_ip'].initial = self.instance.wan_container_gateway_ip
-            self.fields['wan_container_gateway_mac'].initial = self.instance.wan_container_gateway_mac
-            self.fields['wan_container_netbits'].initial = self.instance.wan_container_netbits
             self.fields['dns_servers'].initial = self.instance.dns_servers
             self.fields['url_filter_kind']. initial = self.instance.url_filter_kind
             self.fields['node_label'].initial = self.instance.node_label
@@ -132,9 +126,6 @@
         self.instance.bbs_server = self.cleaned_data.get("bbs_server")
         self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
         self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
-        self.instance.wan_container_gateway_ip = self.cleaned_data.get("wan_container_gateway_ip")
-        self.instance.wan_container_gateway_mac = self.cleaned_data.get("wan_container_gateway_mac")
-        self.instance.wan_container_netbits = self.cleaned_data.get("wan_container_netbits")
         self.instance.dns_servers = self.cleaned_data.get("dns_servers")
         self.instance.url_filter_kind = self.cleaned_data.get("url_filter_kind")
         self.instance.node_label = self.cleaned_data.get("node_label")
@@ -153,7 +144,7 @@
                                      'classes':['suit-tab suit-tab-general']}),
                  ("backend config", {'fields': [ "backend_network_label", "url_filter_kind", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"],
                                      'classes':['suit-tab suit-tab-backend']}),
-                 ("vSG config", {'fields': [ "wan_container_gateway_ip", "wan_container_gateway_mac", "wan_container_netbits", "dns_servers"],
+                 ("vSG config", {'fields': ["dns_servers"],
                                      'classes':['suit-tab suit-tab-vsg']}) ]
     readonly_fields = ('backend_status_text', "service_specific_attribute")
     inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index 0da4809..c57d9fb 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -372,9 +372,6 @@
                           ("bbs_api_port", None),
                           ("bbs_server", None),
                           ("backend_network_label", "hpc_client"),
-                          ("wan_container_gateway_ip", ""),
-                          ("wan_container_gateway_mac", ""),
-                          ("wan_container_netbits", "24"),
                           ("dns_servers", "8.8.8.8"),
                           ("url_filter_kind", None),
                           ("node_label", None) )
@@ -419,25 +416,15 @@
 
 VSGService.setup_simple_attributes()
 
-#class STagBlock(PlCoreBase):
-#    instance = models.ForeignKey(Instance, related_name="s_tags")
-#    s_tag = models.CharField(null=false, blank=false, unique=true, max_length=10)
-#    #c_tags = models.TextField(null=true, blank=true)
-#
-#    def __unicode__(self): return u'%s' % (self.s_tag)
-
 class VSGTenant(TenantWithContainer):
     class Meta:
         proxy = True
 
     KIND = VCPE_KIND
 
-    sync_attributes = ("nat_ip", "nat_mac",
-                       "lan_ip", "lan_mac",
-                       "wan_ip", "wan_mac",
-                       "wan_container_ip", "wan_container_mac",
-                       "private_ip", "private_mac",
-                       "hpc_client_ip", "hpc_client_mac")
+    sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
+                       "wan_container_gateway_ip", "wan_container_gateway_mac",
+                       "wan_vm_ip", "wan_vm_mac")
 
     default_attributes = {"instance_id": None,
                           "container_id": None,
@@ -448,22 +435,12 @@
 
     def __init__(self, *args, **kwargs):
         super(VSGTenant, self).__init__(*args, **kwargs)
-        self.cached_vbng=None
         self.cached_vrouter=None
 
     @property
     def vbng(self):
-        vbng = self.get_newest_subscribed_tenant(VBNGTenant)
-        if not vbng:
-            return None
-
-        # always return the same object when possible
-        if (self.cached_vbng) and (self.cached_vbng.id == vbng.id):
-            return self.cached_vbng
-
-        vbng.caller = self.creator
-        self.cached_vbng = vbng
-        return vbng
+        # not supported
+        return None
 
     @vbng.setter
     def vbng(self, value):
@@ -523,92 +500,31 @@
     def ssh_command(self, value):
         pass
 
-    @property
-    def addresses(self):
-        if self.instance:
-            ports = self.instance.ports.all()
-        elif self.container:
-            ports = self.container.ports.all()
+    def get_vrouter_field(self, name, default=None):
+        if self.vrouter:
+            return getattr(self.vrouter, name, default)
         else:
-            return {}
-
-        addresses = {}
-        for ns in ports:
-            if "lan" in ns.network.name.lower():
-                addresses["lan"] = (ns.ip, ns.mac)
-            elif "wan" in ns.network.name.lower():
-                addresses["wan"] = (ns.ip, ns.mac)
-            elif "private" in ns.network.name.lower():
-                addresses["private"] = (ns.ip, ns.mac)
-            elif "nat" in ns.network.name.lower():
-                addresses["nat"] = (ns.ip, ns.mac)
-            elif "hpc_client" in ns.network.name.lower():
-                addresses["hpc_client"] = (ns.ip, ns.mac)
-        return addresses
-
-    # ------------------------------------------------------------------------
-    # The following IP addresses all come from the VM
-    # Note: They might not be useful for the VTN-vSG
-
-    @property
-    def nat_ip(self):
-        return self.addresses.get("nat", (None,None) )[0]
-
-    @property
-    def nat_mac(self):
-        return self.addresses.get("nat", (None,None) )[1]
-
-    @property
-    def lan_ip(self):
-        return self.addresses.get("lan", (None, None) )[0]
-
-    @property
-    def lan_mac(self):
-        return self.addresses.get("lan", (None, None) )[1]
-
-    @property
-    def wan_ip(self):
-        return self.addresses.get("wan", (None, None) )[0]
-
-    @property
-    def wan_mac(self):
-        return self.addresses.get("wan", (None, None) )[1]
-
-    # end of VM IP address stubs
-    # ------------------------------------------------------------------------
+            return default
 
     @property
     def wan_container_ip(self):
-        if self.vrouter:
-            return self.vrouter.public_ip
-        else:
-            if  (CORD_USE_VTN):
-                # Should this be an error?
-                return None
-            else:
-                # When not using VTN, wan_container_ip is the same as wan_ip.
-                # XXX Is this broken for multiple-containers-per-VM?
-                return self.wan_ip
+        return self.get_vrouter_field("public_ip", None)
 
-    @wan_container_ip.setter
-    def wan_container_ip(self, value):
-        raise Exception("wan_container_ip is not settable")
-
-    def ip_to_mac(self, ip):
-        (a, b, c, d) = ip.split('.')
-        return "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
-
-    # Generate the MAC for the container interface connected to WAN
     @property
     def wan_container_mac(self):
-        if self.vrouter:
-            return self.vrouter.public_mac
-        else:
-            if (CORD_USE_VTN):
-                # Should this be an error?
-                return None
-            else:
-                return self.ip_to_mac(self.wan_container_ip)
+        return self.get_vrouter_field("public_mac", None)
+
+    @property
+    def wan_container_netbits(self):
+        return self.get_vrouter_field("netbits", None)
+
+    @property
+    def wan_container_gateway_ip(self):
+        return self.get_vrouter_field("gateway_ip", None)
+
+    @property
+    def wan_container_gateway_mac(self):
+        return self.get_vrouter_field("gateway_mac", None)
 
     @property
     def wan_vm_ip(self):
@@ -617,10 +533,7 @@
             tenant = VRouterTenant.objects.get(id=tags[0].value)
             return tenant.public_ip
         else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
-            else:
-                return ""
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
 
     @property
     def wan_vm_mac(self):
@@ -629,26 +542,7 @@
             tenant = VRouterTenant.objects.get(id=tags[0].value)
             return tenant.public_mac
         else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
-            else:
-                return ""
-
-    @property
-    def private_ip(self):
-        return self.addresses.get("private", (None, None) )[0]
-
-    @property
-    def private_mac(self):
-        return self.addresses.get("private", (None, None) )[1]
-
-    @property
-    def hpc_client_ip(self):
-        return self.addresses.get("hpc_client", (None, None) )[0]
-
-    @property
-    def hpc_client_mac(self):
-        return self.addresses.get("hpc_client", (None, None) )[1]
+            raise Exception("no vm_vrouter_tenant tag for instance %s" % o.instance)
 
     @property
     def is_synced(self):
@@ -658,27 +552,6 @@
     def is_synced(self, value):
         pass
 
-    def manage_vbng(self):
-        # Each vCPE object owns exactly one vBNG object
-
-        if self.deleted:
-            return
-
-        if self.vbng is None:
-            vbngServices = VBNGService.get_service_objects().all()
-            if not vbngServices:
-                raise XOSConfigurationError("No VBNG Services available")
-
-            vbng = VBNGTenant(provider_service = vbngServices[0],
-                              subscriber_tenant = self)
-            vbng.caller = self.creator
-            vbng.save()
-
-    def cleanup_vbng(self):
-        if self.vbng:
-            # print "XXX cleanup vnbg", self.vbng
-            self.vbng.delete()
-
     def get_vrouter_service(self):
         vrouterServices = VRouterService.get_service_objects().all()
         if not vrouterServices:
@@ -702,13 +575,6 @@
             self.vrouter.delete()
 
     def cleanup_orphans(self):
-        # ensure vCPE only has one vBNG
-        cur_vbng = self.vbng
-        for vbng in list(self.get_subscribed_tenants(VBNGTenant)):
-            if (not cur_vbng) or (vbng.id != cur_vbng.id):
-                # print "XXX clean up orphaned vbng", vbng
-                vbng.delete()
-
         # ensure vCPE only has one vRouter
         cur_vrouter = self.vrouter
         for vrouter in list(self.get_subscribed_tenants(VRouterTenant)):
@@ -900,7 +766,6 @@
         model_policy_vcpe(self.pk)
 
     def delete(self, *args, **kwargs):
-        self.cleanup_vbng()
         self.cleanup_vrouter()
         self.cleanup_container()
         super(VSGTenant, self).delete(*args, **kwargs)
@@ -914,7 +779,6 @@
         vcpe = vcpe[0]
         vcpe.manage_container()
         vcpe.manage_vrouter()
-        #vcpe.manage_vbng()
         vcpe.manage_bbs_account()
         vcpe.cleanup_orphans()
 
diff --git a/xos/services/vrouter/models.py b/xos/services/vrouter/models.py
index 5dba838..05b57e2 100644
--- a/xos/services/vrouter/models.py
+++ b/xos/services/vrouter/models.py
@@ -95,6 +95,15 @@
         return self.address_pool.cidr
 
     @property
+    def netbits(self):
+        # return number of bits in the network portion of the cidr
+        if self.cidr:
+            parts = self.cidr.split("/")
+            if len(parts)==2:
+                return int(parts[1].strip())
+        return None
+
+    @property
     def address_pool(self):
         if getattr(self, "cached_address_pool", None):
             return self.cached_address_pool
diff --git a/xos/services/vtn/__init__.py b/xos/services/vtn/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/xos/services/vtn/__init__.py
@@ -0,0 +1 @@
+
diff --git a/xos/services/vtn/admin.py b/xos/services/vtn/admin.py
new file mode 100644
index 0000000..c64e054
--- /dev/null
+++ b/xos/services/vtn/admin.py
@@ -0,0 +1,87 @@
+from django.contrib import admin
+
+from services.cord.models import *
+from django import forms
+from django.utils.safestring import mark_safe
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.admin.widgets import FilteredSelectMultiple
+from django.contrib.auth.forms import ReadOnlyPasswordHashField
+from django.contrib.auth.signals import user_logged_in
+from django.utils import timezone
+from django.contrib.contenttypes import generic
+from suit.widgets import LinkedSelect
+from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
+from core.middleware import get_request
+
+from services.vtn.models import *
+from services.cord.models import CordSubscriberRoot
+
+from functools import update_wrapper
+from django.contrib.admin.views.main import ChangeList
+from django.core.urlresolvers import reverse
+from django.contrib.admin.utils import quote
+
+class VTNServiceForm(forms.ModelForm):
+    privateGatewayMac = forms.CharField(required=False)
+    localManagementIp = forms.CharField(required=False)
+    ovsdbPort = forms.CharField(required=False)
+    sshPort = forms.CharField(required=False)
+    sshUser = forms.CharField(required=False)
+    sshKeyFile = forms.CharField(required=False)
+    mgmtSubnetBits = forms.CharField(required=False)
+
+    def __init__(self,*args,**kwargs):
+        super (VTNServiceForm,self ).__init__(*args,**kwargs)
+        if self.instance:
+            self.fields['privateGatewayMac'].initial = self.instance.privateGatewayMac
+            self.fields['localManagementIp'].initial = self.instance.localManagementIp
+            self.fields['ovsdbPort'].initial = self.instance.ovsdbPort
+            self.fields['sshPort'].initial = self.instance.sshPort
+            self.fields['sshUser'].initial = self.instance.sshUser
+            self.fields['sshKeyFile'].initial = self.instance.sshKeyFile
+            self.fields['mgmtSubnetBits'].initial = self.instance.mgmtSubnetBits
+
+    def save(self, commit=True):
+        self.instance.privateGatewayMac = self.cleaned_data.get("privateGatewayMac")
+        self.instance.localManagementIp = self.cleaned_data.get("localManagementIp")
+        self.instance.ovsdbPort = self.cleaned_data.get("ovsdbPort")
+        self.instance.sshPort = self.cleaned_data.get("sshPort")
+        self.instance.sshUser = self.cleaned_data.get("sshUser")
+        self.instance.sshKeyFile = self.cleaned_data.get("sshKeyFile")
+        self.instance.mgmtSubnetBits = self.cleaned_data.get("mgmtSubnetBits")
+        return super(VTNServiceForm, self).save(commit=commit)
+
+    class Meta:
+        model = VTNService
+
+class VTNServiceAdmin(ReadOnlyAwareAdmin):
+    model = VTNService
+    form = VTNServiceForm
+    verbose_name = "VTN Service"
+    verbose_name_plural = "VTN Service"
+    list_display = ("backend_status_icon", "name", "enabled")
+    list_display_links = ('backend_status_icon', 'name', )
+    fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber','description',"view_url","icon_url",
+                                    'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits' ], 'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', )
+    inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
+
+    extracontext_registered_admins = True
+
+    user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
+
+    suit_form_tabs =(('general', 'VTN Service Details'),
+#        ('administration', 'Administration'),
+        ('slices','Slices'),
+        ('serviceattrs','Additional Attributes'),
+        ('serviceprivileges','Privileges'),
+    )
+
+    suit_form_includes = ( # ('vtnadmin.html', 'top', 'administration'),
+                           ) #('hpctools.html', 'top', 'tools') )
+
+    def queryset(self, request):
+        return VTNService.get_service_objects_by_user(request.user)
+
+admin.site.register(VTNService, VTNServiceAdmin)
+
diff --git a/xos/services/vtn/models.py b/xos/services/vtn/models.py
new file mode 100644
index 0000000..cb254d7
--- /dev/null
+++ b/xos/services/vtn/models.py
@@ -0,0 +1,44 @@
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber, NetworkParameter, NetworkParameterType, Port, AddressPool
+from core.models.plcorebase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+from core.models import Tag
+from core.models.service import LeastLoadedNodeScheduler
+from services.cord.models import CordSubscriberRoot
+import traceback
+from xos.exceptions import *
+from xos.config import Config
+
+class ConfigurationError(Exception):
+    pass
+
+VTN_KIND = "VTN"
+
+# -------------------------------------------
+# VTN
+# -------------------------------------------
+
+class VTNService(Service):
+    KIND = VTN_KIND
+
+    class Meta:
+        app_label = "vtn"
+        verbose_name = "VTN Service"
+        proxy = True
+
+    simple_attributes = ( ("privateGatewayMac", "00:00:00:00:00:01"),
+                          ("localManagementIp", "172.27.0.1/24"),
+                          ("ovsdbPort", "6641"),
+                          ("sshPort", "22"),
+                          ("sshUser", "root"),
+                          ("sshKeyFile", "/root/node_key") ,
+                          ("mgmtSubnetBits", "24"),
+
+                         )
+
+VTNService.setup_simple_attributes()
+
diff --git a/xos/services/vtn/templates/vtnadmin.html b/xos/services/vtn/templates/vtnadmin.html
new file mode 100644
index 0000000..a3a2a52
--- /dev/null
+++ b/xos/services/vtn/templates/vtnadmin.html
@@ -0,0 +1,5 @@
+<div class = "row text-center">
+    <div class="col-xs-12">
+        <a href="/admin/vtn/vnrtenant/">vTN Tenants</a>
+    </div>
+</div>
diff --git a/xos/synchronizers/onos/steps/sync_onosapp.py b/xos/synchronizers/onos/steps/sync_onosapp.py
index 77c9e91..add749d 100644
--- a/xos/synchronizers/onos/steps/sync_onosapp.py
+++ b/xos/synchronizers/onos/steps/sync_onosapp.py
@@ -165,13 +165,9 @@
             controller = controllers[0]
             keystone_server = controller.auth_url
             user_name = controller.admin_user
+            tenant_name = controller.admin_tenant
             password = controller.admin_password
 
-        # Put this in the controller object?  Or fetch it from Keystone?
-        # Seems like VTN should be pulling it from Keystone
-        # For now let it be specified by a service / tenant attribute
-        neutron_server = self.attribute_default(o, attrs, "neutron_server", "http://neutron-api:9696/v2.0/")
-
         data = {
             "apps" : {
                 "org.onosproject.cordvtn" : {
@@ -179,21 +175,20 @@
                         "privateGatewayMac" : privateGatewayMac,
                         "localManagementIp": localManagementIp,
                         "ovsdbPort": ovsdbPort,
-                        "sshPort": sshPort,
-                        "sshUser": sshUser,
-                        "sshKeyFile": sshKeyFile,
+                        "ssh": {
+                            "sshPort": sshPort,
+                            "sshUser": sshUser,
+                            "sshKeyFile": sshKeyFile
+                        },
+                        "openstack": {
+                            "endpoint": keystone_server,
+                            "tenant": tenant_name,
+                            "user": user_name,
+                            "password": password
+                        },
                         "publicGateways": [],
                         "nodes" : []
                     }
-                },
-                "org.onosproject.openstackinterface" : {
-                    "openstackinterface" : {
-                        "do_not_push_flows" : "true",
-                        "neutron_server" : neutron_server,
-                        "keystone_server" : keystone_server,
-                        "user_name" : user_name,
-                        "password" : password
-                    }
                 }
             }
         }
diff --git a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
index c28b3c1..9e3dfac 100644
--- a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
+++ b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
@@ -153,9 +153,6 @@
                         if mac:
                             safe_macs.append(mac)
 
-        wan_vm_ip=o.wan_vm_ip
-        wan_vm_mac=o.wan_vm_mac
-
         fields = {"vlan_ids": vlan_ids,   # XXX remove this
                 "s_tags": s_tags,
                 "c_tags": c_tags,
@@ -164,11 +161,6 @@
                 "bbs_addrs": bbs_addrs,
                 "full_setup": full_setup,
                 "isolation": o.instance.isolation,
-                "wan_container_gateway_mac": vcpe_service.wan_container_gateway_mac,
-                "wan_container_gateway_ip": vcpe_service.wan_container_gateway_ip,
-                "wan_container_netbits": vcpe_service.wan_container_netbits,
-                "wan_vm_mac": wan_vm_mac,
-                "wan_vm_ip": wan_vm_ip,
                 "safe_browsing_macs": safe_macs,
                 "container_name": "vcpe-%s-%s" % (s_tags[0], c_tags[0]),
                 "dns_servers": [x.strip() for x in vcpe_service.dns_servers.split(",")],
diff --git a/xos/synchronizers/vtr/steps/sync_vtrtenant.py b/xos/synchronizers/vtr/steps/sync_vtrtenant.py
index d2ec209..8debadf 100644
--- a/xos/synchronizers/vtr/steps/sync_vtrtenant.py
+++ b/xos/synchronizers/vtr/steps/sync_vtrtenant.py
@@ -84,35 +84,22 @@
             s_tags.append(o.target.volt.s_tag)
             c_tags.append(o.target.volt.c_tag)
 
-        wan_vm_ip=""
-        wan_vm_mac=""
-        tags = Tag.select_by_content_object(instance).filter(name="vm_wan_addr")
-        if tags:
-            parts=tags[0].value.split(",")
-            if len(parts)!=3:
-                raise Exception("vm_wan_addr tag is malformed: %s" % value)
-            wan_vm_ip = parts[1]
-            wan_vm_mac = parts[2]
-        else:
-            if CORD_USE_VTN:
-                raise Exception("no vm_wan_addr tag for instance %s" % instance)
-
         fields = {"s_tags": s_tags,
                 "c_tags": c_tags,
                 "isolation": instance.isolation,
-                "wan_container_gateway_mac": vcpe_service.wan_container_gateway_mac,
-                "wan_container_gateway_ip": vcpe_service.wan_container_gateway_ip,
-                "wan_container_netbits": vcpe_service.wan_container_netbits,
-                "wan_vm_mac": wan_vm_mac,
-                "wan_vm_ip": wan_vm_ip,
                 "container_name": "vcpe-%s-%s" % (s_tags[0], c_tags[0]),
                 "dns_servers": [x.strip() for x in vcpe_service.dns_servers.split(",")],
 
                 "result_fn": "%s-vcpe-%s-%s" % (o.test, s_tags[0], c_tags[0]),
                 "resultcode_fn": "code-%s-vcpe-%s-%s" % (o.test, s_tags[0], c_tags[0]) }
 
-        # add in the sync_attributes that come from the SubscriberRoot object
+        # add in the sync_attributes that come from the vSG object
+        # this will be wan_ip, wan_mac, wan_container_ip, wan_container_mac, ...
+        if o.target and o.target.volt and o.target.volt.vsg:
+            for attribute_name in o.target.volt.vsg.sync_attributes:
+                fields[attribute_name] = getattr(o.target.volt.vsg, attribute_name)
 
+        # add in the sync_attributes that come from the SubscriberRoot object
         if o.target and hasattr(o.target, "sync_attributes"):
             for attribute_name in o.target.sync_attributes:
                 fields[attribute_name] = getattr(o.target, attribute_name)
diff --git a/xos/templates/admin/base.html b/xos/templates/admin/base.html
index 3af6b33..b47bf74 100644
--- a/xos/templates/admin/base.html
+++ b/xos/templates/admin/base.html
@@ -39,7 +39,6 @@
   <!-- ngXosLib -->
   <script src="{% static 'js/vendor/ngXosVendor.js' %}"></script>
   <script src="{% static 'js/vendor/ngXosHelpers.js' %}"></script>
-  <script src="{% static 'js/xosApi.js' %}"></script>
 
   <script type="text/javascript">var Suit = { $: $.noConflict() }; if (!$) $ = Suit.$; </script>
   {% if 'SHOW_REQUIRED_ASTERISK'|suit_conf %}
diff --git a/xos/tests/api/apiary.apib b/xos/tests/api/apiary.apib
index fb917bc..f11d612 100644
--- a/xos/tests/api/apiary.apib
+++ b/xos/tests/api/apiary.apib
@@ -3,6 +3,49 @@
 # XOS
  
  
+# Group Users
+
+List of the XOS users
+
+## Users [/api/core/users/]
+
+### List all Users [GET]
+
++ Response 200 (application/json)
+
+        [
+            {
+                "id": 2,
+                "password": "pbkdf2_sha256$12000$9gn8DmZuIoz2$YPQkx3AOOV7jZNYr2ddrgUCkiuaPpvb8+aJR7RwLZNA=",
+                "last_login": "2016-04-12T18:50:45.880823Z",
+                "email": "johndoe@myhouse.com",
+                "username": "johndoe@myhouse.com",
+                "firstname": "john",
+                "lastname": "doe",
+                "phone": null,
+                "user_url": null,
+                "site": "http://xos.dev:9999/api/core/sites/1/",
+                "public_key": null,
+                "is_active": true,
+                "is_admin": false,
+                "is_staff": true,
+                "is_readonly": false,
+                "is_registering": false,
+                "is_appuser": false,
+                "login_page": null,
+                "created": "2016-04-12T18:50:45.912602Z",
+                "updated": "2016-04-12T18:50:45.912671Z",
+                "enacted": null,
+                "policed": null,
+                "backend_status": "Provisioning in progress",
+                "deleted": false,
+                "write_protect": false,
+                "timezone": "America/New_York"
+            }
+        ]
+        
+ 
+ 
 # Group Example
 
 ## Example Services Collection [/api/service/exampleservice/]
@@ -22,6 +65,8 @@
  
 # Group ONOS Services
 
+List of the active onos services
+
 ## ONOS Services Collection [/api/service/onos/]
 
 ### List all ONOS Services [GET]
@@ -52,8 +97,6 @@
             {
                 "humanReadableName": "service_vsg",
                 "id": 2,
-                "wan_container_gateway_ip": "",
-                "wan_container_gateway_mac": "",
                 "dns_servers": "8.8.8.8",
                 "url_filter_kind": null,
                 "node_label": null
@@ -65,7 +108,7 @@
 
 Resource related to the CORD Subscribers.
 
-## Subscribers Collection [/api/tenant/cord/subscriber/]
+## Subscribers [/api/tenant/cord/subscriber/{subscriber_id}/]
 
 ### List All Subscribers [GET]
 
@@ -99,13 +142,12 @@
             }
         ]
 
-## Subscriber Detail [/api/tenant/cord/subscriber/{subscriber_id}/]
+
+### View a Subscriber Detail [GET]
 
 + Parameters
     + subscriber_id: 1 (number) - ID of the Subscriber in the form of an integer
 
-### View a Subscriber Detail [GET]
-
 + Response 200 (application/json)
  
         {
@@ -136,6 +178,9 @@
 
 ### Delete a Subscriber [DELETE]
 
++ Parameters
+    + subscriber_id: 1 (number) - ID of the Subscriber in the form of an integer
+
 + Response 204
 
 ### Subscriber features [/api/tenant/cord/subscriber/{subscriber_id}/features/]
@@ -295,7 +340,7 @@
 
 Virtual Truckroll, enable to perform basic test on user connectivity such as ping, traceroute and tcpdump.
 
-## Truckroll Collection [/api/tenant/truckroll/]
+## Truckroll Collection [/api/tenant/truckroll/{truckroll_id}/]
 
 ### List all Truckroll [GET]
 
@@ -319,6 +364,8 @@
 
 ### Create a Truckroll [POST]
 
+A virtual truckroll is complete once is_synced equal true
+
 + Request (application/json)
 
         {
@@ -344,15 +391,12 @@
             "backend_status": "0 - Provisioning in progress"
         }
 
-## Truckroll Detail [/api/tenant/truckroll/{truckroll_id}/]
 
-A virtual truckroll is complete once is_synced equal true
+### View a Truckroll Detail [GET]
 
 + Parameters
     + truckroll_id: 1 (number) - ID of the Truckroll in the form of an integer
 
-### View a Truckroll Detail [GET]
-
 + Response 200 (application/json)
 
         {
@@ -371,6 +415,9 @@
 
 ### Delete a Truckroll Detail [DELETE]
 
++ Parameters
+    + truckroll_id: 1 (number) - ID of the Truckroll in the form of an integer
+
 + Response 204
 
  
@@ -379,7 +426,7 @@
 
 OLT devices aggregate a set of subscriber connections
 
-## vOLT Collection [/api/tenant/cord/volt/]
+## vOLT Collection [/api/tenant/cord/volt/{volt_id}/]
 
 ### List all vOLT [GET]
 
@@ -431,15 +478,11 @@
                 }
             }
 
-## vOLT Detail [/api/tenant/cord/volt/{volt_id}/]
-
-A virtual volt is complete once is_synced equal true
+### View a vOLT Detail [GET]
 
 + Parameters
     + volt_id: 1 (number) - ID of the vOLT in the form of an integer
 
-### View a vOLT Detail [GET]
-
 + Response 200 (application/json)
 
         {
@@ -462,7 +505,7 @@
  
 # Group ONOS Apps
 
-## app Collection [/api/tenant/onos/app/]
+## ONOS App Collection [/api/tenant/onos/app/]
 
 ### List all apps [GET]
 
diff --git a/xos/tests/api/hooks.py b/xos/tests/api/hooks.py
index e327852..ccf0c6c 100644
--- a/xos/tests/api/hooks.py
+++ b/xos/tests/api/hooks.py
@@ -196,13 +196,13 @@
     setUpTruckroll()
 
 
-@hooks.before("Truckroll > Truckroll Detail > View a Truckroll Detail")
+@hooks.before("Truckroll > Truckroll Collection > View a Truckroll Detail")
 def test2(transaction):
     deleteTruckrolls()
     createTruckroll()
 
 
-@hooks.before("Truckroll > Truckroll Detail > Delete a Truckroll Detail")
+@hooks.before("Truckroll > Truckroll Collection > Delete a Truckroll Detail")
 def test3(transaction):
     deleteTruckrolls()
     createTruckroll()
diff --git a/xos/tests/api/source/core/users.md b/xos/tests/api/source/core/users.md
new file mode 100644
index 0000000..c5dcf68
--- /dev/null
+++ b/xos/tests/api/source/core/users.md
@@ -0,0 +1,41 @@
+# Group Users
+
+List of the XOS users
+
+## Users [/api/core/users/]
+
+### List all Users [GET]
+
++ Response 200 (application/json)
+
+        [
+            {
+                "id": 2,
+                "password": "pbkdf2_sha256$12000$9gn8DmZuIoz2$YPQkx3AOOV7jZNYr2ddrgUCkiuaPpvb8+aJR7RwLZNA=",
+                "last_login": "2016-04-12T18:50:45.880823Z",
+                "email": "johndoe@myhouse.com",
+                "username": "johndoe@myhouse.com",
+                "firstname": "john",
+                "lastname": "doe",
+                "phone": null,
+                "user_url": null,
+                "site": "http://xos.dev:9999/api/core/sites/1/",
+                "public_key": null,
+                "is_active": true,
+                "is_admin": false,
+                "is_staff": true,
+                "is_readonly": false,
+                "is_registering": false,
+                "is_appuser": false,
+                "login_page": null,
+                "created": "2016-04-12T18:50:45.912602Z",
+                "updated": "2016-04-12T18:50:45.912671Z",
+                "enacted": null,
+                "policed": null,
+                "backend_status": "Provisioning in progress",
+                "deleted": false,
+                "write_protect": false,
+                "timezone": "America/New_York"
+            }
+        ]
+        
\ No newline at end of file
diff --git a/xos/tests/api/source/service/onos.md b/xos/tests/api/source/service/onos.md
index 3b5e623..0b82a86 100644
--- a/xos/tests/api/source/service/onos.md
+++ b/xos/tests/api/source/service/onos.md
@@ -1,5 +1,7 @@
 # Group ONOS Services
 
+List of the active onos services
+
 ## ONOS Services Collection [/api/service/onos/]
 
 ### List all ONOS Services [GET]
diff --git a/xos/tests/api/source/service/vsg.md b/xos/tests/api/source/service/vsg.md
index 9247450..1a0569a 100644
--- a/xos/tests/api/source/service/vsg.md
+++ b/xos/tests/api/source/service/vsg.md
@@ -10,8 +10,6 @@
             {
                 "humanReadableName": "service_vsg",
                 "id": 2,
-                "wan_container_gateway_ip": "",
-                "wan_container_gateway_mac": "",
                 "dns_servers": "8.8.8.8",
                 "url_filter_kind": null,
                 "node_label": null
diff --git a/xos/tests/api/source/tenant/cord/subscribers.md b/xos/tests/api/source/tenant/cord/subscribers.md
index bd38d04..61126ce 100644
--- a/xos/tests/api/source/tenant/cord/subscribers.md
+++ b/xos/tests/api/source/tenant/cord/subscribers.md
@@ -2,7 +2,7 @@
 
 Resource related to the CORD Subscribers.
 
-## Subscribers Collection [/api/tenant/cord/subscriber/]
+## Subscribers [/api/tenant/cord/subscriber/{subscriber_id}/]
 
 ### List All Subscribers [GET]
 
@@ -36,13 +36,12 @@
             }
         ]
 
-## Subscriber Detail [/api/tenant/cord/subscriber/{subscriber_id}/]
+
+### View a Subscriber Detail [GET]
 
 + Parameters
     + subscriber_id: 1 (number) - ID of the Subscriber in the form of an integer
 
-### View a Subscriber Detail [GET]
-
 + Response 200 (application/json)
  
         {
@@ -73,6 +72,9 @@
 
 ### Delete a Subscriber [DELETE]
 
++ Parameters
+    + subscriber_id: 1 (number) - ID of the Subscriber in the form of an integer
+
 + Response 204
 
 ### Subscriber features [/api/tenant/cord/subscriber/{subscriber_id}/features/]
diff --git a/xos/tests/api/source/tenant/cord/truckroll.md b/xos/tests/api/source/tenant/cord/truckroll.md
index 33b67db..996c19c 100644
--- a/xos/tests/api/source/tenant/cord/truckroll.md
+++ b/xos/tests/api/source/tenant/cord/truckroll.md
@@ -2,7 +2,7 @@
 
 Virtual Truckroll, enable to perform basic test on user connectivity such as ping, traceroute and tcpdump.
 
-## Truckroll Collection [/api/tenant/truckroll/]
+## Truckroll Collection [/api/tenant/truckroll/{truckroll_id}/]
 
 ### List all Truckroll [GET]
 
@@ -26,6 +26,8 @@
 
 ### Create a Truckroll [POST]
 
+A virtual truckroll is complete once is_synced equal true
+
 + Request (application/json)
 
         {
@@ -51,15 +53,12 @@
             "backend_status": "0 - Provisioning in progress"
         }
 
-## Truckroll Detail [/api/tenant/truckroll/{truckroll_id}/]
 
-A virtual truckroll is complete once is_synced equal true
+### View a Truckroll Detail [GET]
 
 + Parameters
     + truckroll_id: 1 (number) - ID of the Truckroll in the form of an integer
 
-### View a Truckroll Detail [GET]
-
 + Response 200 (application/json)
 
         {
@@ -78,4 +77,7 @@
 
 ### Delete a Truckroll Detail [DELETE]
 
++ Parameters
+    + truckroll_id: 1 (number) - ID of the Truckroll in the form of an integer
+
 + Response 204
diff --git a/xos/tests/api/source/tenant/cord/volt.md b/xos/tests/api/source/tenant/cord/volt.md
index 09140fd..51cb679 100644
--- a/xos/tests/api/source/tenant/cord/volt.md
+++ b/xos/tests/api/source/tenant/cord/volt.md
@@ -2,7 +2,7 @@
 
 OLT devices aggregate a set of subscriber connections
 
-## vOLT Collection [/api/tenant/cord/volt/]
+## vOLT Collection [/api/tenant/cord/volt/{volt_id}/]
 
 ### List all vOLT [GET]
 
@@ -54,15 +54,11 @@
                 }
             }
 
-## vOLT Detail [/api/tenant/cord/volt/{volt_id}/]
-
-A virtual volt is complete once is_synced equal true
+### View a vOLT Detail [GET]
 
 + Parameters
     + volt_id: 1 (number) - ID of the vOLT in the form of an integer
 
-### View a vOLT Detail [GET]
-
 + Response 200 (application/json)
 
         {
diff --git a/xos/tests/api/source/tenant/onos/app.md b/xos/tests/api/source/tenant/onos/app.md
index a43aae9..5376c33 100644
--- a/xos/tests/api/source/tenant/onos/app.md
+++ b/xos/tests/api/source/tenant/onos/app.md
@@ -1,6 +1,6 @@
 # Group ONOS Apps
 
-## app Collection [/api/tenant/onos/app/]
+## ONOS App Collection [/api/tenant/onos/app/]
 
 ### List all apps [GET]
 
diff --git a/xos/tools/xos-manage b/xos/tools/xos-manage
index 0df23a0..172bbd7 100755
--- a/xos/tools/xos-manage
+++ b/xos/tools/xos-manage
@@ -147,6 +147,7 @@
     python ./manage.py makemigrations onos
     python ./manage.py makemigrations vtr
     python ./manage.py makemigrations vrouter
+    python ./manage.py makemigrations vtn
     #python ./manage.py makemigrations servcomp
 }
 
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index fd4f8ec..9bd504a 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -221,15 +221,6 @@
                 type: string
                 required: false
                 description: Label that matches network used to connect HPC and BBS services.
-            wan_container_gateway_ip:
-                type: string
-                required: false
-            wan_container_gateway_mac:
-                type: string
-                required: false
-            wan_container_netbits:
-                type: string
-                required: false
             dns_servers:
                 type: string
                 required: false
@@ -261,6 +252,37 @@
             xos_base_props
             xos_base_service_props
 
+    tosca.nodes.VTNService:
+        derived_from: tosca.nodes.Root
+        description: >
+            CORD: The vRouter Service.
+        capabilities:
+            xos_base_service_caps
+        properties:
+            xos_base_props
+            xos_base_service_props
+            privateGatewayMac:
+                type: string
+                required: false
+            localManagementIp:
+                type: string
+                required: false
+            ovsdbPort:
+                type: string
+                required: false
+            sshPort:
+                type: string
+                required: false
+            sshUser:
+                type: string
+                required: false
+            sshKeyFile:
+                type: string
+                required: false
+            mgmtSubnetBits:
+                type: string
+                required: false
+
     tosca.nodes.CDNService:
         derived_from: tosca.nodes.Root
         description: >
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 9bdcfc3..f790cc5 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -323,15 +323,6 @@
                 type: string
                 required: false
                 description: Label that matches network used to connect HPC and BBS services.
-            wan_container_gateway_ip:
-                type: string
-                required: false
-            wan_container_gateway_mac:
-                type: string
-                required: false
-            wan_container_netbits:
-                type: string
-                required: false
             dns_servers:
                 type: string
                 required: false
@@ -451,6 +442,81 @@
                 required: false
                 description: Version number of Service.
 
+    tosca.nodes.VTNService:
+        derived_from: tosca.nodes.Root
+        description: >
+            CORD: The vRouter 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
+            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.
+            privateGatewayMac:
+                type: string
+                required: false
+            localManagementIp:
+                type: string
+                required: false
+            ovsdbPort:
+                type: string
+                required: false
+            sshPort:
+                type: string
+                required: false
+            sshUser:
+                type: string
+                required: false
+            sshKeyFile:
+                type: string
+                required: false
+            mgmtSubnetBits:
+                type: string
+                required: false
+
     tosca.nodes.CDNService:
         derived_from: tosca.nodes.Root
         description: >
diff --git a/xos/tosca/resources/vcpeservice.py b/xos/tosca/resources/vcpeservice.py
index 2a6a56d..972c13c 100644
--- a/xos/tosca/resources/vcpeservice.py
+++ b/xos/tosca/resources/vcpeservice.py
@@ -14,6 +14,5 @@
     xos_model = VSGService
     copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key",
                     "private_key_fn", "versionNumber", "backend_network_label",
-                    "wan_container_gateway_ip", "wan_container_gateway_mac",
-                    "wan_container_netbits", "dns_servers", "node_label"]
+                    "dns_servers", "node_label"]
 
diff --git a/xos/tosca/resources/vtnservice.py b/xos/tosca/resources/vtnservice.py
new file mode 100644
index 0000000..f0940d6
--- /dev/null
+++ b/xos/tosca/resources/vtnservice.py
@@ -0,0 +1,16 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from services.vtn.models import VTNService
+
+from service import XOSService
+
+class XOSVTNService(XOSService):
+    provides = "tosca.nodes.VTNService"
+    xos_model = VTNService
+    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits']
+
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index d48f531..f73e383 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -181,6 +181,7 @@
     'services.syndicate_storage',
     'services.vtr',
     'services.vrouter',
+    'services.vtn',
     'geoposition',
     'rest_framework_swagger',
 )
diff --git a/xos/xos/xml_util.py b/xos/xos/xml_util.py
index d3aefb1..77b968f 100644
--- a/xos/xos/xml_util.py
+++ b/xos/xos/xml_util.py
@@ -113,8 +113,8 @@
         specified root_node if specified, otherwise start at tree's root.
         """
 
-        if not element_name.startswith('//'):
-            element_name = '//' + element_name
+        if not name.startswith('//'):
+            name = '//' + name 
         elements = self.element.xpath('%s ' % name, namespaces=self.namespaces)
         for element in elements:
             parent = element.getparent()
