43#define POOL_REGEXP "[A-Za-z][-_a-zA-Z0-9]+"
45 "((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-" \
46 "9]|[1-9][0-9]|[0-9])"
47#define ID_POOL_NAME "id_pool_name"
48#define ID_ADDR "id_addr"
53static struct ec_node *with_help(
struct ec_node *node,
const char *help)
75static struct ec_node *with_desc(
struct ec_node *node,
const char *desc)
86static int pool_list_cb(
const struct ec_pnode *parse)
94 names = ip_pool_list();
96 fprintf(stderr,
"Failed to list pools\n");
104 for (i = 0; i < len; i++)
113static int pool_add_cb(
const struct ec_pnode *parse)
115 const char *pool_name;
118 if (ip_pool(pool_name) == NULL) {
119 fprintf(stderr,
"Failed to add pool\n");
126static int pool_del_cb(
const struct ec_pnode *parse)
128 const char *pool_name;
131 ip_pool_free(pool_name);
136static int addr_list_cb(
const struct ec_pnode *parse)
139 const struct ip_pool *pool;
140 const char *pool_name;
145 pool = ip_pool_lookup(pool_name);
146 addrs = ip_pool_addr_list(pool);
148 fprintf(stderr,
"Failed to list pool addresses\n");
154 printf(
"No address\n");
156 for (i = 0; i < len; i++)
165static int addr_add_cb(
const struct ec_pnode *parse)
167 const char *pool_name;
168 struct ip_pool *pool;
172 pool = ip_pool_lookup(pool_name);
174 if (ip_pool_addr_add(pool, addr) < 0) {
175 fprintf(stderr,
"Failed to add address to pool\n");
182static int addr_del_cb(
const struct ec_pnode *parse)
184 const char *pool_name;
185 struct ip_pool *pool;
189 pool = ip_pool_lookup(pool_name);
191 if (ip_pool_addr_del(pool, addr) < 0) {
192 fprintf(stderr,
"Failed to delete address from pool\n");
199static int exit_cb(
const struct ec_pnode *parse)
209static int check_exit(
void *opaque)
220 return ip_pool_list();
225 const char *pool_name;
226 struct ip_pool *pool;
233 if (pool_name == NULL)
235 pool = ip_pool_lookup(pool_name);
239 return ip_pool_addr_list(pool);
242static struct ec_node *create_pool_commands(
void)
244 struct ec_node *cmdlist = NULL;
265 "The name of the pool to create"
283 "The name of the pool to delete"
297static struct ec_node *create_addr_commands(
void)
299 struct ec_node *cmdlist = NULL;
306 "Display the list of IP addresses in a pool"
313 "Add an IP address into a pool"
335 "Delete an IP address from a pool"
350 "The existing IP to delete"
371 "The name of the pool (must exist)"
377static struct ec_node *create_commands(
void)
379 struct ec_node *cmdlist = NULL;
412 fprintf(stderr,
"cannot initialize nodes\n");
422 if (ip_pool_init() < 0) {
423 fprintf(stderr,
"cannot init IP pools: %s\n", strerror(errno));
428 fprintf(stderr,
"cannot init ecoli: %s\n", strerror(errno));
432 node = create_commands();
434 fprintf(stderr,
"failed to create commands: %s\n", strerror(errno));
438 editline =
ec_editline(
"pool-editline", stdin, stdout, stderr, 0);
439 if (editline == NULL) {
440 fprintf(stderr,
"Failed to initialize editline\n");
445 fprintf(stderr,
"Failed to set prompt\n");
int ec_editline_set_prompt(struct ec_editline *editline, const char *prompt)
struct ec_editline * ec_editline(const char *prog, FILE *f_in, FILE *f_out, FILE *f_err, enum ec_editline_init_flags flags)
void ec_editline_free(struct ec_editline *editline)
int ec_editline_interact(struct ec_editline *editline, ec_editline_check_exit_cb_t check_exit_cb, void *opaque)
int ec_editline_set_node(struct ec_editline *editline, const struct ec_node *node)
int(* ec_interact_command_cb_t)(const struct ec_pnode *)
int ec_interact_set_help(struct ec_node *node, const char *help)
int ec_interact_set_desc(struct ec_node *node, const char *desc)
int ec_interact_set_callback(struct ec_node *node, ec_interact_command_cb_t cb)
struct ec_node * ec_node_dynlist(const char *id, ec_node_dynlist_get_t get, void *opaque, const char *re_str, enum ec_node_dynlist_flags flags)
int ec_node_or_add(struct ec_node *node, struct ec_node *child)
#define EC_NODE_OR(args...)
#define EC_NODE_SEQ(args...)
struct ec_node * ec_node_sh_lex(const char *id, struct ec_node *child)
struct ec_node * ec_node_str(const char *id, const char *str)
struct ec_node * ec_node(const char *typename, const char *id)
void ec_node_free(struct ec_node *node)
const struct ec_strvec * ec_pnode_get_strvec(const struct ec_pnode *pnode)
const struct ec_pnode * ec_pnode_find(const struct ec_pnode *root, const char *id)
struct ec_pnode * ec_pnode_get_root(struct ec_pnode *pnode)
struct ec_pnode * ec_pnode(const struct ec_node *node)
void ec_strvec_free(struct ec_strvec *strvec)
const char * ec_strvec_val(const struct ec_strvec *strvec, size_t idx)
struct ec_strvec * ec_strvec(void)
size_t ec_strvec_len(const struct ec_strvec *strvec)