Browse Source

Template Generator: Add support for OS::Designate::Zone

Add support for OS::Designate::Zone as a new resource,
which you can use from Template Generator.

Change-Id: Ie98b2d7b5b6446cb527af14e0e417cca023a79a8
Task: #19673
Story: #2002032
JiyeYu 10 months ago
parent
commit
a2df0bbcca

+ 1
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js View File

@@ -31,6 +31,7 @@
31 31
             'uuid_nohyphen': /^[a-f0-9]{32}$/,
32 32
             'mac_address': /^([A-Fa-f0-9]{2}[:-]){5}([A-Fa-f0-9]{2})$/,
33 33
             'cidr': /^(([0-9.]{1,15})(\/([0-9]|[1-2][0-9]|3[0-2]))?)|(([A-Fa-f0-9:]{1,39})(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?)$/,
34
+            'zone': /^[a-zA-Z0-9_.-]{1,127}\.$/,
34 35
         })
35 36
         ;
36 37
 

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone-blue.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="55" height="55" preserveAspectRatio="xMidYMid meet" style="background-color: #FFFFFF;" viewBox="0 0 55 55">
2
+<g class="currentLayer" style=""><title>Layer 1</title><circle class="frame" r="25" style="fill:white;fill-opacity=0.0;stroke-width:3;stroke: #3f51b5" cy="27.395854949951172" cx="28.040435791015625" id="svg_2"/><g transform="translate(0,300) scale(0.10000000149011612,-0.10000000149011612) " fill="#000" stroke="none" id="svg_1" class="selected">
3
+</g></g><g class="currentLayer" style=""><title>Layer 1</title><text x="15.098859399557114" y="24.90114063024521" style="fill: #3f51b5; stroke: #3f51b5; font-size: 12px;font-family:Helvetica;" id="svg_1" class="">DNS</text><text x="15.351358662724476" y="41.57414920051434" style="fill: #3f51b5; stroke: #3f51b5; font-size: 10px;font-family:Helvetica; " id="svg_2" class="" transform="matrix(1.0821652412414549,0,0,1.0666701793670652,-3.13361918926239,-5.300277292728424) ">ZONE</text></g></svg>

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone-gray.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="55" height="55" preserveAspectRatio="xMidYMid meet" style="background-color: #FFFFFF;" viewBox="0 0 55 55">
2
+<g class="currentLayer" style=""><title>Layer 1</title><circle class="frame" r="25" style="fill:white;fill-opacity=0.0;stroke-width:3;stroke:gray" cy="27.395854949951172" cx="28.040435791015625" id="svg_2"/><g transform="translate(0,300) scale(0.10000000149011612,-0.10000000149011612) " fill="#000" stroke="none" id="svg_1" class="selected">
3
+</g></g><g class="currentLayer" style=""><title>Layer 1</title><text x="15.098859399557114" y="24.90114063024521" style="fill: #808080; stroke: #808080; font-size: 12px;font-family:Helvetica;" id="svg_1" class="">DNS</text><text x="15.351358662724476" y="41.57414920051434" style="fill: #808080; stroke: #808080; font-size: 10px;font-family:Helvetica; " id="svg_2" class="" transform="matrix(1.0821652412414549,0,0,1.0666701793670652,-3.13361918926239,-5.300277292728424) ">ZONE</text></g></svg>

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone-green.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="55" height="55" preserveAspectRatio="xMidYMid meet" style="background-color: #FFFFFF;" viewBox="0 0 55 55">
2
+<g class="currentLayer" style=""><title>Layer 1</title><circle class="frame" r="25" style="fill:white;fill-opacity=0.0;stroke-width:3;stroke:green" cy="27.395854949951172" cx="28.040435791015625" id="svg_2"/><g transform="translate(0,300) scale(0.10000000149011612,-0.10000000149011612) " fill="#000" stroke="none" id="svg_1" class="selected">
3
+</g></g><g class="currentLayer" style=""><title>Layer 1</title><text x="15.098859399557114" y="24.90114063024521" style="fill: green; stroke: green; font-size: 12px;font-family:Helvetica;" id="svg_1" class="">DNS</text><text x="15.351358662724476" y="41.57414920051434" style="fill: green; stroke: green; font-size: 10px;font-family:Helvetica; " id="svg_2" class="" transform="matrix(1.0821652412414549,0,0,1.0666701793670652,-3.13361918926239,-5.300277292728424) ">ZONE</text></g></svg>

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone-red.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="55" height="55" preserveAspectRatio="xMidYMid meet" style="background-color: #FFFFFF;" viewBox="0 0 55 55">
2
+<g class="currentLayer" style=""><title>Layer 1</title><circle class="frame" r="25" style="fill:white;fill-opacity=0.0;stroke-width:3;stroke: #C82128" cy="27.395854949951172" cx="28.040435791015625" id="svg_2"/><g transform="translate(0,300) scale(0.10000000149011612,-0.10000000149011612) " fill="#000" stroke="none" id="svg_1" class="selected">
3
+</g></g><g class="currentLayer" style=""><title>Layer 1</title><text x="15.098859399557114" y="24.90114063024521" style="fill: #C82128; stroke: #C82128; font-size: 12px;font-family:Helvetica;" id="svg_1" class="">DNS</text><text x="15.351358662724476" y="41.57414920051434" style="fill: #C82128; stroke: #C82128; font-size: 10px;font-family:Helvetica; " id="svg_2" class="" transform="matrix(1.0821652412414549,0,0,1.0666701793670652,-3.13361918926239,-5.300277292728424) ">ZONE</text></g></svg>

