cfengine / design-center

CFEngine community-contributed content
http://cfengine.com/
Other
80 stars 68 forks source link

Redmine#6404: support cf-sketch module mode for new packages promises #455

Closed tzz closed 9 years ago

tzz commented 9 years ago

See https://dev.cfengine.com/issues/6404

This requires linking cf-sketch.pl to the package module directory as design_center.

Then the following will install a sketch.

bundle agent main
{
  vars:
      "debug" string => "1";

  packages:
      "Primitives::files_existence"
      policy => "present",
      package_module => design_center,
      classes => scoped_classes_generic("namespace", $(this.promise));
}

body package_module design_center
{
      default_options => { 'verbose=$(debug)', 'veryverbose=$(debug)' },
}
tzz commented 9 years ago

OK, changed to be just an installer. @kacfengine I will figure out why list-installed is not working properly.

tzz commented 9 years ago

Yeah, found it. Version and Architecture are required in list-installed responses. I don't think that's a necessary requirement, but I've adapted regardless.

kacf commented 9 years ago

Yes, a lot of assumptions will break if it's not included. Architecture can be a constant string if it's not meaningful though, like "all".

tzz commented 9 years ago

OK, the following example works:

body file control
{
      inputs => { "$(sys.libdir)/stdlib.cf"} ;
}

bundle agent main
{
  methods:
      # clear all DC data
      "" usebundle => file_make("$(sys.masterdir)/sketches/meta/vardata.conf", '
{
  "compositions": {},
  "activations": {},
  "definitions": {},
  "environments": {},
  "validations": {}
}');

      "" usebundle => install_sketches;

    Primitives__files_existence_ok::
      "" usebundle => activate_sketches;

    any::
      "" usebundle => uninstall_sketches;

}

bundle agent install_sketches
{
  packages:
      "Primitives::files_existence"
      policy => "present",
      package_module => design_center,
      classes => scoped_classes_generic("namespace", "Primitives__files_existence");

      "nonesuch"
      policy => "present",
      package_module => design_center;
}

bundle agent uninstall_sketches
{
  packages:
      "nonesuch"
      policy => "absent",
      package_module => design_center;

      "Primitives::files_existence"
      policy => "absent",
      package_module => design_center;
}

body package_module design_center
{
      default_options => {
                          'installsource=/home/tzz/source/cfengine/design-center/sketches/cfsketches.json',
                          'verbose=0',
                          'veryverbose=0'
      };
}

bundle agent activate_sketches
{
  vars:
      "cfsketch" string => "/home/tzz/source/cfengine/design-center/tools/cf-sketch/cf-sketch.pl";
      "params1" data => '{
  "list_of_files": [ "/tmp/t1" ],
  "success_class": "files_found1",
  "fail_class": "files_not_found1"
 }';
      "pstring1" string => format('%S', params1);

      "params2" data => '{
  "list_of_files": [ "/tmp/t2" ],
  "success_class": "files_found2",
  "fail_class": "files_not_found2"
 }';
      "pstring2" string => format('%S', params2);

  commands:
      "$(cfsketch) --expert --relocate_path sketches --generate --activate Primitives::files_existence='$(pstring1)'";
      "$(cfsketch) --expert --relocate_path sketches --generate --activate Primitives::files_existence='$(pstring2)'";
}
tzz commented 9 years ago

@nickanderson The body package_module design_center could go into the stdlib if the installsource is set correctly for Enterprise and Community, but it also needs manual setup from the user to link cf-sketch.pl to design_center.

tzz commented 9 years ago

@nickanderson @estenberg can you please consider merging this?

tzz commented 9 years ago

ping?

kacf commented 9 years ago

ping?

Sorry, Design Center really isn't my area. @nickanderson or @estenberg?

nickanderson commented 9 years ago

What impact if any does this have on Mission Portal and how sketches are installed today?

tzz commented 9 years ago

This has no effect on MP. It is only usable from policy while MP uses the DC API directly.

nickanderson commented 9 years ago

@estenberg OK to merge this?

tzz commented 9 years ago

ping again!

tzz commented 9 years ago

Thank you for this and all the other help.