Beispiel #1
0
def _genNetwork():
    networkChoice = userchoices.getCosNetwork()
    nicChoice = userchoices.getCosNICs()[0]

    flags = ""

    flags += " --addvmportgroup=%s" % \
        str(userchoices.getAddVmPortGroup()).lower()
    
    flags += " --device=%s" % nicChoice['device'].name
    if nicChoice['vlanID']:
        flags += " --vlanid=%s" % nicChoice['vlanID']

    if nicChoice['bootProto'] == userchoices.NIC_BOOT_DHCP:
        flags += " --bootproto=dhcp"
    else:
        flags += " --bootproto=static"
        flags += " --ip=%s" % nicChoice['ip']
        flags += " --netmask=%s" % nicChoice['netmask']
        flags += " --gateway=%s" % networkChoice['gateway']
        if networkChoice['nameserver1']:
            # can be unset in a static setup.
            flags += " --nameserver=%s" % networkChoice['nameserver1']
            if networkChoice['nameserver2']:
                flags += ",%s" % networkChoice['nameserver2']
        if networkChoice['hostname']:
            flags += " --hostname=%s" % networkChoice['hostname']

    return "network%s\n" % flags
Beispiel #2
0
def _genNetwork():
    networkChoice = userchoices.getCosNetwork()
    nicChoice = userchoices.getCosNICs()[0]

    flags = ""

    flags += " --addvmportgroup=%s" % \
        str(userchoices.getAddVmPortGroup()).lower()

    flags += " --device=%s" % nicChoice['device'].name
    if nicChoice['vlanID']:
        flags += " --vlanid=%s" % nicChoice['vlanID']

    if nicChoice['bootProto'] == userchoices.NIC_BOOT_DHCP:
        flags += " --bootproto=dhcp"
    else:
        flags += " --bootproto=static"
        flags += " --ip=%s" % nicChoice['ip']
        flags += " --netmask=%s" % nicChoice['netmask']
        flags += " --gateway=%s" % networkChoice['gateway']
        if networkChoice['nameserver1']:
            # can be unset in a static setup.
            flags += " --nameserver=%s" % networkChoice['nameserver1']
            if networkChoice['nameserver2']:
                flags += ",%s" % networkChoice['nameserver2']
        if networkChoice['hostname']:
            flags += " --hostname=%s" % networkChoice['hostname']

    return "network%s\n" % flags
Beispiel #3
0
    def start(self):
        "Fetch initial COS NIC and network from userchoices."

        # userchoices.getCosNICS() returns a list of dicts.
        # It probably should have been a single (possibly empty) dict.
        cosnics = userchoices.getCosNICs()
        if cosnics:
            self.nic = cosnics[0]

        # Get existing COS network from userchoices.
        self.net = userchoices.getCosNetwork()

        self.setSubstepEnv({'next': self.askCosNic })
    def getNext(self, *args):
        """Tell userchoices what choices were made on this screen.
        
           You can assign more than one NIC to the COS from scripted install,
           but not from the GUI installer.
        """
        assert len(userchoices.getVmkNICs()) <= 1, \
               "Found more than one Vmk nic in userchoices."

        if userchoices.getVmkNICs():
            userchoices.delVmkNIC(userchoices.getVmkNICs()[0])

        if self.nicSetup.getDevice() in userchoices.getCosNICDevices():
            window = \
                MessageWindow(self.thisWindow, "iSCSI network adapter",
                "You have already assigned this network interface to the\n"
                "management console.  Are you sure you would like to do that?",
                "okcancel")
            if not window.affirmativeResponse:
                return

            cosNIC = userchoices.getCosNICs()[0]
            cosNet = userchoices.getCosNetwork()
            userchoices.setVmkNetwork(cosNet["gateway"])
            userchoices.addVmkNIC(device=cosNIC["device"],
                                  vlanID=cosNIC["vlanID"],
                                  bootProto=cosNIC["bootProto"],
                                  ip=cosNIC["ip"],
                                  netmask=cosNIC["netmask"])
        else:
            try:
                if self.networkAddressWidgets.getUsingDHCP():
                    bootProto = userchoices.NIC_BOOT_DHCP
                    ipSettings = self.networkAddressWidgets.testIPSettings([])
                else:
                    bootProto = userchoices.NIC_BOOT_STATIC
                    tests = ["ip", "netmask", "gateway"]
                    ipSettings = self.networkAddressWidgets.testIPSettings(
                        tests)

                userchoices.setVmkNetwork(ipSettings["gateway"])
                userchoices.addVmkNIC(device=self.nicSetup.getDevice(),
                                      vlanID=self.nicSetup.getVlanID(),
                                      bootProto=bootProto,
                                      ip=ipSettings["ip"],
                                      netmask=ipSettings["netmask"])
            except exception.StayOnScreen:
                self.parent.response(DialogResponses.STAYONSCREEN)
                return

        self.parent.response(DialogResponses.NEXT)
