def build_widgets(self): title_text = Text([("body", self.name)], align="center") desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox(self.name, state=bool(self.current_value)) elif self.optype == OptionType.INT: self.control = IntEdit(caption="{}: ".format(self.name), default=self.current_value) elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor( caption="{}: ".format(self.name), edit_text=edit_text) else: raise Exception("Unknown option type") if self.optype == OptionType.STRING: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([self.reset_button], 36, 1, 0, 'right') return Pile([Divider(), title_text, desc_text, self.control, button_grid])
def __init__(self): super().__init__() self.auth_type = 'userpass' self.cloud_type = cloud_types.ORACLE self.form = Form([ Field(label='Identity Domain', widget=StringEditor(), key='identity-domain'), Field(label='Username or Email', widget=StringEditor(), key='username'), Field(label='Password', widget=PasswordEditor(), key='password') ])
def __init__(self): super().__init__() self.auth_type = 'userpass' self.cloud_type = cloud_types.VSPHERE self.form = Form([ Field(label='api endpoint', widget=StringEditor(), key='endpoint', storable=False), Field(label='user', widget=StringEditor(), key='user'), Field(label='password', widget=PasswordEditor(), key='password') ]) self._datacenters = None
def __init__(self): self.private_key = Field(label='private key', widget=StringEditor(), key='private-key') self.client_id = Field(label='client id', widget=StringEditor(), key='client-id') self.client_email = Field(label='client email', widget=StringEditor(), key='client-email') self.project_id = Field(label='project id', widget=StringEditor(), key='project-id')
def __init__(self): self.endpoint = Field(label='api endpoint', widget=StringEditor(), key='endpoint', storable=False) self.user = Field(label='user', widget=StringEditor(), key='user') self.password = Field(label='password', widget=PasswordEditor(), key='password') self.external_network = Field(label='external network', widget=StringEditor(), key='external-network', storable=False)
def __init__(self): self.sdc_user = Field(label='sdc user', widget=StringEditor(), key='sdc-user') self.sdc_key_id = Field(label='sdc key id', widget=StringEditor(), key='sdc-key-id') self.private_key = Field(label='private key', widget=StringEditor(), key='private-key') self.algorithm = Field(label='algorithm', widget=StringEditor(default='rsa-sha256'), key='algorithm')
def __init__(self): self.application_id = Field(label='application id', widget=StringEditor(), key='application-id') self.subscription_id = Field(label='subscription id', widget=StringEditor(), key='subscription-id') self.tenant_id = Field(label='tenant id', widget=StringEditor(), key='tenant-id') self.application_password = Field(label='application password', widget=PasswordEditor(), key='application-password')
def __init__(self): self.endpoint = Field( label='api endpoint (http://example.com:5240/MAAS)', widget=StringEditor(), key='endpoint', storable=False, validator=partial(self._has_correct_endpoint) ) self.apikey = Field( label='api key', widget=StringEditor(), key='maas-oauth', validator=partial(self._has_correct_api_key) )
def __init__(self): super().__init__() self.auth_type = 'oauth2' self.cloud_type = cloud_types.GCE self.form = Form([ Field(label='private key', widget=StringEditor(), key='private-key'), Field(label='client id', widget=StringEditor(), key='client-id'), Field(label='client email', widget=StringEditor(), key='client-email'), Field(label='project id', widget=StringEditor(), key='project-id') ])
def __init__(self): super().__init__() self.auth_type = 'userpass' self.cloud_type = cloud_types.JOYENT self.form = Form([ Field(label='sdc user', widget=StringEditor(), key='sdc-user'), Field(label='sdc key id', widget=StringEditor(), key='sdc-key-id'), Field(label='private key', widget=StringEditor(), key='private-key'), Field(label='algorithm', widget=StringEditor(default='rsa-sha256'), key='algorithm') ])
def __init__(self): super().__init__() self.auth_type = 'access-key' self.cloud_type = cloud_types.AWS self.access_key = None self.secret_key = None self.form = Form([ Field(label='AWS Access Key', widget=StringEditor(), key='access-key'), Field(label='AWS Secret Key', widget=StringEditor(), key='secret-key') ])
def __init__(self): super().__init__() self.auth_type = 'service-principal-secret' self.cloud_type = cloud_types.AZURE self.form = Form([ Field(label='application id', widget=StringEditor(), key='appnlication-id'), Field(label='subscription id', widget=StringEditor(), key='subscription-id'), Field(label='application password', widget=PasswordEditor(), key='application-password') ])
def __init__(self): super().__init__() self.auth_type = 'oauth1' self.cloud_type = cloud_types.MAAS self.form = Form([ Field(label='api endpoint (http://example.com:5240/MAAS)', widget=StringEditor(), key='endpoint', storable=False, validator=partial(self._has_correct_endpoint)), Field(label='api key', widget=StringEditor(), key='maas-oauth', validator=partial(self._has_correct_api_key)) ])
def build_widgets(self): desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox('', state=bool(self.current_value)) self.wrapped_control = self.control elif self.optype == OptionType.INT: self.control = IntEdit(default=self.current_value) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.FLOAT: edit_text = str(self.current_value) self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') else: raise Exception("Unknown option type") self.control_columns = Columns( [ ('pack', Text("{}:".format(self.name), align='right')), (80, self.wrapped_control) ], dividechars=1 ) if self.optype in [OptionType.STRING, OptionType.FLOAT]: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([ Color.button_secondary(self.reset_button, focus_map='button_secondary focus')], 36, 1, 0, 'right') return Pile([Padding.line_break(""), Padding.left(self.control_columns, left=1), Padding.left(desc_text, left=2), button_grid])
def __init__(self): self.identity_domain = Field( label='identity domain', widget=StringEditor(), key='identity-domain' ) self.username = Field( label='username or e-mail', widget=StringEditor(), key='username' ) self.password = Field( label='password', widget=PasswordEditor(), key='password' )
def __init__(self): super().__init__() self.auth_type = 'userpass' self.cloud_type = cloud_types.CLOUDSIGMA self.form = Form([ Field( label='Username', widget=StringEditor(), key='username' ), Field( label='Password', widget=StringEditor(), key='password' ) ])
def test_provider_form_query_key(self): "app_config.provider_form_widget_query_key" self.app.provider.form = Form( [Field(label='test widget', widget=StringEditor(default='hai2u'), key='test-key')]) assert self.app.provider.form.field('test-key').value == 'hai2u'
def __init__(self): super().__init__() self.auth_type = 'userpass' self.cloud_type = cloud_types.OPENSTACK self.form = Form([ Field(label='username', widget=StringEditor(), key='username'), Field(label='password', widget=PasswordEditor(), key='password'), Field(label='domain name', widget=StringEditor(), key='domain-name'), Field(label='project domain name', widget=StringEditor(), key='project-domain-name'), Field(label='access key', widget=StringEditor(), key='access-key'), Field(label='secret key', widget=StringEditor(), key='secret-key') ])
def __init__(self): self.username = Field(label='username', widget=StringEditor(), key='username') self.password = Field(label='password', widget=PasswordEditor(), key='password') self.domain_name = Field(label='domain name', widget=StringEditor(), key='domain-name') self.project_domain_name = Field(label='project domain name', widget=StringEditor(), key='project-domain-name') self.access_key = Field(label='access key', widget=StringEditor(), key='access-key') self.secret_key = Field(label='secret key', widget=StringEditor(), key='secret-key')
def __init__(self): self.endpoint = Field( label='api endpoint', widget=StringEditor(), key='endpoint', storable=False ) self.user = Field( label='user', widget=StringEditor(), key='user' ) self.password = Field( label='password', widget=PasswordEditor(), key='password' ) self.external_network = Field( label='external network', widget=SelectorHorizontal([ '10.0.0.1/24', '172.16.0.1/24']), key='external-network', storable=False ) self.internal_network = Field( label='virtual switch', widget=SelectorHorizontal([ 'VMNet1', 'VMNet1']), key='network', storable=False ) self.datasource = Field( label='datasource', widget=SelectorHorizontal([ 'VMStorage1', 'VMStorage2', 'VMStorage3']), key='datasource', storable=False )
def build_widgets(self): desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox('', state=bool(self.current_value)) self.wrapped_control = self.control elif self.optype == OptionType.INT: self.control = IntEdit(default=self.current_value) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') else: raise Exception("Unknown option type") self.control_columns = Columns( [('pack', Text("{}:".format(self.name), align='right')), (80, self.wrapped_control)], dividechars=1) if self.optype == OptionType.STRING: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([ Color.button_secondary(self.reset_button, focus_map='button_secondary focus') ], 36, 1, 0, 'right') return Pile([ Padding.line_break(""), Padding.left(self.control_columns, left=1), Padding.left(desc_text, left=2), button_grid ])
def __init__(self, app, step_model, cb): """ Arguments: step_model: step model step_model_widget: step model widget cb: callback """ self.app = app self.model = step_model self.title = Text(('info_minor', step_model.title)) self.description = Text(('info_minor', step_model.description)) self.result = Text(step_model.result) self.output = Text(('info_minor', '')) self.icon = Text(("info_minor", "\N{BALLOT BOX}")) self.additional_input = [] if len(step_model.additional_input) > 0: for i in step_model.additional_input: widget = { "label": Text(('body', i['label'])), "key": i['key'], "input": self.INPUT_TYPES.get(i['type']) } if 'default' in i: widget['input'] = StringEditor(default=i['default']) self.additional_input.append(widget) else: widget = { "label": Text(""), "key": "submit", "input": None } self.additional_input.append(widget) self.cb = cb self.step_pile = self.build_widget() self.show_output = True super().__init__(self.step_pile)
class OptionWidget(WidgetWrap): def __init__(self, name, optype, description, default, current_value=None, value_changed_callback=None): self.name = name self.optype = OptionType.__members__[optype.upper()] self.description = description self.default = default self.current_value = current_value or default w = self.build_widgets() self.value_changed_callback = value_changed_callback super().__init__(w) self.update() def selectable(self): return True def build_widgets(self): title_text = Text([("body", self.name)], align="center") desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox(self.name, state=bool(self.current_value)) elif self.optype == OptionType.INT: self.control = IntEdit(caption="{}: ".format(self.name), default=self.current_value) elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor( caption="{}: ".format(self.name), edit_text=edit_text) else: raise Exception("Unknown option type") if self.optype == OptionType.STRING: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([self.reset_button], 36, 1, 0, 'right') return Pile([Divider(), title_text, desc_text, self.control, button_grid]) def handle_value_changed(self, sender, value): self.current_value = value if self.optype == OptionType.INT: v = value if value not in ['', '-']: v = int(value) self.value_changed_callback(self.name, v) else: self.value_changed_callback(self.name, self.current_value) def do_reset(self, sender): self.current_value = str(self.default) if self.optype == OptionType.BOOLEAN: newstate = True if self.current_value == "True" else False self.control.state = newstate elif self.optype == OptionType.INT: edit_text = self.current_value or "" self.control.set_edit_text(edit_text) elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control.value = edit_text def update(self): pass
class StepWidget(WidgetWrap): INPUT_TYPES = { 'text': StringEditor(), 'password': PasswordEditor(), 'boolean': YesNo(), 'integer': IntegerEditor() } def __init__(self, app, step_model, cb): """ Arguments: step_model: step model step_model_widget: step model widget cb: callback """ self.app = app self.model = step_model self.title = Text(('info_minor', step_model.title)) self.description = Text(('info_minor', step_model.description)) self.result = Text(step_model.result) self.output = Text(('info_minor', '')) self.icon = Text(("info_minor", "\N{BALLOT BOX}")) self.additional_input = [] if len(step_model.additional_input) > 0: for i in step_model.additional_input: widget = { "label": Text(('body', i['label'])), "key": i['key'], "input": self.INPUT_TYPES.get(i['type']) } if 'default' in i: widget['input'] = StringEditor(default=i['default']) self.additional_input.append(widget) else: widget = {"label": Text(""), "key": "submit", "input": None} self.additional_input.append(widget) self.cb = cb self.step_pile = self.build_widget() self.show_output = True super().__init__(self.step_pile) def __repr__(self): return "<StepWidget: {}>".format(self.model.title) def update(self): if not self.show_output: return if not os.path.exists(self.model.path + ".out"): return with open(self.model.path + ".out") as outf: lines = outf.readlines() if len(lines) < 1: return result = json.loads(lines[-1]) self.output.set_text(('body', "\n " + result['message'])) def clear_output(self): self.output.set_text("") def set_description(self, description, color='info_minor'): self.description.set_text((color, description)) def set_icon_state(self, result_code): """ updates status icon Arguments: icon: icon widget result_code: 3 types of results, error, waiting, complete """ if result_code == "error": self.icon.set_text(("error_icon", "\N{BLACK FLAG}")) elif result_code == "waiting": self.icon.set_text(("pending_icon", "\N{HOURGLASS}")) elif result_code == "active": self.icon.set_text(("success_icon", "\N{BALLOT BOX WITH CHECK}")) else: # NOTE: Should not get here, if we do make sure we account # for that error type above. self.icon.set_text(("error_icon", "?")) @property def current_button_index(self): """ Returns the pile index where the button is located """ return len(self.step_pile.contents) - 2 @property def current_button_widget(self): """ Returns the current button widget """ if self.button: return self.button def clear_button(self): """ Clears current button so it can't be pressed again """ self.app.log.debug("Contents: {}".format( self.step_pile.contents[self.current_button_index])) self.step_pile.contents[self.current_button_index] = ( Text(""), self.step_pile.options()) def build_widget(self): return Pile([ Columns([ ('fixed', 3, self.icon), self.description, ], dividechars=1), self.output ]) def generate_additional_input(self): """ Generates additional input fields, useful for doing it after a previous step is run """ self.set_description(self.model.description, 'body') self.icon.set_text(('pending_icon', self.icon.get_text()[0])) for i in self.additional_input: self.app.log.debug(i) self.step_pile.contents.append( (Padding.line_break(""), self.step_pile.options())) column_input = [('weight', 0.5, Padding.left(i['label'], left=5))] if i['input']: column_input.append( ('weight', 1, Color.string_input(i['input'], focus_map='string_input focus'))) self.step_pile.contents.append( (Columns(column_input, dividechars=3), self.step_pile.options())) self.button = submit_btn(on_press=self.submit) self.step_pile.contents.append((Padding.right_20( Color.button_primary(self.button, focus_map='button_primary focus')), self.step_pile.options())) self.step_pile.contents.append((HR(), self.step_pile.options())) self.step_pile.focus_position = self.current_button_index def submit(self, btn): self.set_icon_state('waiting') self.clear_button() self.cb(self.model, self)
class OptionWidget(WidgetWrap): def __init__(self, name, optype, description, default, current_value=None, value_changed_callback=None): self.name = name self.optype = OptionType.__members__[optype.upper()] self.description = description self.default = default self.current_value = current_value or default w = self.build_widgets() self.value_changed_callback = value_changed_callback super().__init__(w) self.update() def selectable(self): return True def build_widgets(self): desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox('', state=bool(self.current_value)) self.wrapped_control = self.control elif self.optype == OptionType.INT: self.control = IntEdit(default=self.current_value) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') else: raise Exception("Unknown option type") self.control_columns = Columns( [ ('pack', Text("{}:".format(self.name), align='right')), (80, self.wrapped_control) ], dividechars=1 ) if self.optype == OptionType.STRING: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([ Color.button_secondary(self.reset_button, focus_map='button_secondary focus')], 36, 1, 0, 'right') return Pile([Padding.line_break(""), Padding.left(self.control_columns, left=1), Padding.left(desc_text, left=2), button_grid]) def handle_value_changed(self, sender, value): self.current_value = value if self.optype == OptionType.INT: v = value if value not in ['', '-']: v = int(value) self.value_changed_callback(self.name, v) else: self.value_changed_callback(self.name, self.current_value) def do_reset(self, sender): self.current_value = str(self.default) if self.optype == OptionType.BOOLEAN: newstate = True if self.current_value == "True" else False self.control.state = newstate elif self.optype == OptionType.INT: edit_text = self.current_value or "" self.control.set_edit_text(edit_text) elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control.value = edit_text def update(self): pass
"clouds` for more information.".format(cloud)) def load_schema(cloud): """ Loads a schema """ for s in Schema: k, v = s if cloud == k: return v() raise SchemaError(cloud) SchemaV1 = OrderedDict([ ('aws', OrderedDict([('_auth-type', 'access-key'), ('access-key', StringEditor()), ('secret-key', StringEditor())])), ('aws-china', OrderedDict([('_auth-type', 'access-key'), ('access-key', StringEditor()), ('secret-key', StringEditor())])), ('aws-gov', OrderedDict([('_auth-type', 'access-key'), ('access-key', StringEditor()), ('secret-key', StringEditor())])), ('maas', OrderedDict([('_auth-type', 'oauth1'), ('@maas-server', StringEditor()), ('maas-oauth', StringEditor())])), ('azure', OrderedDict([('_auth-type', 'userpass'), ('application-id', StringEditor()), ('subscription-id', StringEditor()), ('tenant-id', StringEditor()),
class OptionWidget(WidgetWrap): def __init__(self, name, optype, description, default, current_value=None, value_changed_callback=None): self.name = name self.optype = OptionType.__members__[optype.upper()] self.description = description self.default = default self.current_value = current_value or default w = self.build_widgets() self.value_changed_callback = value_changed_callback super().__init__(w) self.update() def selectable(self): return True def build_widgets(self): desc_text = Text(["\n", strip_solo_dots(self.description)]) self.reset_button = PlainButton("Reset to Default", self.do_reset) if self.optype == OptionType.BOOLEAN: self.control = CheckBox('', state=bool(self.current_value)) self.wrapped_control = self.control elif self.optype == OptionType.INT: self.control = IntEdit(default=self.current_value) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') elif self.optype == OptionType.FLOAT: edit_text = str(self.current_value) self.control = StringEditor(edit_text=edit_text) self.wrapped_control = Color.string_input( self.control, focus_map='string_input focus') else: raise Exception("Unknown option type") self.control_columns = Columns( [('pack', Text("{}:".format(self.name), align='right')), (80, self.wrapped_control)], dividechars=1) if self.optype in [OptionType.STRING, OptionType.FLOAT]: connect_signal(self.control._edit, 'change', self.handle_value_changed) else: connect_signal(self.control, 'change', self.handle_value_changed) button_grid = GridFlow([ Color.button_secondary(self.reset_button, focus_map='button_secondary focus') ], 36, 1, 0, 'right') return Pile([ Padding.line_break(""), Padding.left(self.control_columns, left=1), Padding.left(desc_text, left=2), button_grid ]) def handle_value_changed(self, sender, value): self.current_value = value if self.optype == OptionType.INT: v = value if value not in ['', '-']: v = int(value) self.value_changed_callback(self.name, v) elif self.optype == OptionType.FLOAT: try: v = float(value) except: pass else: self.value_changed_callback(self.name, v) else: self.value_changed_callback(self.name, self.current_value) def do_reset(self, sender): self.current_value = str(self.default) if self.optype == OptionType.BOOLEAN: newstate = True if self.current_value == "True" else False self.control.state = newstate elif self.optype == OptionType.INT: edit_text = self.current_value or "" self.control.set_edit_text(edit_text) elif self.optype == OptionType.STRING: edit_text = self.current_value or "" self.control.value = edit_text elif self.optype == OptionType.FLOAT: self.control.value = self.current_value def update(self): pass
from ubuntui.utils import Color, Padding from ubuntui.widgets.buttons import cancel_btn, confirm_btn from ubuntui.widgets.hr import HR from ubuntui.widgets.input import StringEditor, YesNo from ubuntui.widgets.text import Instruction # import os # Network format # # { key: (Widget, Help Text)} NETWORK = OrderedDict([ ('_USE_LXD_BRIDGE', (YesNo(), 'Use a new bridge')), ('LXD_BRIDGE', (StringEditor(default='lxdbr0'), 'Bridge name')), # ('_LXD_CONFILE', # (StringEditor(), # None)), ('LXD_DOMAIN', (StringEditor(default='lxd'), 'DNS domain for the bridge')), ('LXD_IPV4_ADDR', (StringEditor(default='10.10.0.1'), 'IPv4 Address (e.g. 10.10.0.1)')), ('LXD_IPV4_NETMASK', (StringEditor(default='255.255.255.0'), 'IPv4 netmask (e.g. 255.255.255.0)')), ('LXD_IPV4_NETWORK', (StringEditor(default='10.10.0.1/24'), 'IPv4 network (e.g. 10.10.0.1/24)')), ('LXD_IPV4_DHCP_RANGE', (StringEditor(default='10.10.0.2,10.10.0.254'), 'IPv4 DHCP range (e.g. 10.10.0.2,10.10.0.254)')), ('LXD_IPV4_DHCP_MAX', (StringEditor(default='250'), 'IPv4 DHCP number of hosts (e.g. 250)')), ('LXD_IPV4_NAT', (YesNo(), 'NAT IPv4 traffic'))