Exemplo n.º 1
0
class TabNotifier(Tab):

    def __init__(self, main_loop):
        self.main_loop = main_loop
        self.name = u"Notifier"
        self.notifier_conf_file = "/etc/ovirt-engine/notifier/notifier.conf.d/20-notifier.conf"
        self.mail_server_key = "MAIL_SERVER"
        self.mail_user_key = "MAIL_USER"
        self.mail_pass_key = "MAIL_PASSWORD"
        self.encryption_key = "MAIL_SMTP_ENCRYPTION"
        self.mail_from_key = "MAIL_FROM"
        self.widget = SimplePopupLauncher(self.load_entries())

    def load_entries(self):
        notifier_conf = {}
        try:
            with open(self.notifier_conf_file) as f:
                for line in f.readlines():
                    if not line.strip():
                        continue
                    if line.startswith("#"):
                        continue
                    items = line.split("=")
                    if len(items) != 2:
                        continue
                    notifier_conf[items[0]] = items[1].rstrip()
        except IOError:
            pass
        self.w_mail_server = urwid.Edit("Mail SMTP server: ", notifier_conf.get(self.mail_server_key, ""))
        self.w_mail_user = urwid.Edit("Authentication user account: ", notifier_conf.get(self.mail_user_key, ""))
        self.w_mail_pass = urwid.Edit("Authentication user password: "******""), mask="*")
        self.w_mail_from = urwid.Edit("Mail sender account: ", notifier_conf.get(self.mail_from_key, ""))
        self.encryption_option_list = []
        self.w_encryption = self.genRadioButton(
            "Mail server encryption: ",
            [("none", None), ("ssl", None), ("tls", None)],
            self.encryption_option_list)
        self.set_radio_option(self.encryption_option_list, notifier_conf.get(self.encryption_key, ""))
        return urwid.Pile([
            self.w_mail_server,
            self.w_mail_user,
            self.w_mail_pass,
            self.w_mail_from,
            self.w_encryption,
            urwid.Divider(),
            urwid.Button("Save", on_press=self.save),
        ])

    def save(self, button):
        with open(self.notifier_conf_file,"w") as f:
            f.write("MAIL_SERVER=%s\n" % self.w_mail_server.edit_text.strip())
            f.write("MAIL_USER=%s\n" % self.w_mail_user.edit_text.strip())
            f.write("SENSITIVE_KEYS=\"${SENSITIVE_KEYS},MAIL_PASSWORD\"\n")
            f.write("MAIL_PASSWORD=%s\n" % self.w_mail_pass.edit_text.strip())
            f.write("MAIL_SMTP_ENCRYPTION=%s\n" % self.get_radio_option(self.encryption_option_list))
            f.write("MAIL_FROM=%s\n" % self.w_mail_from.edit_text.strip())
            f.write("HTML_MESSAGE_FORMAT=true\n")
        os.system("service ovirt-engine-notifier restart")
        self.widget.set_popup_text("Configuration finished.")
        self.widget.open_pop_up()
