Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created January 8, 2016 21:16
Show Gist options
  • Save eriknelson/c7bc6070484e8e8229b4 to your computer and use it in GitHub Desktop.
Save eriknelson/c7bc6070484e8e8229b4 to your computer and use it in GitHub Desktop.
diff --git a/fusor-ember-cli/app/controllers/openstack/overcloud.js b/fusor-ember-cli/app/controllers/openstack/overcloud.js
index 271bab8..3156b29 100644
--- a/fusor-ember-cli/app/controllers/openstack/overcloud.js
+++ b/fusor-ember-cli/app/controllers/openstack/overcloud.js
@@ -1,9 +1,13 @@
import Ember from 'ember';
+import EmberValidations, { validator } from 'ember-validations'
import DeploymentControllerMixin from "../../mixins/deployment-controller-mixin";
import NeedsDeploymentMixin from "../../mixins/needs-deployment-mixin";
-export default Ember.Controller.extend(DeploymentControllerMixin, NeedsDeploymentMixin, {
-
+let OvercloudController = Ember.Controller.extend(
+ DeploymentControllerMixin,
+ NeedsDeploymentMixin,
+ EmberValidations,
+{
isCloudForms: Ember.computed.alias("deploymentController.isCloudForms"),
nextStepRouteNameOvercloud: Ember.computed('isCloudForms', function() {
@@ -14,16 +18,6 @@ export default Ember.Controller.extend(DeploymentControllerMixin, NeedsDeploymen
}
}),
- isValidPrivateNetworkRange: Ember.computed('model.deployment.openstack_overcloud_private_net', function() {
- // TODO
- return true;
- }),
-
- isValidPrivateFloatRange: Ember.computed('model.deployment.openstack_overcloud_float_net', function() {
- // TODO
- return true;
- }),
-
isValidOvercloudPassword: Ember.computed('overcloudPassword', 'confirmOvercloudPassword', function () {
return Ember.isPresent(this.get('overcloudPassword')) &&
this.get('overcloudPassword') === this.get('confirmOvercloudPassword');
@@ -47,8 +41,63 @@ export default Ember.Controller.extend(DeploymentControllerMixin, NeedsDeploymen
);
}),
- disableNextOvercloud: Ember.computed.not('validOvercloudNetworks'),
+ disableNextOvercloud: Ember.computed.not('fullyValidated'),
overcloudPassword: Ember.computed.alias("deploymentController.model.openstack_overcloud_password"),
- confirmOvercloudPassword: Ember.computed.alias("deploymentController.confirmOvercloudPassword")
+ confirmOvercloudPassword: Ember.computed.alias("deploymentController.confirmOvercloudPassword"),
+
+////////////////////////////////////////////////////////////
+// Validation aliases and logic
+// TODO: isValidOvercloudNetworks should be migrated to use ember-validations.
+// For now, fullyValidated glues together the previous validations with
+// ember-validations proof of concept on the range/cidr notation.
+////////////////////////////////////////////////////////////
+
+ fullyValidated: Ember.computed(
+ 'validOvercloudNetworks',
+ 'isValid',
+ function() {
+ let fullyValid = this.get('validOvercloudNetworks') && this.get('isValid');
+ return fullyValid;
+ }
+ ),
+
+ validations: {
+ 'deploymentAlias.openstack_overcloud_private_net': {
+ inline: validator(function() {
+ let privateNet = this.model.get('deploymentAlias.openstack_overcloud_private_net');
+ let invalidRangeAndFormat = !validateIpRangeAndFormat(privateNet);
+ if(invalidRangeAndFormat) {
+ return 'Private network is invalid range or format.';
+ }
+ })
+ },
+ 'deploymentAlias.openstack_overcloud_float_net': {
+ inline: validator(function() {
+ let floatnet = this.model.get('deploymentAlias.openstack_overcloud_float_net');
+ let invalidRangeAndFormat = !validateIpRangeAndFormat(floatnet);
+ if(invalidRangeAndFormat) {
+ return 'Floating ip network is invalid range or format.';
+ }
+ })
+ }
+ }
});
+
+function validateIpRangeAndFormat(testString) {
+ // Create new regex from multiple line string, zipped up w/join
+ // No regex flags: RegExp(string, flags)
+ // NOTE: Regex backslashes must be escaped since this is not a literal regex!
+ // No regex subgroupings js?
+ let validationRegex = new RegExp([
+ '\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',
+ '\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',
+ '\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',
+ '\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',
+ '\\/(3[0-2]|[1-2]?[0-9])\\b'
+ ].join(''), '');
+
+ return validationRegex.test(testString);
+}
+
+export default OvercloudController;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment