Ejemplo n.º 1
0
    def __init__(self, save_only=False, managed_iface=None):
        self.save_only = save_only
        self.footer = None
        self.frame = None
        self.screen = None
        self.dns_might_have_changed = False
        self.managediface = managed_iface or network.get_physical_ifaces()[0]
        # Set to true to move all settings to end
        self.globalsave = True
        # Tasks to be executed on Apply
        self.apply_tasks = set()
        self.version = utils.get_fuel_version()

        # settings load
        self.settings = settings_module.Settings()

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs={"mos_version": self.version})

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs={"mos_version": self.version})

        self.main()
        self.choices = []
Ejemplo n.º 2
0
 def test_get_fuel_version(self):
     output = 'abc.xyz'
     with patch('__builtin__.open',
                mock.mock_open(read_data=output),
                create=True):
         data = utils.get_fuel_version()
         self.assertEqual(output, data)
Ejemplo n.º 3
0
    def __init__(self, save_only=False, managed_iface=None):
        self.save_only = save_only
        self.footer = None
        self.frame = None
        self.screen = None
        self.dns_might_have_changed = False
        self.managediface = managed_iface or network.get_physical_ifaces()[0]
        # Set to true to move all settings to end
        self.globalsave = True
        # Tasks to be executed on Apply
        self.apply_tasks = set()
        self.version = utils.get_fuel_version()
        self.codename = 'xenial'

        # settings load
        self.settings = settings_module.Settings()

        template_kwargs = {
            "mos_version": self.version,
            "codename": self.codename,
        }

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs=template_kwargs)

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs=template_kwargs)

        self.main()
        self.choices = []
Ejemplo n.º 4
0
 def test_get_fuel_version_with_exc(self):
     with patch(
             '__builtin__.open',
             mock.mock_open(),
             create=True
     ) as mocked_open:
         mocked_open.side_effect = IOError()
         data = utils.get_fuel_version()
         self.assertEqual("", data)
Ejemplo n.º 5
0
 def test_get_fuel_version(self):
     output = 'abc.xyz'
     with patch(
             '__builtin__.open',
             mock.mock_open(read_data=output),
             create=True
     ):
         data = utils.get_fuel_version()
         self.assertEqual(output, data)
Ejemplo n.º 6
0
    def __init__(self):
        self.footer = None
        self.frame = None
        self.screen = None
        self.managediface = network.get_physical_ifaces()[0]
        # Set to true to move all settings to end
        self.globalsave = True
        self.version = utils.get_fuel_version()

        # settings load
        self.settings = settings_module.Settings()

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs={"mos_version": self.version})

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs={"mos_version": self.version})

        self.main()
        self.choices = []
Ejemplo n.º 7
0
    def __init__(self):
        self.footer = None
        self.frame = None
        self.screen = None
        self.managediface = network.get_physical_ifaces()[0]
        self.dns_might_have_changed = False
        # Set to true to move all settings to end
        self.globalsave = True
        self.version = utils.get_fuel_version()

        # settings load
        self.settings = settings_module.Settings()

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs={"mos_version": self.version})

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs={"mos_version": self.version})

        self.main()
        self.choices = []
Ejemplo n.º 8
0
 def test_get_fuel_version_with_exc(self):
     with patch('__builtin__.open', mock.mock_open(),
                create=True) as mocked_open:
         mocked_open.side_effect = IOError()
         data = utils.get_fuel_version()
         self.assertEqual("", data)