Exemplo n.º 2
0
class TabNFS(object):

    def __init__(self, main_loop):
        self.main_loop = main_loop
        self.name = u"NFS Config"
        self.exports_file = "/etc/exports"
        self.w_entries = self.load_entries()
        self.widget = SimplePopupLauncher(self.get_entry_widget())

    def load_entries(self):
        widget_lines = []
        with open(self.exports_file) as f:
            for line in f.readlines():
                if not line.strip():
                    continue
                items = line.split()
                widget_items = [urwid.Edit("Path: ", items[0]), urwid.Edit("Param: ", items[1])]
                widget_items.append(urwid.Button("Delete", on_press=self.delete_line, user_data=widget_items))
                widget_lines.append(widget_items)
        return widget_lines

    def delete_line(self, button, line):
        self.w_entries.remove(line)
        self.widget.original_widget = self.get_entry_widget()
        self.widget.original_widget.focus_position = max(0, len(self.w_entries)-1)

    def get_entry_widget(self):
        pile = urwid.Pile([
            urwid.Columns(entry) for entry in self.w_entries
        ])
        pile.contents.append((urwid.Button("New", on_press=self.new), ('pack', None)))
        pile.contents.append((urwid.Button("Save", on_press=self.save), ('pack', None)))
        return pile

    def new(self, button):
        widget_items = [urwid.Edit("Path: ", ""), urwid.Edit("Param: ", "*(rw)")]
        widget_items.append(urwid.Button("Delete", on_press=self.delete_line, user_data=widget_items))
        self.w_entries.append(widget_items)
        self.widget.original_widget = self.get_entry_widget()
        self.widget.original_widget.focus_position = len(self.w_entries)

    def save(self, button):
        f = open(self.exports_file,"w")
        for entry in self.w_entries:
            path = entry[0].edit_text.strip()
            param = entry[1].edit_text.strip()
            if path and param:
                os.system("chkconfig nfs-server on &>/dev/null")
                f.write("%s %s\n" % (path, param))
                os.system("mkdir -p %s" % path)
                os.system("chown -R vdsm:kvm %s" % path)
        f.close()
        os.system("service nfs start &>/dev/null")
        os.system("exportfs -r")
        self.widget.set_popup_text("Save success.")
        self.widget.open_pop_up()
Exemplo n.º 3
0
 def __init__(self, main_loop):
     self.main_loop = main_loop
     self.name = u"Notifier"
     self.notifier_conf_file = "/etc/ovirt-engine/notifier/notifier.conf.d/20-notifier.conf"
     self.mail_server_key = "MAIL_SERVER"
     self.mail_user_key = "MAIL_USER"
     self.mail_pass_key = "MAIL_PASSWORD"
     self.encryption_key = "MAIL_SMTP_ENCRYPTION"
     self.mail_from_key = "MAIL_FROM"
     self.widget = SimplePopupLauncher(self.load_entries())
Exemplo n.º 4
0
class TabIOMMU(object):

    def __init__(self, main_loop):
        self.main_loop = main_loop
        self.name = u"IOMMU Config"
        self.widget = SimplePopupLauncher(self.get_widget())

    def get_widget(self):
        if os.system("cat /etc/default/grub|grep iommu &>/dev/null"):
            return urwid.Pile([
                urwid.Text(u"IOMMU is disabled."),
                urwid.Button(u"Enable IOMMU", on_press=self.enable_iommu)
            ])
        else:
            return urwid.Pile([
                urwid.Text(u"IOMMU is enabled."),
                urwid.Button(u"Disable IOMMU", on_press=self.disable_iommu)
            ])

    def disable_iommu(self, button):
        os.system("sed -i 's/intel_iommu=on//g' /etc/default/grub")
        os.system("sed -i 's/amd_iommu=on//g' /etc/default/grub")
        os.system("sed -i 's/[ \t]*$//' /etc/default/grub")
        os.system("sed -i 's/[ \t]*\"$/\"/' /etc/default/grub")
        self.apply_grub_config()

    def enable_iommu(self, button):
        if os.system("cat /etc/default/grub|grep iommu &>/dev/null"):
            os.system("sed -i 's/[ \t]*$//' /etc/default/grub")
            os.system("sed -i '/^GRUB_CMDLINE_LINUX/ s/\"$/ intel_iommu=on\"/' /etc/default/grub")
            os.system("sed -i '/^GRUB_CMDLINE_LINUX/ s/\"$/ amd_iommu=on\"/' /etc/default/grub")
        self.apply_grub_config()

    def apply_grub_config(self):
        os.system("grub2-mkconfig -o /boot/grub2/grub.cfg")
        self.widget.set_popup_text("Config success! Please reboot the system to let the config take effect.")
        self.widget.open_pop_up()