+ 71
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone.html View File

@@ -0,0 +1,71 @@
1
+<md-tabs md-dynamic-height md-stretch-tabs="always" md-border-bottom>
2
+    <md-tab label="Properties" >
3
+        <md-content layout-padding>
4
+            <md-input-container class="md-block">
5
+                <label>Name</label>
6
+                <input ng-model="$ctrl.zone.name" name="name" type="text" required ng-pattern="validate_zone" md-maxlength="255">
7
+                <div ng-messages="$ctrl.formReference.name.$error" role="alert" multiple>
8
+                    <div ng-message="required" class="my-message">You must supply a name.</div>
9
+                    <div ng-message="pattern" class="my-message">That doesn't look like a valid name.
10
+                    </div>
11
+                    <div ng-message="md-maxlength" class="my-message">
12
+                      Too long name.
13
+                    </div>
14
+                </div>
15
+            </md-input-container>
16
+            <md-input-container class="md-block">
17
+                <label>Email</label>
18
+                <input ng-model="$ctrl.zone.email" name="email" type="text" required>
19
+                <div ng-messages="$ctrl.formReference.email.$error" role="alert" multiple>
20
+                    <div ng-message="required" class="my-message">You must supply an email.</div>
21
+                </div>
22
+            </md-input-container>
23
+            <md-input-container class="md-block">
24
+                <label>TTL</label>
25
+                <input ng-model="$ctrl.zone.ttl" name="ttl" type="number">
26
+            </md-input-container>
27
+            <md-input-container class="md-block">
28
+                <label>Description</label>
29
+                <input ng-model="$ctrl.zone.description" name="description" type="text" md-maxlength="255">
30
+                <div ng-messages="$ctrl.formReference.description.$error" role="alert" multiple>
31
+                    <div ng-message="md-maxlength" class="my-message">
32
+                      Too long description.
33
+                    </div>
34
+                </div>
35
+            </md-input-container>
36
+        </md-content>
37
+
38
+        <md-switch class="md-primary" name="show_more" ng-model="show_more">
39
+          {$ 'Show More Properties' | translate $}
40
+        </md-switch>
41
+    </md-tab>
42
+
43
+    <md-tab label="More Properties" ng-if="show_more">
44
+        <md-content layout-padding>
45
+            <md-input-container class="md-block" flex-gt-xs>
46
+                <label>Type</label>
47
+                <md-select ng-model="$ctrl.zone.type">
48
+                    <md-option ng-repeat="type in options.types" ng-value="type.id">
49
+                        {$ type.name $}
50
+                    </md-option>
51
+                </md-select>
52
+            </md-input-container>
53
+            <md-input-container class="md-block" flex-gt-xs>
54
+                <label>Masters</label>
55
+                <md-chips ng-model="$ctrl.zone.masters"
56
+                          placeholder="+ master"
57
+                          readonly="false"
58
+                          md-removeable="true"
59
+                          md-transform-chip="validate_master($chip)">
60
+                </md-chips>
61
+            </md-input-container>
62
+
63
+        </md-content>
64
+    </md-tab>
65
+
66
+    <md-tab label="Depends on">
67
+        <md-content layout-padding>
68
+            <depends-on dependson='dependson'></depends-on>
69
+        </md-content>
70
+    </md-tab>
71
+</md-tabs>

+ 94
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone.js View File

@@ -0,0 +1,94 @@
1
+(function(angular) {
2
+    'use strict';
3
+
4
+    // OS::Designate::Zone
5
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator').value('osDesignateZoneSettings',
6
+        {
7
+            resource_key: "OS__Designate__Zone",
8
+            admin: false,
9
+            icon: {
10
+                class: 'fa-key ',
11
+                name: 'OS::Designate::Zone',
12
+                code: '\uf084',
13
+                color: '#483dff'
14
+            },
15
+            label: 'name',
16
+            modal_component: '<os-designate-zone zone="resource" dependson="dependson" form-reference="resourceForm"></os-designate-zone>',
17
+            edge_settings: null,
18
+            necessary_properties: {
19
+                'name': null,
20
+                'email': null
21
+            },
22
+        }
23
+    );
24
+
25
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator')
26
+    .run(['osDesignateZoneSettings', 'hotgenGlobals', function( osDesignateZoneSettings, hotgenGlobals){
27
+        hotgenGlobals.update_resource_icons(
28
+            osDesignateZoneSettings.resource_key,
29
+            osDesignateZoneSettings.icon);
30
+
31
+        hotgenGlobals.update_resource_components(
32
+            osDesignateZoneSettings.resource_key,
33
+            osDesignateZoneSettings.modal_component);
34
+
35
+        hotgenGlobals.update_edge_directions(
36
+            osDesignateZoneSettings.resource_key,
37
+            osDesignateZoneSettings.edge_settings);
38
+
39
+        hotgenGlobals.update_node_labels(
40
+            osDesignateZoneSettings.resource_key,
41
+            osDesignateZoneSettings.label);
42
+    }]);
43
+
44
+
45
+    function osDesignateZoneController($scope, hotgenGlobals, hotgenNotify, validationRules){
46
+        $scope.options = hotgenGlobals.get_resource_options();
47
+
48
+        $scope.options.types = [
49
+            {'id': 'PRIMARY', 'name': 'PRIMARY'},
50
+            {'id': 'SECONDARY', 'name': 'SECONDARY'}
51
+        ];
52
+
53
+        $scope.admin = $scope.options.auth.admin;
54
+        this.$onInit = function(){
55
+            if (typeof this.zone.masters === 'undefined'){
56
+                this.zone.masters = [];
57
+            }
58
+            $scope.dependson = this.dependson;
59
+        }
60
+
61
+        $scope.validate_zone = validationRules['zone'];
62
+
63
+        $scope.validate_master = function (input_string){
64
+            var re =  /^[A-Za-z0-9_.-]+$/;
65
+            var match = re.exec(input_string);
66
+            if (match){
67
+                return input_string;
68
+            } else{
69
+                hotgenNotify.show_error('Invalid master value.');
70
+                return null;
71
+            }
72
+        }
73
+    }
74
+
75
+    osDesignateZoneController.$inject = ['$scope', 'hotgenGlobals', 'hotgenNotify',
76
+        'horizon.dashboard.project.heat_dashboard.template_generator.validationRules',
77
+    ];
78
+    osDesignateZonePath.$inject = ['horizon.dashboard.project.heat_dashboard.template_generator.basePath'];
79
+
80
+    function osDesignateZonePath(basePath){
81
+        return basePath + 'js/resources/os__designate__zone/os__designate__zone.html';
82
+    }
83
+
84
+    angular.module('horizon.dashboard.project.heat_dashboard.template_generator').component('osDesignateZone', {
85
+        templateUrl: osDesignateZonePath,
86
+        controller: osDesignateZoneController,
87
+        bindings:{
88
+            'zone': '=',
89
+            'dependson': '=',
90
+            'formReference': '<',
91
+        }
92
+    });
93
+
94
+})(window.angular);

