mirror of https://github.com/portainer/portainer
feat(container-details): add section to join networks (#927)
parent
4adedf9436
commit
a161d25d48
|
@ -290,6 +290,22 @@
|
||||||
<div class="pagination-controls">
|
<div class="pagination-controls">
|
||||||
<dir-pagination-controls></dir-pagination-controls>
|
<dir-pagination-controls></dir-pagination-controls>
|
||||||
</div>
|
</div>
|
||||||
|
<hr />
|
||||||
|
<form class="form-horizontal">
|
||||||
|
<!-- network-input -->
|
||||||
|
<div class="row">
|
||||||
|
<label for="container_network" class="col-sm-3 col-lg-3 control-label text-left">Join a Network</label>
|
||||||
|
<div class="col-sm-5 col-lg-5">
|
||||||
|
<select class="form-control" ng-model="selectedNetwork" id="container_network">
|
||||||
|
<option selected disabled hidden value="">Select a network</option>
|
||||||
|
<option ng-repeat="net in availableNetworks" ng-value="net.Id">{{ net.Name }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4 col-lg-4">
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!selectedNetwork" ng-click="containerJoinNetwork(container, selectedNetwork)">Join Network</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</rd-widget-body>
|
</rd-widget-body>
|
||||||
</rd-widget>
|
</rd-widget>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -197,5 +197,44 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Con
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.containerJoinNetwork = function containerJoinNetwork(container, networkId) {
|
||||||
|
$('#joinNetworkSpinner').show();
|
||||||
|
Network.connect({id: networkId}, { Container: $stateParams.id }, function (d) {
|
||||||
|
if (container.message) {
|
||||||
|
$('#joinNetworkSpinner').hide();
|
||||||
|
Notifications.error('Error', d, 'Unable to connect container to network');
|
||||||
|
} else {
|
||||||
|
$('#joinNetworkSpinner').hide();
|
||||||
|
Notifications.success('Container joined network', $stateParams.id);
|
||||||
|
$state.go('container', {id: $stateParams.id}, {reload: true});
|
||||||
|
}
|
||||||
|
}, function (e) {
|
||||||
|
$('#joinNetworkSpinner').hide();
|
||||||
|
Notifications.error('Failure', e, 'Unable to connect container to network');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Network.query({}, function (d) {
|
||||||
|
var networks = d;
|
||||||
|
if ($scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM' || $scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE') {
|
||||||
|
networks = d.filter(function (network) {
|
||||||
|
if (network.Scope === 'global') {
|
||||||
|
return network;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$scope.globalNetworkCount = networks.length;
|
||||||
|
networks.push({Name: 'bridge'});
|
||||||
|
networks.push({Name: 'host'});
|
||||||
|
networks.push({Name: 'none'});
|
||||||
|
}
|
||||||
|
networks.push({Name: 'container'});
|
||||||
|
$scope.availableNetworks = networks;
|
||||||
|
if (!_.find(networks, {'Name': 'bridge'})) {
|
||||||
|
$scope.config.HostConfig.NetworkMode = 'nat';
|
||||||
|
}
|
||||||
|
}, function (e) {
|
||||||
|
Notifications.error('Failure', e, 'Unable to retrieve networks');
|
||||||
|
});
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Reference in New Issue