Exemplo n.º 5
0
 def __init__(self, main_loop):
     self.main_loop = main_loop
     self.name = u"NFS Config"
     self.exports_file = "/etc/exports"
     self.w_entries = self.load_entries()
     self.widget = SimplePopupLauncher(self.get_entry_widget())
Exemplo n.º 6
0
 def __init__(self, main_loop):
     self.main_loop = main_loop
     self.name = u"IOMMU Config"
     self.widget = SimplePopupLauncher(self.get_widget())
Exemplo n.º 7
0
class TabNeutron(Tab):

    def __init__(self, main_loop):
        self.main_loop = main_loop
        self.name = u"Neutron Deploy"
        self.vm_name = "NeutronAppliance"
        self.widget = SimplePopupLauncher(self.get_pass())

    def get_pass(self):
        self.w_password = urwid.Edit(u"Please enter admin@internal password to procceed: ", mask="*")
        return urwid.Columns([
            ('weight', 4, self.w_password),
            ('weight', 1, urwid.Button(u"GO", on_press=self.on_pass))
        ])

    def on_pass(self, button):
        self.api = API(url='https://127.0.0.1/api',
            username='******',
            password=self.w_password.edit_text.encode("ascii", "ignore"),
            insecure=True)
        if not self.api.vms.get(name=self.vm_name) == None:
            self.widget.set_popup_text("Vm named '%s' exists, please remove or rename it and try again" % self.vm_name)
            self.widget.open_pop_up()
            return

        divider = urwid.Divider("-")
        self.w_mgmt_profile = VnicProfileSelector(self.api, True, self.vnic_profile_changed_mgmt)
        self.w_int_profile = VnicProfileSelector(self.api, True, self.vnic_profile_changed_int)
        self.w_int_profile.set_ip_info(False)
        self.w_ext_profile = VnicProfileSelector(self.api, False, None)
        self.w_vm_pass = urwid.Edit(u"vm root password: "******"*")
        self.w_keystone_pass = urwid.Edit(u"keystone admin password: "******"*")
        self.widget.original_widget = urwid.Pile([
            urwid.Text(u"Deploying neutron appliance under datacenter 'Default'"),
            divider,
            urwid.Text("Choose profile for management network:"),
            self.w_mgmt_profile,
            divider,
            urwid.Text("Choose profile for internal network:"),
            self.w_int_profile,
            divider,
            urwid.Text("Choose profile for external network:"),
            self.w_ext_profile,
            divider,
            self.w_vm_pass,
            self.w_keystone_pass,
            divider,
            urwid.Button(u"OK", on_press=self.begin_deploy)
        ])

    def vnic_profile_changed_mgmt(self, button, selected):
        if selected:
            if self.w_mgmt_profile.get_vnic_profile_id_by_name(button.get_label()) == self.w_int_profile.get_vnic_profile_id():
                self.w_int_profile.set_ip_info(False)
            else:
                self.w_int_profile.set_ip_info(True)

    def vnic_profile_changed_int(self, button, selected):
        if selected:
            if self.w_mgmt_profile.get_vnic_profile_id() == self.w_int_profile.get_vnic_profile_id_by_name(button.get_label()):
                self.w_int_profile.set_ip_info(False)
            else:
                self.w_int_profile.set_ip_info(True)

    def begin_deploy(self, button):
        conf_widget = self.widget.original_widget
        self.output = urwid.Text("")
        widget = urwid.BoxAdapter(urwid.Frame(
            header=urwid.Text("Setup output:"),
            body=urwid.Filler(self.output, valign="bottom"),
            footer=urwid.Button("percentage"),
            focus_part="header"), 20)
        widget.set_focus("footer")
        self.widget.original_widget = widget

        self.log(u"Detecting ip conflicts...")
        conflict = True
        conflict_ip = self.w_mgmt_profile.w_ip.edit_text
        if os.system("arping %s -w 10" % conflict_ip):
            conflict = False
        elif not self.mgmt_int_same():
            conflict_ip = self.w_int_profile.w_ip.edit_text
            if os.system("arping %s -w 10" % conflict_ip):
                conflict = False
        if conflict:
            self.widget.set_popup_text("IP address %s is already used, please configure a unused IP address." % conflict_ip)
            self.widget.open_pop_up()
            self.widget.original_widget = conf_widget
            return

        self.log(u"Begin neutron appliance deploy")
        self.add_vm()
        self.add_external_provider()
        self.configure_uiplugin()
        self.configure_httpd()
        self.log(u"Neutron appliance deploy finished, please REFRESH your webadmin page")
        self.api.disconnect()

    def log(self, text):
        self.output.set_text(self.output.text + text + "\n")
        self.main_loop.draw_screen()

    def mgmt_int_same(self):
        return self.w_mgmt_profile.get_vnic_profile_id() == self.w_int_profile.get_vnic_profile_id()

    def add_vm(self):
        mgmt_int_same = self.mgmt_int_same()
        template_name = "Neutron_Appliance_Template"
        nics = []
        nics.append(params.NIC(
            name="eth0",
            boot_protocol="STATIC",
            on_boot=True,
            network=params.Network(
                ip=params.IP(
                    address=self.w_mgmt_profile.w_ip.edit_text,
                    netmask=self.w_mgmt_profile.w_netmask.edit_text,
                    gateway=self.w_mgmt_profile.w_gateway.edit_text,
                )
            )
        ))
        if not mgmt_int_same:
            nics.append(params.NIC(
                name="eth2",
                boot_protocol="STATIC",
                on_boot=True,
                network=params.Network(
                    ip=params.IP(
                        address=self.w_int_profile.w_ip.edit_text,
                        netmask=self.w_int_profile.w_netmask.edit_text,
                        gateway=self.w_int_profile.w_gateway.edit_text,
                    )
                )
            ))
        nics.append(params.NIC(
            name="eth1",
            boot_protocol="NONE",
            on_boot=True,
        ))
        vm=params.VM(
            name=self.vm_name,
            cluster=self.api.clusters.get(name="Default"),
            template=self.api.templates.get(name=template_name),
        )
        self.log(u"Adding neutron vm")
        self.api.vms.add(vm)
        self.log(u"Neutron vm added successflly")
        self.api.vms.get(self.vm_name).nics.add(params.NIC(
            name='eth0',
            vnic_profile=params.VnicProfile(id=self.w_mgmt_profile.get_vnic_profile_id()),
            interface='virtio'
        ))
        self.log("NIC 'eth0' added to neutron vm as management network")
        self.api.vms.get(self.vm_name).nics.add(params.NIC(
            name='eth1',
            vnic_profile=params.VnicProfile(id=self.w_ext_profile.get_vnic_profile_id()),
            interface='virtio'
        ))
        self.log("NIC 'eth1' added to neutron vm as external network")
        if not mgmt_int_same:
            self.api.vms.get(self.vm_name).nics.add(params.NIC(
                name='eth2',
                vnic_profile=params.VnicProfile(id=self.w_int_profile.get_vnic_profile_id()),
                interface='virtio'
            ))
            self.log("NIC 'eth2' added to neutron vm as internal network")

        cloud_init_content = """runcmd:
 - sed -i 's/ServerAlias 127.0.0.1/ServerAlias %s/' /etc/httpd/conf.d/15-horizon_vhost.conf
 - sed -i 's/local_ip =127.0.0.1/local_ip = %s/' /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini
 - sed -i 's/#CSRF_COOKIE_SECURE/CSRF_COOKIE_SECURE/' /etc/openstack-dashboard/local_settings
 - sed -i 's/#SESSION_COOKIE_SECURE/SESSION_COOKIE_SECURE/' /etc/openstack-dashboard/local_settings
 - service httpd restart
 - mysql neutron --execute="delete from ml2_gre_endpoints where ip_address='127.0.0.1'"
 - service neutron-openvswitch-agent restart
 - chkconfig cloud-init off
 - source /root/keystonerc_admin
 - keystone user-password-update --pass %s admin
 - sed -i '/^export OS_PASSWORD/c\export OS_PASSWORD=%s' /root/keystonerc_admin""" % (
                self.w_mgmt_profile.w_ip.edit_text,
                self.w_mgmt_profile.w_ip.edit_text if mgmt_int_same else self.w_int_profile.w_ip.edit_text,
                self.w_keystone_pass.edit_text,
                self.w_keystone_pass.edit_text,
            )

        initialization=params.Initialization(
            cloud_init=params.CloudInit(
                host=params.Host(address="localhost"),
                regenerate_ssh_keys=True,
                users=params.Users(
                    user=[params.User(user_name="root", password=self.w_vm_pass.edit_text)]
                    ),
                network_configuration=params.NetworkConfiguration(
                    nics=params.Nics(nic=nics)
                ),
                files=params.Files(
                    file=[params.File(name="/tmp/setup", type_="PLAINTEXT", content=cloud_init_content,)]
                )
            )
        )
        self.log("Wait for vm to be created...")
        created = False
        while not created:
            time.sleep(10)
            if "down" == self.api.vms.get(name=self.vm_name).status.state:
                created = True
        self.log("Starting vm...")
        vm = self.api.vms.get(name=self.vm_name)
        vm.start(
            action=params.Action(
                use_cloud_init=True,
                vm=params.VM(
                    initialization=initialization
                )
            )
        )

    def add_external_provider(self):
        external_provider_name = "neutron-appliance"
        if not self.api.openstacknetworkproviders.get(name=external_provider_name) == None:
            self.log("Removing existing external provider: %s ..." % external_provider_name)
            self.api.openstacknetworkproviders.get(name=external_provider_name).delete()
        self.log(u"Adding external provider...")
        agent_configuration = params.AgentConfiguration(
            network_mappings='vmnet:br-tun',
            broker_type='rabbit_mq',
            address=self.w_mgmt_profile.w_ip.edit_text,
            port=5672,
            username='******',
            password='******',
        )
        self.api.openstacknetworkproviders.add(params.OpenStackNetworkProvider(
            name=external_provider_name,
            description='auto created by eayunos',
            url='http://%s:9696' % self.w_mgmt_profile.w_ip.edit_text,
            requires_authentication=True,
            username='******',
            password=self.w_password.edit_text.encode("ascii", "ignore"),
            authentication_url='http://%s:5000/v2.0/' % self.w_mgmt_profile.w_ip.edit_text,
            tenant_name='admin',
            plugin_type='OPEN_VSWITCH',
            agent_configuration=agent_configuration,
        ))
        self.log(u"External provider added successfully")

    def configure_uiplugin(self):
        os.system("ln -nsf /usr/share/neutron-uiplugin/neutron-resources /usr/share/ovirt-engine/ui-plugins/neutron-resources")
        os.system("ln -nsf /usr/share/neutron-uiplugin/neutron.json /usr/share/ovirt-engine/ui-plugins/neutron.json")
        self.log("Neutron uiplugin configured")

    def configure_httpd(self):
        content = """ProxyPass "/dashboard" "http://{IP}/dashboard"
ProxyPassReverse "/dashboard" "http://{IP}/dashboard"
ProxyPass "/static" "http://{IP}/static"
ProxyPassReverse "/static" "http://{IP}/static"
""".replace("{IP}", self.w_mgmt_profile.w_ip.edit_text)
        with open("/etc/httpd/conf.d/z-neutron.conf", "w") as f:
            f.write(content)
        self.log("Restarting httpd service")
        os.system("service httpd restart")
        self.log("Httpd reverse proxy configured")
Exemplo n.º 8
0
 def __init__(self, main_loop):
     self.main_loop = main_loop
     self.name = u"Neutron Deploy"
     self.vm_name = "NeutronAppliance"
     self.widget = SimplePopupLauncher(self.get_pass())