mirror of https://github.com/portainer/portainer
* feat(network-creation): macvlan driver for swarm * refactor(network-creation): layout rework to make it simpler with MACVLAN and keep it consistent with other drivers * fix(network-creation): MACVLAN - parent network card is now properly saved, names are not prefixed anymore and the --attachable option is now supported * refactor(network-creation): PR macvlan review - rework of macvlan view + code optimisation * fix(network-creation): disable attachable and internal options on macvlan config creationpull/2193/head
parent
8769fadd5c
commit
bda5eac0c1
|
@ -0,0 +1,106 @@
|
|||
<div class="datatable">
|
||||
<rd-widget>
|
||||
<rd-widget-body classes="no-padding">
|
||||
<div class="toolBar">
|
||||
<div class="toolBarTitle">
|
||||
<i class="fa" ng-class="$ctrl.titleIcon" aria-hidden="true" style="margin-right: 2px;"></i> {{ $ctrl.titleText }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="searchBar">
|
||||
<i class="fa fa-search searchIcon" aria-hidden="true"></i>
|
||||
<input type="text" class="searchInput" ng-model="$ctrl.state.textFilter" placeholder="Search..." auto-focus>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover nowrap-cells">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<span class="md-checkbox">
|
||||
<input id="select_all" type="checkbox" ng-model="$ctrl.state.selectAll" ng-change="$ctrl.selectAll()" />
|
||||
<label for="select_all"></label>
|
||||
</span>
|
||||
<a ng-click="$ctrl.changeOrderBy('Hostname')">
|
||||
Name
|
||||
<i class="fa fa-sort-alpha-down" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Hostname' && !$ctrl.state.reverseOrder"></i>
|
||||
<i class="fa fa-sort-alpha-up" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Hostname' && $ctrl.state.reverseOrder"></i>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a ng-click="$ctrl.changeOrderBy('Role')">
|
||||
Role
|
||||
<i class="fa fa-sort-alpha-down" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Role' && !$ctrl.state.reverseOrder"></i>
|
||||
<i class="fa fa-sort-alpha-up" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Role' && $ctrl.state.reverseOrder"></i>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a ng-click="$ctrl.changeOrderBy('EngineVersion')">
|
||||
Engine
|
||||
<i class="fa fa-sort-alpha-down" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'EngineVersion' && !$ctrl.state.reverseOrder"></i>
|
||||
<i class="fa fa-sort-alpha-up" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'EngineVersion' && $ctrl.state.reverseOrder"></i>
|
||||
</a>
|
||||
</th>
|
||||
<th ng-if="$ctrl.showIpAddressColumn">
|
||||
<a ng-click="$ctrl.changeOrderBy('Addr')">
|
||||
IP Address
|
||||
<i class="fa fa-sort-alpha-down" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Addr' && !$ctrl.state.reverseOrder"></i>
|
||||
<i class="fa fa-sort-alpha-up" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Addr' && $ctrl.state.reverseOrder"></i>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a ng-click="$ctrl.changeOrderBy('Status')">
|
||||
Status
|
||||
<i class="fa fa-sort-alpha-down" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Status' && !$ctrl.state.reverseOrder"></i>
|
||||
<i class="fa fa-sort-alpha-up" aria-hidden="true" ng-if="$ctrl.state.orderBy === 'Status' && $ctrl.state.reverseOrder"></i>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr dir-paginate="item in ($ctrl.state.filteredDataSet = ($ctrl.dataset | filter:$ctrl.state.textFilter | orderBy:$ctrl.state.orderBy:$ctrl.state.reverseOrder | itemsPerPage: $ctrl.state.paginatedItemLimit))"
|
||||
ng-class="{active: item.Checked}">
|
||||
<td>
|
||||
<span class="md-checkbox">
|
||||
<input id="select_{{ $index }}" type="checkbox" ng-model="item.Checked" ng-change="$ctrl.selectItem(item)" />
|
||||
<label for="select_{{ $index }}"></label>
|
||||
</span>
|
||||
<a ui-sref="docker.nodes.node({id: item.Id})" ng-if="$ctrl.accessToNodeDetails">{{ item.Hostname }}</a>
|
||||
<span ng-if="!$ctrl.accessToNodeDetails">{{ item.Hostname }}</span>
|
||||
</td>
|
||||
<td>{{ item.Role }}</td>
|
||||
<td>{{ item.EngineVersion }}</td>
|
||||
<td ng-if="$ctrl.showIpAddressColumn">{{ item.Addr }}</td>
|
||||
<td>
|
||||
<span class="label label-{{ item.Status | nodestatusbadge }}">{{ item.Status }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="!$ctrl.dataset">
|
||||
<td colspan="7" class="text-center text-muted">Loading...</td>
|
||||
</tr>
|
||||
<tr ng-if="$ctrl.state.filteredDataSet.length === 0">
|
||||
<td colspan="7" class="text-center text-muted">No node available.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="footer" ng-if="$ctrl.dataset">
|
||||
<div class="paginationControls">
|
||||
<form class="form-inline">
|
||||
<span class="limitSelector">
|
||||
<span style="margin-right: 5px;">
|
||||
Items per page
|
||||
</span>
|
||||
<select class="form-control" ng-model="$ctrl.state.paginatedItemLimit" ng-change="$ctrl.changePaginationLimit()">
|
||||
<option value="0">All</option>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
</span>
|
||||
<dir-pagination-controls max-size="5"></dir-pagination-controls>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
</div>
|
|
@ -0,0 +1,15 @@
|
|||
angular.module('portainer.docker').component('macvlanNodesDatatable', {
|
||||
templateUrl: 'app/docker/components/datatables/macvlan-nodes-datatable/macvlanNodesDatatable.html',
|
||||
controller: 'GenericDatatableController',
|
||||
bindings: {
|
||||
titleText: '@',
|
||||
titleIcon: '@',
|
||||
dataset: '<',
|
||||
tableKey: '@',
|
||||
orderBy: '@',
|
||||
reverseOrder: '<',
|
||||
showIpAddressColumn: '<',
|
||||
accessToNodeDetails: '<',
|
||||
state: '='
|
||||
}
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
angular.module('portainer.docker').component('networkMacvlanForm', {
|
||||
templateUrl: 'app/docker/components/network-macvlan-form/networkMacvlanForm.html',
|
||||
controller: 'NetworkMacvlanFormController',
|
||||
bindings: {
|
||||
data: '=',
|
||||
applicationState: '<'
|
||||
}
|
||||
});
|
|
@ -0,0 +1,108 @@
|
|||
<div>
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Macvlan configuration
|
||||
</div>
|
||||
<!-- selector -->
|
||||
<div class="form-group">
|
||||
<span class="col-sm-12 text-muted small">
|
||||
<i class="fa fa-info-circle blue-icon" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
To create a MACVLAN network you need to create a configuration, then create the network from this configuration.
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group" style="margin-bottom: 0">
|
||||
<div class="boxselector_wrapper">
|
||||
<div>
|
||||
<input type="radio" id="network_config" ng-model="$ctrl.data.Scope" value="local">
|
||||
<label for="network_config">
|
||||
<div class="boxselector_header">
|
||||
<i class="fa fa-cog" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
Configuration
|
||||
</div>
|
||||
<p>I want to configure a network before deploying it</p>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" id="network_deploy" ng-model="$ctrl.data.Scope" value="swarm" ng-disabled="$ctrl.availableNetworks.length === 0">
|
||||
<label for="network_deploy" ng-class="$ctrl.availableNetworks.length === 0 ? 'boxselector_disabled' : ''">
|
||||
<div class="boxselector_header">
|
||||
<i class="fa fa-sitemap" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
Creation
|
||||
</div>
|
||||
<p>I want to create a network from a configuration</p>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !selector -->
|
||||
|
||||
<ng-form name="macvlanConfigurationForm">
|
||||
<!-- configuration-inputs -->
|
||||
<div ng-show="$ctrl.data.Scope === 'local'">
|
||||
<!-- network-card-input -->
|
||||
<div class="form-group">
|
||||
<label for="network_card" class="col-sm-3 col-lg-2 control-label text-left">Parent network card</label>
|
||||
<div class="col-sm-9 col-lg-10">
|
||||
<input type="text" class="form-control" name="network_card" ng-model="$ctrl.data.ParentNetworkCard" placeholder="e.g. eth0 or ens160 ..."
|
||||
ng-required="$ctrl.data.Scope === 'local' && !$ctrl.data.ParentNetworkCard">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" ng-show="macvlanConfigurationForm.network_card.$invalid">
|
||||
<div class="col-sm-12 small text-warning">
|
||||
<div ng-messages="macvlanConfigurationForm.network_card.$error">
|
||||
<p ng-message="required">
|
||||
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Parent network card must be specified.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- network-card-input -->
|
||||
<!-- nodes-selector -->
|
||||
<div ng-if="$ctrl.applicationState.endpoint.mode.agentProxy && $ctrl.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE'">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<macvlan-nodes-datatable title-text="Select the nodes where you want to deploy the local configuration" title-icon="fa-hdd"
|
||||
dataset="$ctrl.nodes" table-key="nodes" state="$ctrl.data.DatatableState" order-by="Hostname" show-ip-address-column="$ctrl.applicationState.endpoint.apiVersion >= 1.25"
|
||||
access-to-node-details="!$ctrl.applicationState.application.authentication || $ctrl.isAdmin" name="node_selector"
|
||||
ng-model="tmp" ng-required="$ctrl.requiredNodeSelection()"></macvlan-nodes-datatable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" ng-show="macvlanConfigurationForm.node_selector.$invalid">
|
||||
<div class="col-sm-12 small text-warning">
|
||||
<div ng-messages="macvlanConfigurationForm.node_selector.$error">
|
||||
<p ng-message="required">
|
||||
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> At least one node must be selected.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !nodes-selector -->
|
||||
</div>
|
||||
<!-- configuration-inputs -->
|
||||
<!-- deploy-inputs -->
|
||||
<div ng-show="$ctrl.data.Scope === 'swarm'">
|
||||
<!-- configuration-selector -->
|
||||
<!-- network-input -->
|
||||
<div class="form-group">
|
||||
<label for="config_network" class="col-sm-2 col-lg-1 control-label text-left">Configuration</label>
|
||||
<div class="col-sm-9">
|
||||
<select class="form-control" ng-options="net.Name for net in $ctrl.availableNetworks" ng-model="$ctrl.data.SelectedNetworkConfig"
|
||||
name="config_network" ng-required="$ctrl.requiredConfigSelection()">
|
||||
<option selected disabled hidden value="">Select a network</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !network-input -->
|
||||
<div class="form-group" ng-show="macvlanConfigurationForm.config_network.$invalid">
|
||||
<div class="col-sm-12 small text-warning">
|
||||
<div ng-messages="macvlanConfigurationForm.config_network.$error">
|
||||
<p ng-message="required">
|
||||
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Select a configuration network.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !configuration-selector -->
|
||||
</div>
|
||||
<!-- deploy-inputs -->
|
||||
</ng-form>
|
||||
</div>
|
|
@ -0,0 +1,51 @@
|
|||
angular.module('portainer.docker')
|
||||
.controller('NetworkMacvlanFormController', ['$q', 'NodeService', 'NetworkService', 'Notifications', 'StateManager', 'Authentication',
|
||||
function ($q, NodeService, NetworkService, Notifications, StateManager, Authentication) {
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.requiredNodeSelection = function () {
|
||||
if (ctrl.data.Scope !== 'local' || ctrl.data.DatatableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return ctrl.data.DatatableState.selectedItemCount === 0;
|
||||
};
|
||||
|
||||
ctrl.requiredConfigSelection = function () {
|
||||
if (ctrl.data.Scope !== 'swarm') {
|
||||
return false;
|
||||
}
|
||||
return !ctrl.data.SelectedNetworkConfig;
|
||||
};
|
||||
|
||||
function initComponent() {
|
||||
if (StateManager.getState().application.authentication) {
|
||||
var userDetails = Authentication.getUserDetails();
|
||||
var isAdmin = userDetails.role === 1 ? true : false;
|
||||
ctrl.isAdmin = isAdmin;
|
||||
}
|
||||
var provider = ctrl.applicationState.endpoint.mode.provider;
|
||||
var apiVersion = ctrl.applicationState.endpoint.apiVersion;
|
||||
$q.all({
|
||||
nodes: provider !== 'DOCKER_SWARM_MODE' || NodeService.nodes(),
|
||||
networks: NetworkService.networks(
|
||||
provider === 'DOCKER_STANDALONE' || provider === 'DOCKER_SWARM_MODE',
|
||||
false,
|
||||
provider === 'DOCKER_SWARM_MODE' && apiVersion >= 1.25
|
||||
)
|
||||
})
|
||||
.then(function success(data) {
|
||||
if (data.nodes !== true) {
|
||||
ctrl.nodes = data.nodes;
|
||||
}
|
||||
ctrl.availableNetworks = data.networks.filter(function (item) {
|
||||
return item.ConfigOnly === true;
|
||||
});
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve informations for macvlan');
|
||||
});
|
||||
}
|
||||
|
||||
initComponent();
|
||||
}
|
||||
]);
|
|
@ -0,0 +1,8 @@
|
|||
function MacvlanFormData() {
|
||||
this.Scope = 'local';
|
||||
this.SelectedNetworkConfig = '';
|
||||
this.DatatableState = {
|
||||
selectedItems: []
|
||||
};
|
||||
this.ParentNetworkCard = '';
|
||||
}
|
|
@ -23,4 +23,7 @@ function NetworkViewModel(data) {
|
|||
this.NodeName = data.Portainer.Agent.NodeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ConfigFrom = data.ConfigFrom;
|
||||
this.ConfigOnly = data.ConfigOnly;
|
||||
}
|
|
@ -1,138 +1,207 @@
|
|||
angular.module('portainer.docker')
|
||||
.controller('CreateNetworkController', ['$q', '$scope', '$state', 'PluginService', 'Notifications', 'NetworkService', 'LabelHelper', 'Authentication', 'ResourceControlService', 'FormValidator', 'HttpRequestHelper',
|
||||
function ($q, $scope, $state, PluginService, Notifications, NetworkService, LabelHelper, Authentication, ResourceControlService, FormValidator, HttpRequestHelper) {
|
||||
.controller('CreateNetworkController', ['$q', '$scope', '$state', 'PluginService', 'Notifications', 'NetworkService', 'LabelHelper', 'Authentication', 'ResourceControlService', 'FormValidator', 'HttpRequestHelper',
|
||||
function ($q, $scope, $state, PluginService, Notifications, NetworkService, LabelHelper, Authentication, ResourceControlService, FormValidator, HttpRequestHelper) {
|
||||
|
||||
$scope.formValues = {
|
||||
DriverOptions: [],
|
||||
Subnet: '',
|
||||
Gateway: '',
|
||||
Labels: [],
|
||||
AccessControlData: new AccessControlFormData(),
|
||||
NodeName: null
|
||||
};
|
||||
$scope.formValues = {
|
||||
DriverOptions: [],
|
||||
Subnet: '',
|
||||
Gateway: '',
|
||||
IPRange: '',
|
||||
AuxAddress: '',
|
||||
Labels: [],
|
||||
AccessControlData: new AccessControlFormData(),
|
||||
NodeName: null,
|
||||
Macvlan: new MacvlanFormData()
|
||||
};
|
||||
|
||||
$scope.state = {
|
||||
formValidationError: '',
|
||||
actionInProgress: false
|
||||
};
|
||||
$scope.state = {
|
||||
formValidationError: '',
|
||||
actionInProgress: false
|
||||
};
|
||||
|
||||
$scope.availableNetworkDrivers = [];
|
||||
$scope.availableNetworkDrivers = [];
|
||||
|
||||
$scope.config = {
|
||||
Driver: 'bridge',
|
||||
CheckDuplicate: true,
|
||||
Internal: false,
|
||||
// Force IPAM Driver to 'default', should not be required.
|
||||
// See: https://github.com/docker/docker/issues/25735
|
||||
IPAM: {
|
||||
Driver: 'default',
|
||||
Config: []
|
||||
},
|
||||
Labels: {}
|
||||
};
|
||||
$scope.config = {
|
||||
Driver: 'bridge',
|
||||
CheckDuplicate: true,
|
||||
Internal: false,
|
||||
Attachable: false,
|
||||
// Force IPAM Driver to 'default', should not be required.
|
||||
// See: https://github.com/docker/docker/issues/25735
|
||||
IPAM: {
|
||||
Driver: 'default',
|
||||
Config: []
|
||||
},
|
||||
Labels: {}
|
||||
};
|
||||
|
||||
$scope.addDriverOption = function() {
|
||||
$scope.formValues.DriverOptions.push({ name: '', value: '' });
|
||||
};
|
||||
$scope.addDriverOption = function () {
|
||||
$scope.formValues.DriverOptions.push({
|
||||
name: '',
|
||||
value: ''
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeDriverOption = function(index) {
|
||||
$scope.formValues.DriverOptions.splice(index, 1);
|
||||
};
|
||||
$scope.removeDriverOption = function (index) {
|
||||
$scope.formValues.DriverOptions.splice(index, 1);
|
||||
};
|
||||
|
||||
$scope.addLabel = function() {
|
||||
$scope.formValues.Labels.push({ key: '', value: ''});
|
||||
};
|
||||
$scope.addLabel = function () {
|
||||
$scope.formValues.Labels.push({
|
||||
key: '',
|
||||
value: ''
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeLabel = function(index) {
|
||||
$scope.formValues.Labels.splice(index, 1);
|
||||
};
|
||||
$scope.removeLabel = function (index) {
|
||||
$scope.formValues.Labels.splice(index, 1);
|
||||
};
|
||||
|
||||
function prepareIPAMConfiguration(config) {
|
||||
if ($scope.formValues.Subnet) {
|
||||
var ipamConfig = {};
|
||||
ipamConfig.Subnet = $scope.formValues.Subnet;
|
||||
if ($scope.formValues.Gateway) {
|
||||
ipamConfig.Gateway = $scope.formValues.Gateway ;
|
||||
function prepareIPAMConfiguration(config) {
|
||||
if ($scope.formValues.Subnet) {
|
||||
var ipamConfig = {};
|
||||
ipamConfig.Subnet = $scope.formValues.Subnet;
|
||||
if ($scope.formValues.Gateway) {
|
||||
ipamConfig.Gateway = $scope.formValues.Gateway;
|
||||
}
|
||||
if ($scope.formValues.IPRange) {
|
||||
ipamConfig.IPRange = $scope.formValues.IPRange;
|
||||
}
|
||||
if ($scope.formValues.AuxAddress) {
|
||||
ipamConfig.AuxAddress = $scope.formValues.AuxAddress;
|
||||
}
|
||||
config.IPAM.Config.push(ipamConfig);
|
||||
}
|
||||
}
|
||||
config.IPAM.Config.push(ipamConfig);
|
||||
|
||||
function prepareDriverOptions(config) {
|
||||
var options = {};
|
||||
$scope.formValues.DriverOptions.forEach(function (option) {
|
||||
options[option.name] = option.value;
|
||||
});
|
||||
config.Options = options;
|
||||
}
|
||||
|
||||
function prepareLabelsConfig(config) {
|
||||
config.Labels = LabelHelper.fromKeyValueToLabelHash($scope.formValues.Labels);
|
||||
}
|
||||
|
||||
function prepareConfiguration() {
|
||||
var config = angular.copy($scope.config);
|
||||
prepareIPAMConfiguration(config);
|
||||
prepareDriverOptions(config);
|
||||
prepareLabelsConfig(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
function modifyNetworkConfigurationForMacvlanConfigOnly(config) {
|
||||
config.Internal = null;
|
||||
config.Attachable = null;
|
||||
config.ConfigOnly = true;
|
||||
config.Options.parent = $scope.formValues.Macvlan.ParentNetworkCard;
|
||||
}
|
||||
|
||||
function modifyNetworkConfigurationForMacvlanConfigFrom(config, selectedNetworkConfig) {
|
||||
config.ConfigFrom = {
|
||||
Network: selectedNetworkConfig.Name
|
||||
};
|
||||
config.Scope = 'swarm';
|
||||
}
|
||||
|
||||
function validateForm(accessControlData, isAdmin) {
|
||||
$scope.state.formValidationError = '';
|
||||
var error = '';
|
||||
error = FormValidator.validateAccessControl(accessControlData, isAdmin);
|
||||
|
||||
if (error) {
|
||||
$scope.state.formValidationError = error;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function createNetwork(context) {
|
||||
HttpRequestHelper.setPortainerAgentTargetHeader(context.nodeName);
|
||||
|
||||
$scope.state.actionInProgress = true;
|
||||
NetworkService.create(context.networkConfiguration)
|
||||
.then(function success(data) {
|
||||
var networkIdentifier = data.Id;
|
||||
var userId = context.userDetails.ID;
|
||||
return ResourceControlService.applyResourceControl('network', networkIdentifier, userId, context.accessControlData, []);
|
||||
})
|
||||
.then(function success() {
|
||||
Notifications.success('Network successfully created');
|
||||
if (context.reload) {
|
||||
$state.go('docker.networks', {}, {
|
||||
reload: true
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'An error occured during network creation');
|
||||
})
|
||||
.finally(function final() {
|
||||
$scope.state.actionInProgress = false;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.create = function () {
|
||||
var networkConfiguration = prepareConfiguration();
|
||||
var accessControlData = $scope.formValues.AccessControlData;
|
||||
var userDetails = Authentication.getUserDetails();
|
||||
var isAdmin = userDetails.role === 1;
|
||||
|
||||
if (!validateForm(accessControlData, isAdmin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var creationContext = {
|
||||
nodeName: $scope.formValues.NodeName,
|
||||
networkConfiguration: networkConfiguration,
|
||||
userDetails: userDetails,
|
||||
accessControlData: accessControlData,
|
||||
reload: true
|
||||
};
|
||||
|
||||
if ($scope.config.Driver === 'macvlan') {
|
||||
if ($scope.formValues.Macvlan.Scope === 'local') {
|
||||
modifyNetworkConfigurationForMacvlanConfigOnly(networkConfiguration);
|
||||
} else if ($scope.formValues.Macvlan.Scope === 'swarm') {
|
||||
var selectedNetworkConfig = $scope.formValues.Macvlan.SelectedNetworkConfig;
|
||||
modifyNetworkConfigurationForMacvlanConfigFrom(networkConfiguration, selectedNetworkConfig);
|
||||
creationContext.nodeName = selectedNetworkConfig.NodeName;
|
||||
}
|
||||
}
|
||||
|
||||
if ($scope.config.Driver === 'macvlan' && $scope.formValues.Macvlan.Scope === 'local' &&
|
||||
$scope.applicationState.endpoint.mode.agentProxy && $scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE') {
|
||||
var selectedNodes = $scope.formValues.Macvlan.DatatableState.selectedItems;
|
||||
selectedNodes.forEach(function (node, idx) {
|
||||
creationContext.nodeName = node.Hostname;
|
||||
creationContext.reload = idx === selectedNodes.length - 1 ? true : false;
|
||||
createNetwork(creationContext);
|
||||
});
|
||||
} else {
|
||||
createNetwork(creationContext);
|
||||
}
|
||||
};
|
||||
|
||||
function initView() {
|
||||
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
||||
|
||||
PluginService.networkPlugins(apiVersion < 1.25)
|
||||
.then(function success(data) {
|
||||
if ($scope.applicationState.endpoint.mode.provider !== 'DOCKER_SWARM_MODE') {
|
||||
data.splice(data.indexOf('macvlan'), 1);
|
||||
}
|
||||
$scope.availableNetworkDrivers = data;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve network drivers');
|
||||
});
|
||||
}
|
||||
|
||||
initView();
|
||||
}
|
||||
}
|
||||
|
||||
function prepareDriverOptions(config) {
|
||||
var options = {};
|
||||
$scope.formValues.DriverOptions.forEach(function (option) {
|
||||
options[option.name] = option.value;
|
||||
});
|
||||
config.Options = options;
|
||||
}
|
||||
|
||||
function prepareLabelsConfig(config) {
|
||||
config.Labels = LabelHelper.fromKeyValueToLabelHash($scope.formValues.Labels);
|
||||
}
|
||||
|
||||
function prepareConfiguration() {
|
||||
var config = angular.copy($scope.config);
|
||||
prepareIPAMConfiguration(config);
|
||||
prepareDriverOptions(config);
|
||||
prepareLabelsConfig(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
function validateForm(accessControlData, isAdmin) {
|
||||
$scope.state.formValidationError = '';
|
||||
var error = '';
|
||||
error = FormValidator.validateAccessControl(accessControlData, isAdmin);
|
||||
|
||||
if (error) {
|
||||
$scope.state.formValidationError = error;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$scope.create = function () {
|
||||
var networkConfiguration = prepareConfiguration();
|
||||
var accessControlData = $scope.formValues.AccessControlData;
|
||||
var userDetails = Authentication.getUserDetails();
|
||||
var isAdmin = userDetails.role === 1;
|
||||
|
||||
if (!validateForm(accessControlData, isAdmin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var nodeName = $scope.formValues.NodeName;
|
||||
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
||||
|
||||
$scope.state.actionInProgress = true;
|
||||
NetworkService.create(networkConfiguration)
|
||||
.then(function success(data) {
|
||||
var networkIdentifier = data.Id;
|
||||
var userId = userDetails.ID;
|
||||
return ResourceControlService.applyResourceControl('network', networkIdentifier, userId, accessControlData, []);
|
||||
})
|
||||
.then(function success() {
|
||||
Notifications.success('Network successfully created');
|
||||
$state.go('docker.networks', {}, {reload: true});
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'An error occured during network creation');
|
||||
})
|
||||
.finally(function final() {
|
||||
$scope.state.actionInProgress = false;
|
||||
});
|
||||
};
|
||||
|
||||
function initView() {
|
||||
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
||||
|
||||
PluginService.networkPlugins(apiVersion < 1.25)
|
||||
.then(function success(data){
|
||||
$scope.availableNetworkDrivers = data;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve network drivers');
|
||||
});
|
||||
}
|
||||
|
||||
initView();
|
||||
}]);
|
||||
]);
|
|
@ -9,37 +9,22 @@
|
|||
<div class="col-lg-12 col-md-12 col-xs-12">
|
||||
<rd-widget>
|
||||
<rd-widget-body>
|
||||
<form class="form-horizontal">
|
||||
<form class="form-horizontal" name="networkCreationForm">
|
||||
<!-- name-input -->
|
||||
<div class="form-group">
|
||||
<label for="network_name" class="col-sm-1 control-label text-left">Name</label>
|
||||
<div class="col-sm-11">
|
||||
<label for="network_name" class="col-sm-2 col-lg-1 control-label text-left">Name</label>
|
||||
<div class="col-sm-10 col-lg-11">
|
||||
<input type="text" class="form-control" ng-model="config.Name" id="network_name" placeholder="e.g. myNetwork">
|
||||
</div>
|
||||
</div>
|
||||
<!-- !name-input -->
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Network configuration
|
||||
</div>
|
||||
<!-- subnet-gateway-inputs -->
|
||||
<div class="form-group">
|
||||
<label for="network_subnet" class="col-sm-2 col-lg-1 control-label text-left">Subnet</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.Subnet" id="network_subnet" placeholder="e.g. 172.20.0.0/16">
|
||||
</div>
|
||||
<label for="network_gateway" class="col-sm-2 col-lg-1 control-label text-left">Gateway</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.Gateway" id="network_gateway" placeholder="e.g. 172.20.10.11">
|
||||
</div>
|
||||
</div>
|
||||
<!-- !subnet-gateway-inputs -->
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Driver configuration
|
||||
</div>
|
||||
<!-- driver-input -->
|
||||
<div class="form-group">
|
||||
<label for="network_driver" class="col-sm-2 col-lg-1 control-label text-left">Driver</label>
|
||||
<div class="col-sm-11">
|
||||
<div class="col-sm-10 col-lg-11">
|
||||
<select class="form-control" ng-options="driver for driver in availableNetworkDrivers" ng-model="config.Driver" ng-if="availableNetworkDrivers.length > 0">
|
||||
<option disabled hidden value="">Select a driver</option>
|
||||
</select>
|
||||
|
@ -77,6 +62,38 @@
|
|||
<!-- !driver-options-input-list -->
|
||||
</div>
|
||||
<!-- !driver-options -->
|
||||
<!-- macvlan-management -->
|
||||
<network-macvlan-form ng-show="config.Driver === 'macvlan'" data="formValues.Macvlan" application-state="applicationState"></network-macvlan-form>
|
||||
<!-- !macvlan-management -->
|
||||
<div ng-hide="config.Driver === 'macvlan' && formValues.Macvlan.Scope === 'swarm'">
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Network configuration
|
||||
</div>
|
||||
<!-- subnet-gateway-inputs -->
|
||||
<div class="form-group">
|
||||
<label for="network_subnet" class="col-sm-2 col-lg-1 control-label text-left">Subnet</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.Subnet" id="network_subnet" placeholder="e.g. 172.20.0.0/16">
|
||||
</div>
|
||||
<label for="network_gateway" class="col-sm-2 col-lg-1 control-label text-left">Gateway</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.Gateway" id="network_gateway" placeholder="e.g. 172.20.10.11">
|
||||
</div>
|
||||
</div>
|
||||
<!-- !subnet-gateway-inputs -->
|
||||
<!-- iprange-auxaddr-inputs -->
|
||||
<div class="form-group">
|
||||
<label for="network_iprange" class="col-sm-2 col-lg-1 control-label text-left">IP range</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.IPRange" id="network_iprange" placeholder="e.g. 172.20.10.128/25">
|
||||
</div>
|
||||
<label for="network_auxaddr" class="col-sm-2 col-lg-1 control-label text-left">Exclude IPs</label>
|
||||
<div class="col-sm-4 col-lg-5">
|
||||
<input type="text" class="form-control" ng-model="formValues.AuxAddress" id="network_auxaddr" placeholder="e.g. my-router=172.20.10.129">
|
||||
</div>
|
||||
</div>
|
||||
<!-- !iprange-auxaddr-inputs -->
|
||||
</div>
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Advanced configuration
|
||||
</div>
|
||||
|
@ -108,24 +125,37 @@
|
|||
</div>
|
||||
<!-- !labels-->
|
||||
<!-- internal -->
|
||||
<div class="form-group">
|
||||
<div class="form-group" ng-hide="config.Driver === 'macvlan' && formValues.Macvlan.Scope === 'local'">
|
||||
<div class="col-sm-12">
|
||||
<label for="ownership" class="control-label text-left">
|
||||
Restrict external access to the network
|
||||
</label>
|
||||
<label class="switch" style="margin-left: 20px;">
|
||||
<input type="checkbox" ng-model="config.Internal"><i></i>
|
||||
<label name="ownership" class="switch" style="margin-left: 20px;">
|
||||
<input type="checkbox" ng-model="config.Internal">
|
||||
<i></i>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !internal -->
|
||||
<div ng-if="applicationState.endpoint.mode.agentProxy && applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && config.Driver !== 'overlay'">
|
||||
<!-- attachable -->
|
||||
<div class="form-group" ng-hide="config.Driver === 'macvlan' && formValues.Macvlan.Scope === 'local'">
|
||||
<div class="col-sm-12">
|
||||
<label for="attachable" class="control-label text-left">
|
||||
Enable manual container attachment
|
||||
</label>
|
||||
<label name="attachable" class="switch" style="margin-left: 20px;">
|
||||
<input type="checkbox" ng-model="config.Attachable">
|
||||
<i></i>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !attachable -->
|
||||
<div ng-if="applicationState.endpoint.mode.agentProxy && applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && config.Driver !== 'overlay' && config.Driver !== 'macvlan'">
|
||||
<div class="col-sm-12 form-section-title">
|
||||
Deployment
|
||||
</div>
|
||||
<!-- node-selection -->
|
||||
<node-selector
|
||||
model="formValues.NodeName">
|
||||
<node-selector model="formValues.NodeName">
|
||||
</node-selector>
|
||||
<!-- !node-selection -->
|
||||
</div>
|
||||
|
@ -138,7 +168,8 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="state.actionInProgress || !config.Name" ng-click="create()" button-spinner="state.actionInProgress">
|
||||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="state.actionInProgress || !config.Name || (config.Driver === 'macvlan' && networkCreationForm.$invalid)"
|
||||
ng-click="create()" button-spinner="state.actionInProgress">
|
||||
<span ng-hide="state.actionInProgress">Create the network</span>
|
||||
<span ng-show="state.actionInProgress">Creating network...</span>
|
||||
</button>
|
||||
|
@ -151,4 +182,4 @@
|
|||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -626,6 +626,12 @@ ul.sidebar .sidebar-list .sidebar-sublist a.active {
|
|||
box-shadow: 0 3px 10px -2px rgba(161, 170, 166, 0.5);
|
||||
position: relative;
|
||||
}
|
||||
.boxselector_wrapper label.boxselector_disabled {
|
||||
background: #CACACA;
|
||||
border-color: #787878;
|
||||
color: #787878;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.boxselector_wrapper input[type="radio"]:checked + label {
|
||||
background: #337ab7;
|
||||
|
|
Loading…
Reference in New Issue