-
Notifications
You must be signed in to change notification settings - Fork 0
/
restrict_upgrades.go
51 lines (44 loc) · 1.36 KB
/
restrict_upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package apiserver
import (
"github.com/juju/collections/set"
"github.com/juju/juju/apiserver/params"
)
func upgradeMethodsOnly(facadeName, methodName string) error {
if !IsMethodAllowedDuringUpgrade(facadeName, methodName) {
return params.UpgradeInProgressError
}
return nil
}
func IsMethodAllowedDuringUpgrade(facadeName, methodName string) bool {
methods, ok := allowedMethodsDuringUpgrades[facadeName]
if !ok {
return false
}
return methods.Contains(methodName)
}
// allowedMethodsDuringUpgrades stores api calls
// that are not blocked during the upgrade process
// as well as their respective facade names.
// When needed, at some future point, this solution
// will need to be adjusted to cater for different
// facade versions as well.
var allowedMethodsDuringUpgrades = map[string]set.Strings{
"Client": set.NewStrings(
"FullStatus", // for "juju status"
"FindTools", // for "juju upgrade-model", before we can reset upgrade to re-run
"AbortCurrentUpgrade", // for "juju upgrade-model", so that we can reset upgrade to re-run
),
"SSHClient": set.NewStrings( // allow all SSH client related calls
"PublicAddress",
"PrivateAddress",
"BestAPIVersion",
"AllAddresses",
"PublicKeys",
"Proxy",
),
"Pinger": set.NewStrings(
"Ping",
),
}