Ejemplo n.º 9
0
def save_only(iface, settingsfile=consts.SETTINGS_FILE):
    from fuelmenu.common import pwgen
    import netifaces

    if utils.is_post_deployment():
        print("Not updating settings when invoked during post-deployment.\n"
              "Run fuelmenu manually to make changes.")
        sys.exit(0)

    # Calculate and set Static/DHCP pool fields
    # Max IPs = net size - 2 (master node + bcast)
    try:
        ip = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr']
        netmask = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['netmask']
        mac = netifaces.ifaddresses(iface)[netifaces.AF_LINK][0]['addr']
    except Exception:
        print("Interface %s is missing either IP address or netmask"
              % (iface))
        sys.exit(1)
    net_ip_list = network.getNetwork(ip, netmask)
    try:
        dhcp_pool = net_ip_list[1:]
        dynamic_start = str(dhcp_pool[0])
        dynamic_end = str(dhcp_pool[-1])
    except Exception:
        print("Unable to define DHCP pools")
        sys.exit(1)
    try:
        hostname, sep, domain = os.uname()[1].partition('.')
    except Exception:
        print("Unable to calculate hostname and domain")
        sys.exit(1)
    try:
        dhcptimeout = 5
        dhcp_server_data = network.search_external_dhcp(iface, dhcptimeout)
    except errors.NetworkException:
        log.error("DHCP scan failed")
        dhcp_server_data = []

    num_dhcp = len(dhcp_server_data)
    if num_dhcp == 0:
        log.debug("No DHCP servers found")
    else:
        # Problem exists, but permit user to continue
        log.error("%s foreign DHCP server(s) found: %s" %
                  (num_dhcp, dhcp_server_data))
        print("ERROR: %s foreign DHCP server(s) found: %s" %
              (num_dhcp, dhcp_server_data))
    if network.duplicateIPExists(ip, iface):
        log.error("Duplicate host found with IP {0}".format(ip))
        print("ERROR: Duplicate host found with IP {0}".format(ip))

    default_settings_file = os.path.join(os.path.dirname(__file__),
                                         "settings.yaml")
    mos_version = utils.get_fuel_version()

    settings = settings_module.Settings()

    settings.load(
        default_settings_file,
        template_kwargs={"mos_version": mos_version})

    settings.load(settingsfile, template_kwargs={"mos_version": mos_version})

    settings_upd = \
        {
            "ADMIN_NETWORK/interface": iface,
            "ADMIN_NETWORK/ipaddress": ip,
            "ADMIN_NETWORK/netmask": netmask,
            "ADMIN_NETWORK/mac": mac,
            "ADMIN_NETWORK/dhcp_pool_start": dynamic_start,
            "ADMIN_NETWORK/dhcp_pool_end": dynamic_end,
            "ADMIN_NETWORK/dhcp_gateway": ip,
            "HOSTNAME": hostname,
            "DNS_DOMAIN": domain,
            "DNS_SEARCH": domain,
            "astute/user": "******",
            "astute/password": pwgen.password(),
            "cobbler/user": "******",
            "cobbler/password": pwgen.password(),
            "keystone/admin_token": pwgen.password(),
            "keystone/ostf_user": "******",
            "keystone/ostf_password": pwgen.password(),
            "keystone/nailgun_user": "******",
            "keystone/nailgun_password": pwgen.password(),
            "keystone/monitord_user": "******",
            "keystone/monitord_password": pwgen.password(),
            "mcollective/user": "******",
            "mcollective/password": pwgen.password(),
            "postgres/keystone_dbname": "keystone",
            "postgres/keystone_user": "******",
            "postgres/keystone_password": pwgen.password(),
            "postgres/nailgun_dbname": "nailgun",
            "postgres/nailgun_user": "******",
            "postgres/nailgun_password": pwgen.password(),
            "postgres/ostf_dbname": "ostf",
            "postgres/ostf_user": "******",
            "postgres/ostf_password": pwgen.password(),
            "FUEL_ACCESS/user": "******",
            "FUEL_ACCESS/password": "******",
        }
    for setting in settings_upd.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            settings.setdefault(part1, {})
            # Keep old values for passwords if already set
            if "password" in setting:
                settings[part1].setdefault(part2, settings_upd[setting])
            else:
                settings[part1][part2] = settings_upd[setting]
        else:
            if "password" in setting:
                settings.setdefault(setting, settings_upd[setting])
            else:
                settings[setting] = settings_upd[setting]

    # Write astute.yaml
    settings.write(outfn=settingsfile)
