Revision 2dc27ac1 snf-astakos-app/astakos/im/management/commands/resource-modify.py
b/snf-astakos-app/astakos/im/management/commands/resource-modify.py | ||
---|---|---|
64 | 64 |
default='mb', |
65 | 65 |
help=("Specify display unit for resource values " |
66 | 66 |
"(one of %s); defaults to mb") % style_options), |
67 |
make_option('--allow-in-projects',
|
|
67 |
make_option('--api-visible',
|
|
68 | 68 |
metavar='True|False', |
69 |
help=("Specify whether to allow this resource " |
|
70 |
"in projects.")), |
|
69 |
help="Control visibility of this resource in the API"), |
|
70 |
make_option('--ui-visible', |
|
71 |
metavar='True|False', |
|
72 |
help="Control visibility of this resource in the UI"), |
|
71 | 73 |
) |
72 | 74 |
|
73 | 75 |
def handle(self, *args, **options): |
... | ... | |
77 | 79 |
'default_quota': self.change_limit, |
78 | 80 |
'default_quota_interactive': self.change_interactive, |
79 | 81 |
'default_quota_from_file': self.change_from_file, |
80 |
'allow_in_projects': self.set_allow_in_projects, |
|
82 |
'api_visible': self.set_api_visible, |
|
83 |
'ui_visible': self.set_ui_visible, |
|
81 | 84 |
} |
82 | 85 |
|
83 | 86 |
opts = [(key, value) |
... | ... | |
88 | 91 |
raise CommandError("Please provide exactly one of the options: " |
89 | 92 |
"--default-quota, --default-quota-interactive, " |
90 | 93 |
"--default-quota-from-file, " |
91 |
"--allow-in-projects.")
|
|
94 |
"--api-visible, --ui-visible.")
|
|
92 | 95 |
|
93 | 96 |
self.unit_style = options['unit_style'] |
94 | 97 |
check_style(self.unit_style) |
... | ... | |
97 | 100 |
action = actions[key] |
98 | 101 |
action(resource_name, value) |
99 | 102 |
|
100 |
def set_allow_in_projects(self, resource_name, allow): |
|
103 |
def set_api_visible(self, resource_name, allow): |
|
104 |
if resource_name is None: |
|
105 |
raise CommandError("Please provide a resource name.") |
|
106 |
|
|
107 |
try: |
|
108 |
allow = utils.parse_bool(allow) |
|
109 |
except ValueError: |
|
110 |
raise CommandError("Expecting a boolean value.") |
|
111 |
resource = self.get_resource(resource_name) |
|
112 |
resource.api_visible = allow |
|
113 |
if not allow and resource.ui_visible: |
|
114 |
self.stdout.write("Also resetting 'ui_visible' for consistency.\n") |
|
115 |
resource.ui_visible = False |
|
116 |
resource.save() |
|
117 |
|
|
118 |
def set_ui_visible(self, resource_name, allow): |
|
101 | 119 |
if resource_name is None: |
102 | 120 |
raise CommandError("Please provide a resource name.") |
103 | 121 |
|
... | ... | |
106 | 124 |
except ValueError: |
107 | 125 |
raise CommandError("Expecting a boolean value.") |
108 | 126 |
resource = self.get_resource(resource_name) |
109 |
resource.allow_in_projects = allow |
|
127 |
|
|
128 |
resource.ui_visible = allow |
|
129 |
if allow and not resource.api_visible: |
|
130 |
self.stdout.write("Also setting 'api_visible' for consistency.\n") |
|
131 |
resource.api_visible = True |
|
110 | 132 |
resource.save() |
111 | 133 |
|
112 | 134 |
def get_resource(self, resource_name): |
Also available in: Unified diff