def build_widget(self): self.step_pile = pile = Pile([ Columns([ ('fixed', 3, self.icon), self.description, ], dividechars=1), Padding.line_break(""), Padding.push_4(self.output), ]) if utils.is_linux() and self.model.needs_sudo: pile.contents.append((Padding.line_break(""), pile.options())) label = 'This step requires sudo.' if not self.app.sudo_pass: label += ' Enter sudo password, if needed:' self.sudo_input = PasswordEditor() columns = [ ('weight', 0.5, Padding.left(Text(('body', label)), left=5)), ] if self.sudo_input: columns.append( ('weight', 1, Color.string_input(self.sudo_input, focus_map='string_input focus'))) pile.contents.append((Columns(columns, dividechars=3), pile.options()))
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.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): 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.application_password = Field(label='application password', widget=PasswordEditor(), key='application-password')
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 e-mail', 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.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): 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 = '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 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])) if utils.is_linux() and self.model.needs_sudo: self.step_pile.contents.append( (Padding.line_break(""), self.step_pile.options())) can_sudo = utils.can_sudo() label = 'This step requires sudo.' if not can_sudo: label += ' Please enter sudo password:'******'weight', 0.5, Padding.left(Text(('body', label)), left=5)), ] if not can_sudo: self.sudo_input = PasswordEditor() columns.append( ('weight', 1, Color.string_input(self.sudo_input, focus_map='string_input focus'))) self.step_pile.contents.append( (Columns(columns, dividechars=3), self.step_pile.options())) 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(label="Run", on_press=self.submit) self.step_pile.contents.append( (Padding.line_break(""), self.step_pile.options())) self.step_pile.contents.append((Text(""), self.step_pile.options())) self.step_pile.contents.append((HR(), self.step_pile.options())) self.show_button() self.step_pile.focus_position = self.current_button_index
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_sudo_field(self): if not utils.is_linux() or not self.model.needs_sudo: return [] rows = [] if not self.app.sudo_pass: self.sudo_input = PasswordEditor() self.clear_sudo_error() columns = [ ('weight', 0.5, Padding.left(self.sudo_label, left=5)), ] if self.sudo_input: columns.append( ('weight', 1, Filler(Color.string_input(self.sudo_input, focus_map='string_input focus'), valign='bottom'))) rows.extend([ Padding.line_break(""), Columns(columns, dividechars=3, box_columns=[1]), ]) return rows
('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()), ('application-password', PasswordEditor()), ('location', StringEditor()), ('endpoint', StringEditor()), ('storage-endpoint', StringEditor()), ('storage-account-type', StringEditor()), ('storage-account', StringEditor()), ('storage-account-key', StringEditor()), ('controller-resource-group', StringEditor())])), ('azure-china', OrderedDict([('_auth-type', 'userpass'), ('application-id', StringEditor()), ('subscription-id', StringEditor()), ('tenant-id', StringEditor()), ('application-password', PasswordEditor()), ('location', StringEditor()), ('endpoint', StringEditor()), ('storage-endpoint', StringEditor()), ('storage-account-type', 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()), ('application-password', PasswordEditor()), ('location', StringEditor()), ('endpoint', StringEditor()), ('storage-endpoint', StringEditor()), ('storage-account-type', StringEditor()), ('storage-account', StringEditor()), ('storage-account-key', StringEditor()), ('controller-resource-group', StringEditor()) ])), ('azure-china', OrderedDict([ ('_auth-type', 'userpass'), ('application-id', StringEditor()), ('subscription-id', StringEditor()), ('tenant-id', StringEditor()), ('application-password', PasswordEditor()), ('location', StringEditor()),
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)