def edit(request, id): try: maas = MAAS() domain = maas.get(f"domains/{id}/").json() form = EditDomainForm(request.POST or None, initial=domain) if form.is_valid(): resp = form.save(domain['id']) if resp.status_code in maas.ok: sweetify.sweetalert(request, 'Success', text=_('Successfully edited domain'), button='Ok', timer=2000) return redirect("maas:dns:index") sweetify.warning(request, _(resp.text), button='Ok', timer=2000) context = { 'title': 'Edit Domain', 'menu_active': 'domains', 'form': form, 'title_submit': 'Save Domain', 'col_size': '4' } except (MAASError, ConnectionError, TimeoutError) as e: sweetify.sweetalert(request, 'Warning', text=str(e), button='Ok', timer=5000) context = None return render(request, 'maas/form.html', context)
def index(request): try: if settings.WITH_EX_RESPONSE: domains = load_document('domains.json') else: maas = MAAS() domains = maas.get("domains/").json() machine_file = open("hujan_ui/maas/ex_response/domains.json", "w") json.dump(domains, machine_file) machine_file.close() context = { 'title': 'DNS', 'domains': domains, 'menu_active': 'domains', } except (MAASError, ConnectionError, TimeoutError) as e: sweetify.sweetalert(request, 'Warning', text=str(e), button='OK', timer=5000) context = None return render(request, 'maas/dns/index.html', context)
class AddMachineForm(forms.Form): hostname = forms.CharField(label='Machine name') domain = forms.ChoiceField() ARCHITECTURE = [ ('amd64/generic', 'amd64/generic'), ] architecture = forms.ChoiceField(choices=ARCHITECTURE) # minimum_kernel = forms.CharField() zone = forms.ChoiceField() resouce_pool = forms.ChoiceField() mac_addresses = forms.CharField(label='MAC Address') POWER_TYPE = [ # ('amt', 'Intel AMT'), # ('apc', 'American Power Conversion (APC) PDU'), # ('dli', 'Digital Loggers, Inc. PDU'), # ('fence_cdu', 'Sentry Switch CDU'), # ('hmc', 'IBM Hardware Management Console (HMC)'), ('ipmi', 'IPMI'), # ('moonshot', 'HP Moonshot - iLO4 (IPMI)'), # ('mscm', 'HP Moonshot - iLO Chassis Manager'), # ('msftocs', 'Microsoft OCS - Chassis Manager'), # ('nova', 'OpenStack Nova'), # ('nova', 'OpenStack Nova'), # ('openbmc', 'OpenBMC Power Driver'), # ('recs_box', 'Christmann RECS|Box Power Driver'), # ('redfish', 'Redfish'), # ('smk15k', 'SeaMicro 15000'), # ('ucsm', 'Cisco UCS Manager'), # ('virsh', 'Virsh (virtual systems)'), # ('vmware', 'VMware'), # ("wedge", "Facebook's Wedge"), # ("rsd", "Rack Scale Design"), # ('vmware', 'VMware'), # TODO : a temporary comment because the machine only supports IPMI types ] power_type = forms.ChoiceField(choices=POWER_TYPE, initial=POWER_TYPE[0][0]) def __init__(self, *args, **kwargs): self.maas = MAAS() super().__init__(*args, **kwargs) self.fields['domain'].choices = self.get_choices_domains() self.fields['zone'].choices = self.get_choices_zones() self.fields['resouce_pool'].choices = self.get_choices_resourcepools() def get_choices_zones(self): resp = self.maas.get(f"/zones/").json() return [ (zone['name'], zone['name']) for zone in resp ] def get_choices_domains(self): resp = self.maas.get(f"/domains/").json() return [ (domain['name'], domain['name']) for domain in resp ] def get_choices_resourcepools(self): resp = self.maas.get(f"/resourcepools/").json() return [ (resource['name'], resource['name']) for resource in resp ]