Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# 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 horizon import api
from horizon import forms
from horizon.dashboards.syspanel.users.forms import CreateUserForm
class CreateUser(CreateUserForm):
role_id = forms.ChoiceField(widget=forms.HiddenInput())
tenant_id = forms.CharField(widget=forms.HiddenInput())
def __init__(self, request, *args, **kwargs):
super(CreateUser, self).__init__(request, *args, **kwargs)
tenant_id = self.request.path.split("/")[-1]
self.fields['tenant_id'].initial = tenant_id
'cookie_name': cookie}
else:
context['session_persistence'] = {'type': stype}
else:
context['session_persistence'] = {}
try:
api.lbaas.vip_create(request, **context)
return True
except Exception:
return False
class AddMemberAction(workflows.Action):
pool_id = forms.ThemableChoiceField(label=_("Pool"))
member_type = forms.ChoiceField(
label=_("Member Source"),
choices=[('server_list', _("Select from active instances")),
('member_address', _("Specify member IP address"))],
required=False,
widget=forms.Select(attrs={
'class': 'switchable',
'data-slug': 'membertype'
}))
members = forms.MultipleChoiceField(
required=False,
initial=["default"],
widget=forms.SelectMultiple(attrs={
'class': 'switched',
'data-switch-on': 'membertype',
'data-membertype-server_list': _("Member Instance(s)"),
}),
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import workflows
from openstack_dashboard.api import nova
from octavia_dashboard import api
__create_new__ = "Create New"
class SetLBDetailsAction(workflows.Action):
address = forms.ChoiceField(label=_("IP"),
help_text=_("Select from existing VIP IPs"))
name = forms.CharField(max_length=80, label=_("Name"),
required=True)
description = forms.CharField(widget=forms.Textarea(attrs={'rows': 2}),
label=_(
"Load Balancer Description"),
required=False,
help_text=_("Provide Load Balancer "
"Description."))
all_vips = None
is_update = False
LOAD_BALANCING_CHOICES = (
context['confirm_admin_pass'] = data.get("confirm_admin_pass", "")
return context
class CustomizeAction(workflows.Action):
class Meta(object):
name = _("Post-Creation")
help_text_template = ("project/instances/"
"_launch_customize_help.html")
source_choices = [('', _('Select Script Source')),
('raw', _('Direct Input')),
('file', _('File'))]
attributes = {'class': 'switchable', 'data-slug': 'scriptsource'}
script_source = forms.ChoiceField(
label=_('Customization Script Source'),
choices=source_choices,
widget=forms.ThemableSelectWidget(attrs=attributes),
required=False)
script_help = _("A script or set of commands to be executed after the "
"instance has been built (max 16kb).")
script_upload = forms.FileField(
label=_('Script File'),
help_text=script_help,
widget=forms.FileInput(attrs={
'class': 'switched',
'data-switch-on': 'scriptsource',
'data-scriptsource-file': _('Script File')}),
required=False)
def render(self, name, values, attrs=None):
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
output = "<span id="%s">%s</span>%s" %\
("id_%s_label" % name,
"internal-db://",
('' % util.flatatt(final_attrs)))
return mark_safe(output)
class JobBinaryCreateForm(forms.SelfHandlingForm):
NEW_SCRIPT = "%%%NEWSCRIPT%%%"
UPLOAD_BIN = "%%%UPLOADFILE%%%"
job_binary_name = forms.CharField(label=_("Name"))
job_binary_type = forms.ChoiceField(label=_("Storage type"))
job_binary_url = forms.CharField(label=_("URL"),
required=False,
widget=LabeledInput())
job_binary_internal = forms.ChoiceField(label=_("Internal binary"),
required=False)
job_binary_file = forms.FileField(label=_("Upload File"),
required=False)
job_binary_script_name = forms.CharField(label=_("Script name"),
required=False)
job_binary_script = forms.CharField(label=_("Script text"),
required=False,
widget=forms.Textarea(
label=_("Flavor"),
help_text=_("Size of instance to launch."),
required=False,
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'datastore',
}))
vertica_flavor = forms.ChoiceField(
label=_("Flavor"),
help_text=_("Size of instance to launch."),
required=False,
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'datastore',
}))
network = forms.ChoiceField(
label=_("Network"),
help_text=_("Network attached to instance."),
required=False)
volume = forms.IntegerField(
label=_("Volume Size"),
min_value=0,
initial=1,
help_text=_("Size of the volume in GB."))
root_password = forms.CharField(
label=_("Root Password"),
required=False,
help_text=_("Password for root user."),
widget=forms.PasswordInput(attrs={
'class': 'switched',
'data-switch-on': 'datastore',
}))
from horizon import messages
from mistraldashboard import api
from mistraldashboard.default.utils import convert_empty_string_to_none
from mistraldashboard.handle_errors import handle_errors
class CreateForm(forms.SelfHandlingForm):
name = forms.CharField(
max_length=255,
label=_("Name"),
help_text=_('Cron Trigger name.'),
required=True
)
workflow_id = forms.ChoiceField(
label=_('Workflow ID'),
help_text=_('Select Workflow ID.'),
widget=forms.Select(
attrs={'class': 'switchable',
'data-slug': 'workflow_select'}
)
)
input_source = forms.ChoiceField(
label=_('Input'),
help_text=_('JSON of input values defined in the workflow. '
'Select either file or raw content.'),
choices=[('file', _('File')),
('raw', _('Direct Input'))],
widget=forms.Select(
attrs={'class': 'switchable',
def populate_job_choices(self, request):
sahara = saharaclient(request)
jobs = sahara.jobs.list()
choices = [(job.id, job.name)
for job in jobs]
return choices
class Meta:
name = _("Job")
help_text_template = "jobs/_launch_job_help.html"
class JobExecutionExistingGeneralConfigAction(JobExecutionGeneralConfigAction):
cluster = forms.ChoiceField(
label=_("Cluster"),
required=True,
initial=(None, "None"),
widget=forms.Select(attrs={"class": "cluster_choice"}))
def populate_cluster_choices(self, request, context):
sahara = saharaclient(request)
clusters = sahara.clusters.list()
choices = [(cluster.id, cluster.name)
for cluster in clusters]
return choices
class Meta:
name = _("Job")
def __init__(self, request, *args, **kwargs):
super(GeneralConfigAction, self).__init__(request, *args, **kwargs)
hlps = helpers.Helpers(request)
plugin, hadoop_version = (
workflow_helpers.get_plugin_and_hadoop_version(request))
if not saharaclient.SAHARA_FLOATING_IP_DISABLED:
pools = neutron.floating_ip_pools_list(request)
pool_choices = [(pool.id, pool.name) for pool in pools]
pool_choices.insert(0, (None, "Do not assign floating IPs"))
self.fields['floating_ip_pool'] = forms.ChoiceField(
label=_("Floating IP Pool"),
choices=pool_choices,
required=False)
self.fields["use_autoconfig"] = forms.BooleanField(
label=_("Auto-configure"),
help_text=_("If selected, instances of a node group will be "
"automatically configured during cluster "
"creation. Otherwise you should manually specify "
"configuration values."),
required=False,
widget=forms.CheckboxInput(),
initial=True,
)
self.fields["proxygateway"] = forms.BooleanField(
text = ""
extra_context = extra_context or {}
if self.help_text_template:
tmpl = template.loader.get_template(self.help_text_template)
context = template.RequestContext(self.request, extra_context)
text += tmpl.render(context)
else:
text += defaultfilters.linebreaks(force_text(self.help_text))
return defaultfilters.safe(text)
class Meta(object):
name = _("Choose plugin type and version")
class ChooseJobTypeForm(forms.SelfHandlingForm):
guide_job_type = forms.ChoiceField(
label=_("Job Type"),
widget=forms.Select())
def __init__(self, request, *args, **kwargs):
super(ChooseJobTypeForm, self).__init__(request, *args, **kwargs)
self.help_text_template = ("project/data_processing.wizard/"
"_job_type_select_help.html")
self.fields["guide_job_type"].choices = \
self.populate_guide_job_type_choices()
def populate_guide_job_type_choices(self):
choices = [(x, helpers.JOB_TYPE_MAP[x][0])
for x in helpers.JOB_TYPE_MAP]
return choices