Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# See the License for the specific language governing permissions and
# limitations under the License.
from django import shortcuts
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import workflows
import disaster_recovery.api.api as freezer_api
class ActionConfigurationAction(workflows.Action):
action_id = forms.CharField(
widget=forms.HiddenInput(),
required=False)
backup_name = forms.CharField(
label=_("Action Name *"),
required=False)
action = forms.ChoiceField(
help_text=_("Set the action to be taken"))
mode = forms.ChoiceField(
help_text=_("Choose what you want to backup"),
required=False)
storage = forms.ChoiceField(
help_text=_("Set storage backend for a backup"))
cleaned_data['main_binary'] = None
return cleaned_data
class Meta(object):
name = _("Create Job Template")
help_text_template = "job_templates/_create_job_help.html"
class ConfigureInterfaceArgumentsAction(workflows.Action):
hidden_arguments_field = forms.CharField(
required=False,
widget=forms.HiddenInput(attrs={"class": "hidden_arguments_field"}))
argument_ids = forms.CharField(
required=False,
widget=forms.HiddenInput())
def __init__(self, request, *args, **kwargs):
super(ConfigureInterfaceArgumentsAction, self).__init__(
request, *args, **kwargs)
req = request.GET or request.POST
if 'argument_ids' in req:
self.arguments = []
for id in json.loads(req['argument_ids']):
fields = {
"name": "argument_name_" + str(id),
"description": "argument_description_" + str(id),
"mapping_type": "argument_mapping_type_" + str(id),
"location": "argument_location_" + str(id),
"value_type": "argument_value_type_" + str(id),
"default_value": "argument_default_value_" + str(id)}
argument = {k: req[v]
def __init__(self, request, *args, **kwargs):
super(ConfigAssemblyAction, self).__init__(request, *args, **kwargs)
if 'application_id' in request.REQUEST:
plan_id = request.REQUEST['application_id']
solum = solumclient(request)
plan = solum.plans.get(plan_id=plan_id)
plan_uri = plan.uri
else:
plan_uri = request.POST['plan_uri']
self.fields["plan_uri"] = forms.CharField(
widget=forms.HiddenInput(),
initial=plan_uri)
def __init__(self, request, *args, **kwargs):
super(JobExecutionGeneralConfigAction, self).__init__(request,
*args,
**kwargs)
if request.REQUEST.get("job_id", None) is None:
self.fields["job"] = forms.ChoiceField(
label=_("Job"),
required=True)
self.fields["job"].choices = self.populate_job_choices(request)
else:
self.fields["job"] = forms.CharField(
widget=forms.HiddenInput(),
initial=request.REQUEST.get("job_id", None))
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from openstack_dashboard import api
class AddDHCPAgent(forms.SelfHandlingForm):
network_id = forms.CharField(widget=forms.HiddenInput())
network_name = forms.CharField(label=_("Network Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
agent = forms.ThemableChoiceField(
label=_("New DHCP Agent"),
help_text=_("Choose an DHCP Agent to attach to."))
def __init__(self, request, *args, **kwargs):
super(AddDHCPAgent, self).__init__(request, *args, **kwargs)
initial = kwargs.get('initial', {})
self.fields['agent'].choices = self._populate_agent_choices(request,
initial)
def _populate_agent_choices(self, request, initial):
network_id = initial.get('network_id')
agents = initial.get('agents')
# under the License.
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from novaclient import exceptions as nova_exceptions
from horizon import exceptions
from horizon import forms
from horizon import messages
from openstack_dashboard import api
class CreateSnapshot(forms.SelfHandlingForm):
instance_id = forms.CharField(label=_("Instance ID"),
widget=forms.HiddenInput(),
required=False)
name = forms.CharField(max_length=255, label=_("Snapshot Name"))
def handle(self, request, data):
try:
snapshot = api.nova.snapshot_create(request,
data['instance_id'],
data['name'])
# NOTE(gabriel): This API call is only to display a pretty name.
instance = api.nova.server_get(request, data['instance_id'])
vals = {"name": data['name'], "inst": instance.name}
messages.success(request, _('Snapshot "%(name)s" created for '
'instance "%(inst)s"') % vals)
return snapshot
except nova_exceptions.Forbidden as exc:
if str(exc).startswith('Quota exceeded for resources: snapshots'):
import logging
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import api
from horizon import exceptions
from horizon import forms
from horizon import messages
LOG = logging.getLogger(__name__)
class UpdateInstance(forms.SelfHandlingForm):
tenant_id = forms.CharField(widget=forms.HiddenInput)
instance = forms.CharField(widget=forms.HiddenInput)
name = forms.CharField(required=True)
def handle(self, request, data):
try:
server = api.server_update(request, data['instance'], data['name'])
messages.success(request,
_('Instance "%s" updated.') % data['name'])
return server
except:
redirect = reverse("horizon:project:instances:index")
exceptions.handle(request,
_('Unable to update instance.'),
redirect=redirect)
def __init__(self, request, *args, **kwargs):
super(UpdateDefaultQuotasAction, self).__init__(request,
*args,
**kwargs)
disabled_quotas = quotas.get_disabled_quotas(request)
for field in disabled_quotas:
if field in self.fields:
self.fields[field].required = False
self.fields[field].widget = forms.HiddenInput()
no_available_text = _("No clients found.")
no_members_text = _("No clients selected.")
show_roles = False
contributes = ("clients",)
def contribute(self, data, context):
request = self.workflow.request
if data:
field_name = self.get_member_field_name('member')
context["clients"] = request.POST.getlist(field_name)
return context
class InfoConfigurationAction(workflows.Action):
actions = forms.CharField(
widget=forms.HiddenInput(),
required=False)
description = forms.CharField(
label=_("Job Name"),
help_text=_("Set a name for this job"))
job_id = forms.CharField(
widget=forms.HiddenInput(),
required=False)
schedule_start_date = forms.CharField(
label=_("Start Date and Time"),
required=False)
interval_uint = forms.ChoiceField(
label=_("Interval Unit"),
class UpdateGroup(GroupBase):
success_message = _('Successfully updated security group: %s')
error_message = _('Unable to update security group: %s')
id = forms.CharField(widget=forms.HiddenInput())
def _call_network_api(self, request, data):
return api.network.security_group_update(request,
data['id'],
data['name'],
data['description'])
class AddRule(forms.SelfHandlingForm):
id = forms.CharField(widget=forms.HiddenInput())
rule_menu = forms.ChoiceField(label=_('Rule'),
widget=forms.Select(attrs={
'class': 'switchable',
'data-slug': 'rule_menu'}))
# "direction" field is enabled only when custom mode.
# It is because most common rules in local_settings.py is meaningful
# when its direction is 'ingress'.
direction = forms.ChoiceField(
label=_('Direction'),
required=False,
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'rule_menu',
'data-rule_menu-tcp': _('Direction'),
'data-rule_menu-udp': _('Direction'),