Ejemplo n.º 10
0
def save_only(iface, settingsfile=consts.SETTINGS_FILE):
    from fuelmenu.common import pwgen
    import netifaces

    if utils.is_post_deployment():
        print("Not updating settings when invoked during post-deployment.\n"
              "Run fuelmenu manually to make changes.")
        sys.exit(0)

    # Calculate and set Static/DHCP pool fields
    # Max IPs = net size - 2 (master node + bcast)
    try:
        ip = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr']
        netmask = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['netmask']
        mac = netifaces.ifaddresses(iface)[netifaces.AF_LINK][0]['addr']
    except Exception:
        print("Interface %s is missing either IP address or netmask"
              % (iface))
        sys.exit(1)
    net_ip_list = network.getNetwork(ip, netmask)
    try:
        dhcp_pool = net_ip_list[1:]
        dynamic_start = str(dhcp_pool[0])
        dynamic_end = str(dhcp_pool[-1])
    except Exception:
        print("Unable to define DHCP pools")
        sys.exit(1)
    try:
        hostname, sep, domain = os.uname()[1].partition('.')
    except Exception:
        print("Unable to calculate hostname and domain")
        sys.exit(1)
    try:
        dhcptimeout = 5
        dhcp_server_data = network.search_external_dhcp(iface, dhcptimeout)
    except errors.NetworkException:
        log.error("DHCP scan failed")
        dhcp_server_data = []

    num_dhcp = len(dhcp_server_data)
    if num_dhcp == 0:
        log.debug("No DHCP servers found")
    else:
        # Problem exists, but permit user to continue
        log.error("%s foreign DHCP server(s) found: %s" %
                  (num_dhcp, dhcp_server_data))
        print("ERROR: %s foreign DHCP server(s) found: %s" %
              (num_dhcp, dhcp_server_data))
    if network.duplicateIPExists(ip, iface):
        log.error("Duplicate host found with IP {0}".format(ip))
        print("ERROR: Duplicate host found with IP {0}".format(ip))

    default_settings_file = os.path.join(os.path.dirname(__file__),
                                         "settings.yaml")
    mos_version = utils.get_fuel_version()

    settings = settings_module.Settings()

    settings.load(
        default_settings_file,
        template_kwargs={"mos_version": mos_version})

    settings.load(settingsfile, template_kwargs={"mos_version": mos_version})

    settings_upd = \
        {
            "ADMIN_NETWORK/interface": iface,
            "ADMIN_NETWORK/ipaddress": ip,
            "ADMIN_NETWORK/netmask": netmask,
            "ADMIN_NETWORK/mac": mac,
            "ADMIN_NETWORK/dhcp_pool_start": dynamic_start,
            "ADMIN_NETWORK/dhcp_pool_end": dynamic_end,
            "ADMIN_NETWORK/dhcp_gateway": ip,
            "ADMIN_NETWORK/ssh_network": network.getCidr(ip, netmask),
            "HOSTNAME": hostname,
            "DNS_DOMAIN": domain,
            "DNS_SEARCH": domain,
            "astute/user": "******",
            "astute/password": pwgen.password(),
            "cobbler/user": "******",
            "cobbler/password": pwgen.password(),
            "keystone/admin_token": pwgen.password(),
            "keystone/ostf_user": "******",
            "keystone/ostf_password": pwgen.password(),
            "keystone/nailgun_user": "******",
            "keystone/nailgun_password": pwgen.password(),
            "keystone/monitord_user": "******",
            "keystone/monitord_password": pwgen.password(),
            "mcollective/user": "******",
            "mcollective/password": pwgen.password(),
            "postgres/keystone_dbname": "keystone",
            "postgres/keystone_user": "******",
            "postgres/keystone_password": pwgen.password(),
            "postgres/nailgun_dbname": "nailgun",
            "postgres/nailgun_user": "******",
            "postgres/nailgun_password": pwgen.password(),
            "postgres/ostf_dbname": "ostf",
            "postgres/ostf_user": "******",
            "postgres/ostf_password": pwgen.password(),
            "FUEL_ACCESS/user": "******",
            "FUEL_ACCESS/password": "******",
        }
    for setting in settings_upd.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            settings.setdefault(part1, {})
            # Keep old values for passwords if already set
            if "password" in setting:
                settings[part1].setdefault(part2, settings_upd[setting])
            else:
                settings[part1][part2] = settings_upd[setting]
        else:
            if "password" in setting:
                settings.setdefault(setting, settings_upd[setting])
            else:
                settings[setting] = settings_upd[setting]

    # Write astute.yaml
    settings.write(outfn=settingsfile)