Fall back to 169.254.169.254 if DHCP endpoint does not work (unbreak OpenStack)
This commit is contained in:
parent
8dfa3c843a
commit
aa963100ba
3 changed files with 46 additions and 23 deletions
|
@ -31,31 +31,60 @@
|
|||
|
||||
static int cloudinit_fetch(struct system_config *);
|
||||
|
||||
int
|
||||
tryendpoint(struct system_config *sc,
|
||||
int (fetch)(struct system_config *),
|
||||
int (next)(struct system_config *))
|
||||
{
|
||||
free(sc->sc_endpoint);
|
||||
sc->sc_endpoint = NULL;
|
||||
|
||||
switch (sc->sc_dhcpendpoint) {
|
||||
case 0:
|
||||
sc->sc_dhcpendpoint = 1;
|
||||
if (dhcp_getendpoint(sc) == -1)
|
||||
return tryendpoint(sc, fetch, next);
|
||||
break;
|
||||
case 1:
|
||||
sc->sc_dhcpendpoint = 2;
|
||||
if ((sc->sc_endpoint = strdup(DEFAULT_ENDPOINT)) == NULL) {
|
||||
log_warnx("failed to set defaults");
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (next == NULL)
|
||||
return (-1);
|
||||
sc->sc_dhcpendpoint = 0;
|
||||
return (*next)(sc);
|
||||
}
|
||||
|
||||
if ((*fetch)(sc) != 0)
|
||||
return tryendpoint(sc, fetch, next);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
ec2(struct system_config *sc)
|
||||
{
|
||||
free(sc->sc_username);
|
||||
if ((sc->sc_username = strdup("ec2-user")) == NULL ||
|
||||
(sc->sc_endpoint = strdup(DEFAULT_ENDPOINT)) == NULL) {
|
||||
log_warnx("failed to set defaults");
|
||||
if ((sc->sc_username = strdup("ec2-user")) == NULL) {
|
||||
log_warnx("failed to set default user");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
sc->sc_stack = "ec2";
|
||||
return (cloudinit_fetch(sc));
|
||||
sc->sc_dhcpendpoint = 1;
|
||||
return tryendpoint(sc, cloudinit_fetch, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
cloudinit(struct system_config *sc)
|
||||
{
|
||||
if ((dhcp_getendpoint(sc) == -1) &&
|
||||
(sc->sc_endpoint = strdup(DEFAULT_ENDPOINT)) == NULL) {
|
||||
log_warnx("failed to set defaults");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
sc->sc_stack = "cloudinit";
|
||||
return (cloudinit_fetch(sc));
|
||||
sc->sc_dhcpendpoint = 0;
|
||||
return tryendpoint(sc, cloudinit_fetch, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -76,6 +76,7 @@ struct system_config {
|
|||
char *sc_pubkey;
|
||||
char *sc_userdata;
|
||||
char *sc_endpoint;
|
||||
int sc_dhcpendpoint;
|
||||
char *sc_instance;
|
||||
int sc_timeout;
|
||||
|
||||
|
@ -123,6 +124,9 @@ int azure(struct system_config *);
|
|||
/* cloudinit.c */
|
||||
int ec2(struct system_config *);
|
||||
int cloudinit(struct system_config *);
|
||||
int tryendpoint(struct system_config *,
|
||||
int (fetch)(struct system_config *),
|
||||
int (next)(struct system_config *));
|
||||
|
||||
/* opennebula.c */
|
||||
int opennebula(struct system_config *);
|
||||
|
|
|
@ -31,21 +31,11 @@
|
|||
|
||||
static int openstack_fetch(struct system_config *);
|
||||
|
||||
|
||||
int
|
||||
openstack(struct system_config *sc)
|
||||
{
|
||||
if ((dhcp_getendpoint(sc) == -1) &&
|
||||
(sc->sc_endpoint = strdup(DEFAULT_ENDPOINT)) == NULL) {
|
||||
log_warnx("failed to set defaults");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (openstack_fetch(sc) != 0) {
|
||||
free(sc->sc_endpoint);
|
||||
return (cloudinit(sc));
|
||||
}
|
||||
|
||||
return (0);
|
||||
return tryendpoint(sc, openstack_fetch, cloudinit);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Reference in a new issue