Skip to content

Commit

Permalink
fix(dedicated): ip virtual mac & minor improvements
Browse files Browse the repository at this point in the history
Signed-off-by: frenauvh <florian.renaut@corp.ovh.com>
  • Loading branch information
frenautvh authored and marie-j committed Oct 20, 2020
1 parent 88a216a commit 3bcde93
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 162 deletions.
2 changes: 1 addition & 1 deletion packages/manager/apps/dedicated/client/app/ip/ip.app.js
Expand Up @@ -15,7 +15,7 @@ angular
url: '/configuration/ip?serviceName&page&pageSize',
templateUrl: 'ip/ip.html',
controller: 'IpMainCtrl',
reloadOnSearch: true,
reloadOnSearch: false,
translations: { value: ['.', './ip/reverse/update'], format: 'json' },
});
},
Expand Down
Expand Up @@ -29,7 +29,7 @@
</label>
<p
class="form-control-static"
data-ng-bind="('ip_service' + data.ipBlock.routedTo.serviceName) | ducTranslateAlt: data.ipBlock.routedTo.serviceName"
data-ng-bind="('ip_service' + (data.ipBlock.routedTo.serviceName || '_PARK')) | ducTranslateAlt: data.ipBlock.routedTo.serviceName"
></p>
</div>
<div class="form-group">
Expand Down
188 changes: 98 additions & 90 deletions packages/manager/apps/dedicated/client/app/ip/ip/ip-ip.controller.js
Expand Up @@ -16,6 +16,7 @@ angular
$q,
$rootScope,
$scope,
$state,
$stateParams,
$timeout,
$translate,
Expand All @@ -30,6 +31,12 @@ angular
Validator,
) => {
$scope.currentView = 'table';
$scope.alerts = {
mitigation: [],
antihack: [],
arp: [],
spam: [],
};

// pagination
$scope.pageNumber = toInteger($stateParams.page) || 1;
Expand All @@ -44,46 +51,46 @@ angular
$scope.pageSize = 300;
}

$http
.get('/sws/products/services', {
serviceType: 'aapi',
})
.then(({ data }) => data)
.then((services) => {
$scope.services = [
{
category: 'OTHER',
serviceName: '_ALL',
},
{
category: 'OTHER',
serviceName: '_PARK',
},
{
category: 'OTHER',
serviceName: '_FAILOVER',
},
...orderBy(services, 'serviceName'),
];
$scope.selectedService = find($scope.services, {
serviceName: $scope.serviceName,
});
});

function init() {
$scope.alerts = {
mitigation: [],
antihack: [],
arp: [],
spam: [],
};
$scope.loading = {};
$scope.state = {};
$scope.services = [];
$scope.selectedService = null;
$scope.serviceName = $stateParams.serviceName || '_ALL';
}

function fetchServices() {
return $http
.get('/sws/products/services', {
serviceType: 'aapi',
})
.then(({ data }) => data)
.then((services) => {
$scope.services = [
{
category: 'OTHER',
serviceName: '_ALL',
},
{
category: 'OTHER',
serviceName: '_PARK',
},
{
category: 'OTHER',
serviceName: '_FAILOVER',
},
...orderBy(services, 'serviceName'),
];
$scope.selectedService = find($scope.services, {
serviceName: $scope.serviceName,
});
$scope.serviceType = {};
$scope.services.forEach(({ category, serviceName }) => {
$scope.serviceType[serviceName] = category;
});
});
}

$scope.canImportIPFO = () =>
ipFeatureAvailability.allowIPFailoverImport();
$scope.canOrderIPFO = () => ipFeatureAvailability.allowIPFailoverOrder();
Expand All @@ -97,6 +104,21 @@ angular
$scope.parkPrice = price;
});

function refreshIp(ip) {
return $http
.get('/ips', {
params: {
extras: true,
ip,
},
serviceType: 'aapi',
})
.then(({ data }) => data)
.then(({ count, data }) => {
return count === 1 ? data[0] : null;
});
}

function checkIps(ipBlock) {
if (!(ipBlock.ips && ipBlock.ips.length)) {
return;
Expand Down Expand Up @@ -150,6 +172,15 @@ angular
});
}

// Poll virtual mac
if (get(ipBlock, 'virtualMac.status') === 'PENDING') {
IpVirtualMac.pollVirtualMacs(ipBlock.service).then(() => {
refreshIp(ipBlock.ipBlock).then((refreshedIp) => {
Object.assign(ipBlock, refreshedIp);
});
});
}

// Alerts
if (ip.spam === 'BLOCKED_FOR_SPAM') {
ipBlock.alerts.spam.push(ip.ip);
Expand All @@ -166,21 +197,6 @@ angular
});
}

