]> git.ozlabs.org Git - petitboot/commitdiff
ui: add URL for static configurations to load a specified file
authorNishanth Aravamudan <nacc@linux.vnet.ibm.com>
Wed, 19 Aug 2015 21:05:05 +0000 (14:05 -0700)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Fri, 18 Dec 2015 02:06:53 +0000 (13:06 +1100)
In certain configurations, e.g. automation, we want to use static
networking but load a particular file, automatically and parse it as a
pxelinux config file. Currently, we support something like this for DHCP
based booting, but not static. Add a URL field to the UI for static
configurations and reuse the logic from device_handler_process_url() to
load the specified file.

Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover/network.c
discover/platform-powerpc.c
discover/platform.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h
ui/ncurses/nc-config.c

index 0dad087bb4199a3d2ed15510bad1f0b43cc1f1ab..f763687f8b53bbb8c57b14f1c0abe63e171e147b 100644 (file)
@@ -336,7 +336,8 @@ static void configure_interface_dhcp(struct interface *interface)
        return;
 }
 
-static void configure_interface_static(struct interface *interface,
+static void configure_interface_static(struct network *network,
+               struct interface *interface,
                const struct interface_config *config)
 {
        int rc;
@@ -370,6 +371,12 @@ static void configure_interface_static(struct interface *interface,
                                interface->name);
        }
 
+       if (config->static_config.url) {
+               pb_log("config URL %s\n", config->static_config.url);
+               device_handler_process_url(network->handler,
+                               config->static_config.url);
+       }
+
        return;
 }
 
@@ -438,7 +445,7 @@ static void configure_interface(struct network *network,
                configure_interface_dhcp(interface);
 
        } else if (config->method == CONFIG_METHOD_STATIC) {
-               configure_interface_static(interface, config);
+               configure_interface_static(network, interface, config);
        }
 }
 
index 7370d7dcc20a21e78dacc57e2efc8ebe7e3cdb0f..5abc4d7059daa24babceed82de8115ccf49763d3 100644 (file)
@@ -310,7 +310,7 @@ static int parse_one_interface_config(struct config *config,
        } else if (!strcmp(tok, "static")) {
                ifconf->method = CONFIG_METHOD_STATIC;
 
-               /* ip/mask, [optional] gateway */
+               /* ip/mask, [optional] gateway, [optional] url */
                tok = strtok_r(NULL, ",", &saveptr);
                if (!tok)
                        goto out_err;
@@ -323,6 +323,12 @@ static int parse_one_interface_config(struct config *config,
                                talloc_strdup(ifconf, tok);
                }
 
+               tok = strtok_r(NULL, ",", &saveptr);
+               if (tok) {
+                       ifconf->static_config.url =
+                               talloc_strdup(ifconf, tok);
+               }
+
        } else {
                pb_log("Unknown network configuration method %s\n", tok);
                goto out_err;
@@ -575,10 +581,12 @@ static char *iface_config_str(void *ctx, struct interface_config *config)
                str = talloc_asprintf_append(str, "dhcp");
 
        } else if (config->method == CONFIG_METHOD_STATIC) {
-               str = talloc_asprintf_append(str, "static,%s%s%s",
+               str = talloc_asprintf_append(str, "static,%s%s%s%s%s",
                                config->static_config.address,
                                config->static_config.gateway ? "," : "",
-                               config->static_config.gateway ?: "");
+                               config->static_config.gateway ?: "",
+                               config->static_config.url ? "," : "",
+                               config->static_config.url ?: "");
        }
        return str;
 }
index 5f448f1a4a1ba92c9111b7826b074f4da3186f74..fc0930db29a1cd67d6223d891f9fa9a865e064e6 100644 (file)
@@ -60,6 +60,7 @@ static void dump_config(struct config *config)
                        pb_log("   static:\n");
                        pb_log("    ip:  %s\n", ifconf->static_config.address);
                        pb_log("    gw:  %s\n", ifconf->static_config.gateway);
+                       pb_log("    url:  %s\n", ifconf->static_config.url);
 
                }
        }
index ab5ea8a376e1500895ba047b3e656e8ac114fd59..9d07a588f92a5a6c3792b67a27ee507fdf2e4d4d 100644 (file)
@@ -260,6 +260,7 @@ static int pb_protocol_interface_config_len(struct interface_config *conf)
        if (conf->method == CONFIG_METHOD_STATIC) {
                len += 4 + optional_strlen(conf->static_config.address);
                len += 4 + optional_strlen(conf->static_config.gateway);
+               len += 4 + optional_strlen(conf->static_config.url);
        }
 
        return len;
@@ -454,6 +455,8 @@ static int pb_protocol_serialise_config_interface(char *buf,
                                conf->static_config.address);
                pos += pb_protocol_serialise_string(pos,
                                conf->static_config.gateway);