Beispiel #5
0
    def getNext(self, *args):
        """Tell userchoices what choices were made on this screen.
        
           You can assign more than one NIC to the COS from scripted install,
           but not from the GUI installer.
        """
        assert len(userchoices.getVmkNICs()) <= 1, \
               "Found more than one Vmk nic in userchoices."

        if userchoices.getVmkNICs():
            userchoices.delVmkNIC(userchoices.getVmkNICs()[0])

        if self.nicSetup.getDevice() in userchoices.getCosNICDevices():
            window = \
                MessageWindow(self.thisWindow, "iSCSI network adapter",
                "You have already assigned this network interface to the\n"
                "management console.  Are you sure you would like to do that?",
                "okcancel")
            if not window.affirmativeResponse:
                return

            cosNIC = userchoices.getCosNICs()[0]
            cosNet = userchoices.getCosNetwork()
            userchoices.setVmkNetwork(cosNet["gateway"])
            userchoices.addVmkNIC(device=cosNIC["device"],
                                  vlanID=cosNIC["vlanID"],
                                  bootProto=cosNIC["bootProto"],
                                  ip=cosNIC["ip"],
                                  netmask=cosNIC["netmask"])
        else:
            try:
                if self.networkAddressWidgets.getUsingDHCP():
                    bootProto = userchoices.NIC_BOOT_DHCP
                    ipSettings = self.networkAddressWidgets.testIPSettings([])
                else:
                    bootProto = userchoices.NIC_BOOT_STATIC
                    tests = ["ip", "netmask", "gateway"]
                    ipSettings = self.networkAddressWidgets.testIPSettings(tests)

                userchoices.setVmkNetwork(ipSettings["gateway"])
                userchoices.addVmkNIC(device=self.nicSetup.getDevice(),
                                      vlanID=self.nicSetup.getVlanID(),
                                      bootProto=bootProto,
                                      ip=ipSettings["ip"],
                                      netmask=ipSettings["netmask"])
            except exception.StayOnScreen:
                self.parent.response(DialogResponses.STAYONSCREEN)
                return

        self.parent.response(DialogResponses.NEXT)
Beispiel #6
0
    def selectNetConfigMethod(self):

        methods = {
            'dhcp': {
                'name': 'DHCP',
                'describe': 'automatic DHCP settings',
                'substep': self.updateDHCPMethod,
            },
            'staticip': {
                'name': 'static IP',
                'describe': 'static IP network settings',
                'substep': self.askStaticIP,
            },
        }

        # Get existing config method
        self.net = userchoices.getCosNetwork()

        if self.nic['bootProto'] == userchoices.NIC_BOOT_DHCP:
            currMethod = 'dhcp'
            newMethod = 'staticip'
        else:
            currMethod = 'staticip'
            newMethod = 'dhcp'
        textArgs = {
            'currName': methods[currMethod]['name'],
            'currDescribe': methods[currMethod]['describe'],
            'newDescribe': methods[newMethod]['describe'],
        }

        ui = {
            'title': titleSettings,
            'body': selectNetConfigMethodText % textArgs,
            'menu': {
                '1': methods[currMethod]['substep'],
                '2': methods[newMethod]['substep'],
                '<': self.askCosNic,
                '?': self.help,
            }
        }

        self.setSubstepEnv(ui)
Beispiel #7
0
def reviewNetwork(values, networkType):
    """
    networkType is either 'cos' or 'vmk'.

    Used by reviewCosNetwork() and reviewIscsi()
    """
    if networkType == 'cos':
        nics = userchoices.getCosNICs()
        net = userchoices.getCosNetwork()
        xtraNetItems = ('gateway', 'nameserver1', 'nameserver2', 'hostname')
    elif networkType == 'vmk':
        nics = userchoices.getVmkNICs()
        net = userchoices.getVmkNetwork()
        xtraNetItems = ('gateway',)
    else:
        raise ValueError("Illegal arg to reviewNetwork")

    for nic in nics:
        values[networkType + 'Nic'] = htmlEscape(str(nic['device'].name))
        if nic['vlanID']:
            values[networkType + 'VlanID'] = str(nic['vlanID'])
        else:
            values[networkType + 'VlanID'] = '(none)'

        if nic['bootProto'] == 'static':
            values['ip'] = nic['ip']
            values['netmask'] = nic['netmask']
            for value in ['gateway', 'nameserver1', 'nameserver2', 'hostname']:
                if not net[value]:
                    values[value] = '(none)'
                else:
                    values[value] = net[value]
            
            values[networkType + 'NetworkTemplate'] = \
                STATIC_NET_TEMPLATE % values
        else:
            values[networkType + 'NetworkTemplate'] = \
                DHCP_NET_TEMPLATE % values
            # %postinstall script
            log.warn('Could not bring up network for NIC %s with IP Config %s'
                     % (pNic, ipConf))
            log.warn('Exception message: %s' % ex.GetMessage())
        else:
            if not firstSuccessfullyEnabledVNic:
                firstSuccessfullyEnabledVNic = vNic

    # Fix the device naming
    _netInfo.RestorePnics()

    # setHostWideUserchoices must go *after* disconnectDownloadNetwork, as
    # ifdown can clobber /etc/resolv.conf.  It must also go after any static
    # IP addresses have been set, because setting the hostname relies on
    # them existing.
    choices = userchoices.getCosNetwork()
    if choices:
        setHostWideUserchoices(choices)
        if choices['gateway']:
            import host_config # avoid circular imports
            try:
                # If we were able to successfully bring up a vNic, then that's 
                # the one we should use for routing.  If we didn't bring one up
                # then just call activateGatewayRouting with no args and trust
                # that it will do the right thing.
                if firstSuccessfullyEnabledVNic:
                    args = [firstSuccessfullyEnabledVNic.name]
                else:
                    args = []
                host_config.config.activateGatewayRouting(*args)
            except WrappedVmkctlException, ex: