<commit_before>// Copyright 2014 CloudFounders NV
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*global define */
define([
    'jquery', 'knockout',
    'ovs/api', 'ovs/generic', 'ovs/shared', 'ovs/refresher',
    '../../containers/volumestoragerouter', './data'
], function($, ko, api, generic, shared, Refresher, VolumeStorageRouter, data) {
    "use strict";
    return function(parent) {
        var self = this;

        // Variables
        self.shared     = shared;
        self.vSRLoading = $.Deferred();
        self.refresher  = new Refresher();

        // Observables
        self.vsr = ko.observable();

        // Objects
        self.RemoveValidation = function(vsrGuid) {
            var self = this;

            // Variables
            self.vsrGuid = vsrGuid;

            // Observables
            self.loaded = ko.observable(false);
            self.inUse  = ko.observable(false);

            // Computed
            self.validationState = ko.computed(function() {
                var valid = true, reasons = [];
                if (self.loaded() === false) {
                    valid = undefined;
                } else if (self.loaded() === undefined) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.errorvalidating'));
                } else if (self.inUse() === false) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.inuse'));
                }
                return { valid: valid, reasons: reasons, fields: [] };
            });

            // Functions
            self.validate = function() {
                api.post('volumestoragerouters/' + self.vsrGuid + '/can_be_deleted')
                    .done(function(data) {
                        self.loaded(true);
                        self.inUse(data);
                    })
                    .fail(function() {
                        self.loaded(undefined);
                    });
            };
        };
        self.AddValidation = function(vsr, vsa, vsrDeferred, data) {
            var self = this;

            // Variables
            self.vsa         = vsa;
            self.vsr         = vsr;
            self.shared      = shared;
            self.vsrDeferred = vsrDeferred;
            self.data        = data;

            // Observables
            self.loaded      = ko.observable(false);
            self.vRouterPort = ko.observable();
            self.files       = ko.observable();
            self.vsrs        = ko.observableArray([]);
            self.mountpoints = ko.observableArray([]);
            self.ipAddresses = ko.observableArray([]);

            // Computed
            self.validationState = ko.computed(function() {
                var valid = true, reasons = [], fields = [];
                if (self.loaded() === false) {
                    valid = undefined;
                } else if (self.loaded() === undefined) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.errorvalidating'));
                } else {
                    $.each(self.vsrs(), function(index, vsr) {
                        if (self.vsr().mountpointCache() === vsr.mountpointCache() && $.inArray('cache', fields) === -1) {
                            valid = false;
                            fields.push('cache');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.cachefs') }));
                        }
                        if (self.vsr().mountpointDFS() === vsr.mountpointDFS() && $.inArray('dfs', fields) === -1) {
                            valid = false;
                            fields.push('dfs');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.dfs') }));
                        }
                        if (self.vsr().mountpointMD() === vsr.mountpointMD() && $.inArray('md', fields) === -1) {
                            valid = false;
                            fields.push('md');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.mdfs') }));
                        }
                        if (self.vsr().mountpointTemp() === vsr.mountpointTemp() && $.inArray('temp', fields) === -1) {
                            valid = false;
                            fields.push('temp');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.tempfs') }));
                        }
                        if (self.vsr().port() === vsr.port() && $.inArray('port', fields) === -1) {
                            valid = false;
                            fields.push('port');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.portinuse'));
                        }
                        return true;
                    });
                    if ($.inArray(self.vsr().storageIP(), self.ipAddresses()) === -1 && $.inArray('ip', fields) === -1) {
                        valid = false;
                        fields.push('ip');
                        reasons.push($.t('ovs:wizards.vsatovpool.confirm.ipnotavailable', { what: self.vsr().storageIP() }));
                    }
                    if (self.data.vPool().backendType() === 'CEPH_S3' && self.files() !== undefined && (
                            (self.files().hasOwnProperty('/etc/ceph/ceph.conf') && !self.files()['/etc/ceph/ceph.conf']) ||
                            (self.files().hasOwnProperty('/etc/ceph/ceph.keyring') && !self.files()['/etc/ceph/ceph.keyring']))) {
                        valid = false;
                        fields.push('ceph_files');
                        reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.cephfilesmissing'));
                    }
                }
                return { valid: valid, reasons: reasons, fields: fields };
            });

            // Functions
            self.validate = function() {
                var calls = [
                    $.Deferred(function(physicalDeferred) {
                        var post_data = {};
                        if (self.data.vPool().backendType() === 'CEPH_S3') {
                            post_data.files = '/etc/ceph/ceph.conf,/etc/ceph/ceph.keyring';
                        }
                        api.post('vmachines/' + self.vsa.guid() + '/get_physical_metadata', post_data)
                            .then(self.shared.tasks.wait)
                            .then(function(data) {
                                self.mountpoints(data.mountpoints);
                                self.ipAddresses(data.ipaddresses);
                                self.vRouterPort(data.xmlrpcport);
                                self.files(data.files);
                            })
                            .done(physicalDeferred.resolve)
                            .fail(physicalDeferred.reject);
                    }).promise(),
                    self.vsrDeferred.promise()
                ];
                generic.crossFiller(
                    self.vsa.servedVSRGuids, self.vsrs,<commit_msg>OVS-751 - Ignore missing ceph configuration on subsequent nodes, since the ceph files are copied by manager.py<commit_after>// Copyright 2014 CloudFounders NV
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*global define */
define([
    'jquery', 'knockout',
    'ovs/api', 'ovs/generic', 'ovs/shared', 'ovs/refresher',
    '../../containers/volumestoragerouter', './data'
], function($, ko, api, generic, shared, Refresher, VolumeStorageRouter, data) {
    "use strict";
    return function(parent) {
        var self = this;

        // Variables
        self.shared     = shared;
        self.vSRLoading = $.Deferred();
        self.refresher  = new Refresher();

        // Observables
        self.vsr = ko.observable();

        // Objects
        self.RemoveValidation = function(vsrGuid) {
            var self = this;

            // Variables
            self.vsrGuid = vsrGuid;

            // Observables
            self.loaded = ko.observable(false);
            self.inUse  = ko.observable(false);

            // Computed
            self.validationState = ko.computed(function() {
                var valid = true, reasons = [];
                if (self.loaded() === false) {
                    valid = undefined;
                } else if (self.loaded() === undefined) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.errorvalidating'));
                } else if (self.inUse() === false) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.inuse'));
                }
                return { valid: valid, reasons: reasons, fields: [] };
            });

            // Functions
            self.validate = function() {
                api.post('volumestoragerouters/' + self.vsrGuid + '/can_be_deleted')
                    .done(function(data) {
                        self.loaded(true);
                        self.inUse(data);
                    })
                    .fail(function() {
                        self.loaded(undefined);
                    });
            };
        };
        self.AddValidation = function(vsr, vsa, vsrDeferred, data) {
            var self = this;

            // Variables
            self.vsa         = vsa;
            self.vsr         = vsr;
            self.shared      = shared;
            self.vsrDeferred = vsrDeferred;
            self.data        = data;

            // Observables
            self.loaded      = ko.observable(false);
            self.vRouterPort = ko.observable();
            self.vsrs        = ko.observableArray([]);
            self.mountpoints = ko.observableArray([]);
            self.ipAddresses = ko.observableArray([]);

            // Computed
            self.validationState = ko.computed(function() {
                var valid = true, reasons = [], fields = [];
                if (self.loaded() === false) {
                    valid = undefined;
                } else if (self.loaded() === undefined) {
                    valid = false;
                    reasons.push($.t('ovs:wizards.vsatovpool.confirm.errorvalidating'));
                } else {
                    $.each(self.vsrs(), function(index, vsr) {
                        if (self.vsr().mountpointCache() === vsr.mountpointCache() && $.inArray('cache', fields) === -1) {
                            valid = false;
                            fields.push('cache');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.cachefs') }));
                        }
                        if (self.vsr().mountpointDFS() === vsr.mountpointDFS() && $.inArray('dfs', fields) === -1) {
                            valid = false;
                            fields.push('dfs');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.dfs') }));
                        }
                        if (self.vsr().mountpointMD() === vsr.mountpointMD() && $.inArray('md', fields) === -1) {
                            valid = false;
                            fields.push('md');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.mdfs') }));
                        }
                        if (self.vsr().mountpointTemp() === vsr.mountpointTemp() && $.inArray('temp', fields) === -1) {
                            valid = false;
                            fields.push('temp');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.mtptinuse', { what: $.t('ovs:generic.tempfs') }));
                        }
                        if (self.vsr().port() === vsr.port() && $.inArray('port', fields) === -1) {
                            valid = false;
                            fields.push('port');
                            reasons.push($.t('ovs:wizards.addvpool.gathermountpoints.portinuse'));
                        }
                        return true;
                    });
                    if ($.inArray(self.vsr().storageIP(), self.ipAddresses()) === -1 && $.inArray('ip', fields) === -1) {
                        valid = false;
                        fields.push('ip');
                        reasons.push($.t('ovs:wizards.vsatovpool.confirm.ipnotavailable', { what: self.vsr().storageIP() }));
                    }
                }
                return { valid: valid, reasons: reasons, fields: fields };
            });

            // Functions
            self.validate = function() {
                var calls = [
                    $.Deferred(function(physicalDeferred) {
                        api.post('vmachines/' + self.vsa.guid() + '/get_physical_metadata')
                            .then(self.shared.tasks.wait)
                            .then(function(data) {
                                self.mountpoints(data.mountpoints);
                                self.ipAddresses(data.ipaddresses);
                                self.vRouterPort(data.xmlrpcport);
                            })
                            .done(physicalDeferred.resolve)
                            .fail(physicalDeferred.reject);
                    }).promise(),
                    self.vsrDeferred.promise()
                ];
                generic.crossFiller(
                    self.vsa.servedVSRGuids, self.vsrs,
{'fraction_non_alphanumeric': 0.1347311464321948, 'fraction_numerical': 0.0023672641190395673, 'mean_word_length': 1.2931141439205955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2890867', 'n_tokens_mistral': 3949, 'n_tokens_neox': 3768, 'n_words': 702}