+ 54
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone.spec.js View File

@@ -0,0 +1,54 @@
1
+(function() {
2
+    'use strict';
3
+
4
+    describe('component os-designate-zone', function(){
5
+
6
+        beforeEach(module('horizon.dashboard.project.heat_dashboard.template_generator'));
7
+
8
+        beforeEach(module('appTemplates'));
9
+
10
+        var $scope, $isolateScope, $compile;
11
+        var element;
12
+
13
+        beforeEach(inject(function($injector) {
14
+            $scope = $injector.get('$rootScope').$new();
15
+            $compile = $injector.get('$compile');
16
+
17
+            $scope.resource = {};
18
+            $scope.dependson = [];
19
+            $scope.resourceForm = {};
20
+
21
+            // element will enable you to test your directive's element on the DOM
22
+            element = $compile(angular.element('<os-designate-zone zone="resource" '+
23
+                    'dependson="dependson" form-reference="resourceForm">'+
24
+                    '</os-designate-zone>'))($scope);
25
+
26
+            // Digest needs to be called to set any values on the directive's scope
27
+            $scope.$digest();
28
+
29
+            $isolateScope = element.isolateScope();
30
+        }));
31
+
32
+        it('find tab title Properties',  function() {
33
+            expect(element.find('span').html()).toContain("Properties");
34
+        });
35
+
36
+        it('find tab title Properties with resource properties set',  function() {
37
+            $scope.resource = { masters: [], attributes: []};
38
+            element = $compile(angular.element('<os-designate-zone zone="resource" '+
39
+                    'dependson="dependson" form-reference="resourceForm">'+
40
+                    '</os-designate-zone>'))($scope);
41
+
42
+            $scope.$digest();
43
+
44
+            expect(element.find('span').html()).toContain("Properties");
45
+        });
46
+
47
+        it('test validate master function', function() {
48
+            expect($isolateScope.validate_master('192.168.1.1')).toEqual('192.168.1.1');
49
+            expect($isolateScope.validate_master('localhost')).toEqual('localhost');
50
+            expect($isolateScope.validate_master('xxx@gmail.com')).toEqual(null);
51
+        });
52
+    });
53
+
54
+})();

+ 3
- 0
heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__designate__zone/os__designate__zone.svg View File

@@ -0,0 +1,3 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="55" height="55" preserveAspectRatio="xMidYMid meet" style="background-color: #FFFFFF;" viewBox="0 0 55 55">
2
+<g class="currentLayer" style=""><title>Layer 1</title><circle class="frame" r="25" style="fill:white;fill-opacity=0.0;stroke-width:3;stroke:black" cy="27.395854949951172" cx="28.040435791015625" id="svg_2"/><g transform="translate(0,300) scale(0.10000000149011612,-0.10000000149011612) " fill="#000" stroke="none" id="svg_1" class="selected">
3
+</g></g><g class="currentLayer" style=""><title>Layer 1</title><text x="15.098859399557114" y="24.90114063024521" style="fill: #000000; stroke: #000; font-size: 12px;font-family:Helvetica;" id="svg_1" class="">DNS</text><text x="15.351358662724476" y="41.57414920051434" style="fill: #000000; stroke: #000; font-size: 10px;font-family:Helvetica; " id="svg_2" class="" transform="matrix(1.0821652412414549,0,0,1.0666701793670652,-3.13361918926239,-5.300277292728424) ">ZONE</text></g></svg>

Loading…
Cancel
Save