Merge ~steverydz/maas:compose-machine-validation into maas:master

Proposed by Steve Rydz
Status: Merged
Approved by: Steve Rydz
Approved revision: f11399726d29af5b3b68926361a529801dd21056
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~steverydz/maas:compose-machine-validation
Merge into: maas:master
Diff against target: 95 lines (+23/-10)
2 files modified
src/maasserver/static/js/angular/controllers/pod_details.js (+17/-9)
src/maasserver/static/partials/pod-details.html (+6/-1)
Reviewer Review Type Date Requested Status
Caleb Ellis (community) Approve
Review via email: mp+367057@code.launchpad.net

Commit message

LP: #1823265 - Disable compose button if hostname contains underscore

Description of the change

Done
- Disabled "Compose" button if "Host name" contains an underscore
- Some minor eslint fixes

QA steps:
- Go to a POD detail page
- Select "Compose" from the "Take action" button
- Type in a "Host name" with an underscore in it
- See that the "Compose" button is disabled
- Remove the underscore from the "Host name"
- See that the "Compose" button is now enabled

To post a comment you must log in.
Revision history for this message
Caleb Ellis (caleb-ellis) wrote :

LGTM!

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/static/js/angular/controllers/pod_details.js b/src/maasserver/static/js/angular/controllers/pod_details.js
2index aeaa539..8a32b8e 100644
3--- a/src/maasserver/static/js/angular/controllers/pod_details.js
4+++ b/src/maasserver/static/js/angular/controllers/pod_details.js
5@@ -24,7 +24,9 @@ function PodDetailsController(
6 VLANsManager,
7 FabricsManager,
8 SpacesManager,
9- ValidationService
10+ ValidationService,
11+ $log,
12+ $document
13 ) {
14 // Set title and page.
15 $rootScope.title = "Loading...";
16@@ -190,11 +192,11 @@ function PodDetailsController(
17 // Update the pod with new data on the region.
18 $scope.updatePod = function(pod) {
19 return $scope.podManager.updateItem(pod).then(
20- function(pod) {
21+ function() {
22 updateName();
23 },
24 function(error) {
25- console.log(error);
26+ $log.error(error);
27 updateName();
28 }
29 );
30@@ -252,6 +254,12 @@ function PodDetailsController(
31 var requests = $scope.compose.obj.requests;
32 var valid = true;
33
34+ var hostname = $scope.compose.obj.hostname;
35+
36+ if (hostname && hostname.includes("_")) {
37+ return false;
38+ }
39+
40 requests.forEach(function(request) {
41 if (request.size > request.available || request.size === "") {
42 valid = false;
43@@ -458,12 +466,12 @@ function PodDetailsController(
44 $scope.copyToClipboard = function($event) {
45 var clipboardParent = $event.currentTarget.previousSibling;
46 var clipboardValue = clipboardParent.previousSibling.value;
47- var el = document.createElement("textarea");
48+ var el = $document.createElement("textarea");
49 el.value = clipboardValue;
50- document.body.appendChild(el);
51+ $document.body.appendChild(el);
52 el.select();
53- document.execCommand("copy");
54- document.body.removeChild(el);
55+ $document.execCommand("copy");
56+ $document.body.removeChild(el);
57 };
58
59 // Called to cancel composition.
60@@ -594,7 +602,7 @@ function PodDetailsController(
61
62 $scope.selectSubnetByIP = function(iface) {
63 if (iface.ipaddress) {
64- angular.forEach($scope.availableSubnets, function(subnet, idx) {
65+ angular.forEach($scope.availableSubnets, function(subnet) {
66 let inNetwork = ValidationService.validateIPInNetwork(
67 iface.ipaddress,
68 subnet.cidr
69@@ -654,7 +662,7 @@ function PodDetailsController(
70 // Start watching key fields.
71 $scope.startWatching = function() {
72 $scope.$watch("subnets", function() {
73- angular.forEach($scope.subnets, function(subnet, idx) {
74+ angular.forEach($scope.subnets, function(subnet) {
75 // filter subnets from vlans not attached to host
76 if ($scope.pod.attached_vlans.includes(subnet.vlan)) {
77 $scope.availableSubnets.push(_getSubnetDetails(subnet));
78diff --git a/src/maasserver/static/partials/pod-details.html b/src/maasserver/static/partials/pod-details.html
79index bcfc763..bb34204 100644
80--- a/src/maasserver/static/partials/pod-details.html
81+++ b/src/maasserver/static/partials/pod-details.html
82@@ -47,7 +47,12 @@
83 </div>
84 <div class="row">
85 <div class="col-6">
86- <maas-obj-field type="text" key="hostname" label="Hostname" subtle="false" placeholder="Hostname (optional)" label-width="2" label-width-tablet="2" input-width="3" input-width-tablet="4"></maas-obj-field>
87+ <div class="p-form__group">
88+ <label for="hostname" class="p-form__label col-2 tablet-col-2">Hostname</label>
89+ <div class="p-form__control col-3 tablet-col-4">
90+ <input type="text" name="hostname" id="hostname" data-ng-model="compose.obj.hostname" placeholder="Hostname (optional)">
91+ </div>
92+ </div>
93 <maas-obj-field type="options" key="domain" label="Domain" subtle="false" placeholder="Choose a domain"
94 options="domain.id as domain.name for domain in domains" label-width="2" label-width-tablet="2" input-width="3" input-width-tablet="4"></maas-obj-field>
95 <maas-obj-field type="options" key="zone"

Subscribers

People subscribed via source and target branches