Skip to content

Commit

Permalink
nanny: create workers and assign config from create policy
Browse files Browse the repository at this point in the history
  • Loading branch information
wipawel committed Jul 9, 2014
1 parent b526c7a commit dcbeeb9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions nanny/nanny.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,13 @@ ni_objectmodel_nanny_create_policy(ni_dbus_object_t *object, const ni_dbus_metho
xml_document_t *doc;
xml_node_t *root, *pnode;
ni_nanny_t *mgr;
ni_fsm_t *fsm;
unsigned int count = 0;

if ((mgr = ni_objectmodel_nanny_unwrap(object, error)) == NULL)
return FALSE;

fsm = mgr->fsm;
if (argc != 1 || !ni_dbus_variant_get_string(&argv[0], &doc_string) || ni_string_empty(doc_string))
return ni_dbus_error_invalid_args(error, ni_dbus_object_get_path(object), method->name);

Expand All @@ -910,7 +912,8 @@ ni_objectmodel_nanny_create_policy(ni_dbus_object_t *object, const ni_dbus_metho

root = xml_document_root(doc);
for (pnode = root->children; pnode != NULL; pnode = pnode->next) {
ni_fsm_policy_t *policy;
const ni_fsm_policy_t *policies[1];
xml_node_t *config = NULL;
const char *pname;

if (!ni_ifconfig_is_policy(pnode)) {
Expand All @@ -929,26 +932,35 @@ ni_objectmodel_nanny_create_policy(ni_dbus_object_t *object, const ni_dbus_metho
return FALSE;
}

if (ni_fsm_policy_by_name(mgr->fsm, pname) != NULL) {
if (ni_fsm_policy_by_name(fsm, pname) != NULL) {
dbus_set_error(error, NI_DBUS_ERROR_POLICY_EXISTS,
"Policy \"%s\" already exists in call to %s.%s",
pname, ni_dbus_object_get_path(object), method->name);
return FALSE;
}

/* Create policy and corresponding worker (e.g. for hotplug or factory devices */
policy = ni_fsm_policy_new(mgr->fsm, pname, pnode);
policies[0] = ni_fsm_policy_new(fsm, pname, pnode);

config = xml_node_new(NI_CLIENT_IFCONFIG, NULL);
config = ni_fsm_policy_transform_document(config, policies, 1);
if (!config || !ni_fsm_workers_from_xml(fsm, config, ni_ifpolicy_get_origin(pnode))) {
dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
"Bad policy \"%s\" in call to %s.%s",
doc_string, ni_dbus_object_get_path(object), method->name);
return FALSE;
}

/* Rebuild the hierarchy cause new policy may hit some matches */
ni_fsm_build_hierarchy(mgr->fsm);
ni_fsm_build_hierarchy(fsm);

/* Schedule recheck on Factory devices
* (Hotplugs and existing devices are scheduled upon DEVICE_READY)
*/
__ni_objectmodel_nanny_factory_device_recheck(mgr, pname);

policy_object = ni_objectmodel_register_managed_policy(ni_dbus_object_get_server(object),
ni_managed_policy_new(mgr, policy, NULL));
ni_managed_policy_new(mgr, (ni_fsm_policy_t *) policies[0], NULL));

if (ni_dbus_message_append_object_path(reply, ni_dbus_object_get_path(policy_object)))
count++;
Expand Down

0 comments on commit dcbeeb9

Please sign in to comment.