function refreshIp(ip) {
return $http
.get('/ips', {
params: {
extras: true,
ip,
},
serviceType: 'aapi',
})
.then(({ data }) => data)
.then(({ count, data }) => {
return count === 1 ? data[0] : null;
});
}

function refreshAlerts(ips) {
$scope.loading.alerts = true;
const params = {
Expand All @@ -201,7 +217,12 @@ angular
arp: [],
spam: [],
};
if ($scope.serviceName && $scope.serviceName !== '_ALL') {
if (
$scope.serviceName &&
$scope.serviceName !== '_ALL' &&
$scope.serviceName !== '_PARK' &&
$scope.serviceName !== '_FAILOVER'
) {
params.serviceName = $scope.serviceName;
}
return ipsPromise
Expand Down Expand Up @@ -245,21 +266,27 @@ angular
} else if ($scope.serviceName && $scope.serviceName !== '_ALL') {
params.serviceName = $scope.serviceName;
}
return $http
.get('/ips', {
params,
serviceType: 'aapi',
})
const fetchServicesPromise = $scope.services.length
? $q.when($scope.services)
: fetchServices();
return fetchServicesPromise
.then(() =>
$http.get('/ips', {
params,
serviceType: 'aapi',
}),
)
.then(({ data }) => data)
.then(({ count, data }) => {
$scope.ipsCount = count;
$scope.ipsList = map(data, (ip) => {
const serviceName = get(ip, 'routedTo.serviceName');
return {
...ip,
collapsed: !ip.isUniq,
service: {
serviceName: get(ip, 'routedTo.serviceName'),
category: ip.type,
serviceName,
category: $scope.serviceType[serviceName],
},
};
});
Expand All @@ -268,19 +295,15 @@ angular
$scope.ipsList,
(ip) => !get(ip, 'routedTo.serviceName'),
);
$scope.ipsList = map($scope.ipsList, (ip) => ({
...ip,
routedTo: {
serviceName: '_PARK',
},
}));
}
$scope.ipsList.forEach(checkIps);
refreshAlerts(
count === $scope.ipsList.length || $scope.serviceName === '_PARK'
? data
: null,
);
})
.catch((error) => {
Alerter.error(`
${$translate.instant('ip_dashboard_error')}
<br />
${get(error, 'data.message') || get(error, 'data', error)}
`);
})
.finally(() => {
$scope.loading.table = false;
Expand All @@ -293,11 +316,11 @@ angular
return $translate.instant('ip_virtualmac_add_impossible_server');
}

if (ipBlock.service.virtualmac.status === 'PENDING') {
if (ipBlock.virtualMac.status === 'PENDING') {
return $translate.instant('ip_virtualmac_add_impossible_status');
}

if (ipBlock.service.virtualmac.status === 'OK') {
if (ipBlock.virtualMac.status === 'OK') {
return $translate.instant('ip_virtualmac_add_impossible_exists');
}
return $translate.instant('ip_virtualmac_add_impossible_unavailable');
Expand Down Expand Up @@ -329,13 +352,12 @@ angular
$location.search('page', $scope.pageNumber);
$location.search('serviceName', serviceName);
refreshTable();
refreshAlerts();
};

function pollVirtualMacs(service) {
IpVirtualMac.pollVirtualMacs(service).then((vmacInfos) => {
set(service, 'virtualmac', vmacInfos);
});
}
$scope.navigateToService = (serviceName) => {
$state.go('app.ip', { page: 1, serviceName }, { reload: true });
};

$scope.alertsCount = function alertsCount(ipBlock) {
if (ipBlock) {
Expand Down Expand Up @@ -432,23 +454,6 @@ angular
});
});

$scope.$on('ips.table.refreshVmac', (e, ipBlock) => {
if (ipBlock.service.category === 'DEDICATED') {
set(ipBlock, 'service.loading.virtualmac', true);
IpVirtualMac.getVirtualMacList(ipBlock.service)
.then((vmacInfos) => {
set(ipBlock, 'service.virtualmac', vmacInfos);

if (vmacInfos && vmacInfos.status === 'PENDING') {
pollVirtualMacs(ipBlock.service);
}
})
.finally(() => {
set(ipBlock, 'service.loading.virtualmac', false);
});
}
});

// Add only an Ipv6
$scope.$on('ips.table.add', (e, ipBlock, ipv6) => {
// Ensure ipBlock is loaded and opened
Expand All @@ -469,6 +474,7 @@ angular
$scope.$on('ips.table.reload', () => {
init();
refreshTable();
refreshAlerts();
});

$scope.$on('organisation.change.done', () => {
Expand Down Expand Up @@ -598,5 +604,7 @@ angular
} else {
refreshTable();
}

refreshAlerts();
},
);

0 comments on commit 3bcde93

Please sign in to comment.