+               pos += pb_protocol_serialise_string(pos,
+                               conf->static_config.url);
        }
 
        return pos - buf;
@@ -900,6 +903,9 @@ static int pb_protocol_deserialise_config_interface(const char **buf,
 
                if (read_string(iface, buf, len, &iface->static_config.gateway))
                        return -1;
+
+               if (read_string(iface, buf, len, &iface->static_config.url))
+                       return -1;
        }
 
        return 0;
index 702b6f5f82286605cc00303f11cb2f84d4610150..c2de8a5bab215ec31cbc399e8e5cabb625a86f4e 100644 (file)
@@ -115,6 +115,7 @@ struct interface_config {
                struct {
                        char *address;
                        char *gateway;
+                       char *url;
                } static_config;
        };
 };
index 64fb4c792139d71dc0891dda330752b2427dc272..e7451bb5dc08fda57d54cd9a73e9bbcd32a60711 100644 (file)
@@ -33,7 +33,7 @@
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       34
+#define N_FIELDS       37
 
 extern struct help_text config_help_text;
 
@@ -96,6 +96,9 @@ struct config_screen {
                struct nc_widget_label          *gateway_l;
                struct nc_widget_textbox        *gateway_f;
                struct nc_widget_label          *gateway_help_l;
+               struct nc_widget_label          *url_l;
+               struct nc_widget_textbox        *url_f;
+               struct nc_widget_label          *url_help_l;
                struct nc_widget_label          *dns_l;
                struct nc_widget_textbox        *dns_f;
                struct nc_widget_label          *dns_dhcp_help_l;
@@ -274,11 +277,12 @@ static int screen_process_form(struct config_screen *screen)
        }
 
        if (net_conf_type == NET_CONF_TYPE_STATIC) {
-               char *ip, *mask, *gateway;
+               char *ip, *mask, *gateway, *url;
 
                ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
                mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
                gateway = widget_textbox_get_value(screen->widgets.gateway_f);
+               url = widget_textbox_get_value(screen->widgets.url_f);
 
                if (!ip || !*ip || !mask || !*mask) {
                        screen->scr.frame.status =
@@ -292,6 +296,7 @@ static int screen_process_form(struct config_screen *screen)
                iface->static_config.address = talloc_asprintf(iface, "%s/%s",
                                ip, mask);
                iface->static_config.gateway = talloc_strdup(iface, gateway);
+               iface->static_config.url = talloc_strdup(iface, url);
        }
 
        str = widget_textbox_get_value(screen->widgets.dns_f);
@@ -510,6 +515,19 @@ static void config_screen_layout_widgets(struct config_screen *screen)
                y++;
        }
 
+       wl = widget_label_base(screen->widgets.url_l);
+       wf = widget_textbox_base(screen->widgets.url_f);
+       wh = widget_label_base(screen->widgets.url_help_l);
+       widget_set_visible(wl, show);
+       widget_set_visible(wf, show);
+       widget_set_visible(wh, show);
+
+       if (show) {
+               layout_pair(screen, y, screen->widgets.url_l, wf);
+               widget_move(wh, y, help_x);
+               y++;
+       }
+
        wh = widget_label_base(screen->widgets.dns_help_l);
        layout_pair(screen, y, screen->widgets.dns_l,
                        widget_textbox_base(screen->widgets.dns_f));
@@ -693,7 +711,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 {
        struct nc_widgetset *set = screen->widgetset;
        struct interface_config *ifcfg;
-       char *str, *ip, *mask, *gw;
+       char *str, *ip, *mask, *gw, *url;
        enum net_conf_type type;
        unsigned int i;
        int add_len, clear_len, any_len, min_len = 20;
@@ -849,7 +867,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                                                i, str, is_default);
        }
 
-       gw = ip = mask = NULL;
+       url = gw = ip = mask = NULL;
        if (ifcfg && ifcfg->method == CONFIG_METHOD_STATIC) {
                char *sep;
 
@@ -862,6 +880,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                        mask = sep + 1;
                }
                gw = ifcfg->static_config.gateway;
+               url = ifcfg->static_config.url;
        }
 
        screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, _("IP/mask:"));
@@ -884,6 +903,11 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        widget_textbox_set_fixed_size(screen->widgets.gateway_f);
        widget_textbox_set_validator_ipv4(screen->widgets.gateway_f);
 
+       screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:"));
+       screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url);
+       screen->widgets.url_help_l =
+               widget_new_label(set, 0, 0, _("(eg. tftp://)"));
+
        str = talloc_strdup(screen, "");
        for (i = 0; i < config->network.n_dns_servers; i++) {
                str = talloc_asprintf_append(str, "%s%s",