Benjamin Smith avatar Benjamin Smith committed 00bc9d9

reorg

Comments (0)

Files changed (2)

+"""
+NOPE, NO PEP8 HERE!
+
+This is the XML to reference the code below
+
+This would define the base service in
+a "global" scope(services.xml)
+<testservice test="test"/>
+
+This is the XML used by the "host" template
+in a "host" scope
+<testservice test1="test_one" test2="test_two"/>
+"""
+
+from cfbuild import BasicService, RecordParm, StringParm
+
+
+class TestService(BasicService):
+    """Test service"""
+    names = ("testservice", )
+    # Other services needing to inherit
+    required_services = ( "ip", )
+
+    # These params come in from services.xml
+    # There are different types of Parms(e.g int, float, text, ip)
+    parms = RecordParm(make_map(
+            test = StringParm(),
+        ))
+
+    # These params come in from the host template (whatever is calling it).
+    hostparms = RecordParm(make_map(
+            test1 = StringParm(required=1),
+            test2 = StringParm(required=1),
+    ))
+
+    def assemble(self):
+        hostvars = {}
+        # This creates the testservice/site.ini
+        # sets some basic vars needed at runtime.
+        sitevars = self.auto_sitevars()
+        for host, hargs in self.host_args.items():
+            # Define host variable
+            # will end up in testservice/site.ini
+            # and will be available to runtime script.
+            # It should be noted that these vars get evaluated in by Perl at run time,
+            # so be careful what you put in here (quotes and backticks will be bad)
+            hostvars["testvar1"] = hargs.test1
+            hostvars["testvar2"] = hargs.test1
+
+            # Set the vars we defined above
+            self.set_hostvars(host, hostvars)
+        # Create script to be executed on the host when cf is executed.
+        self.add_file("configure.pl", configure_pl)
+
+# This is the code that gets executed on the host at runtime
+configure_pl = r"""#
+# $Id: $
+use strict;
+
+# This will be run on the host when CF is executed
+sub configure {
+    my ($options) = get_options({}, @_);
+    # Do fun stuff
+
+    # This will print out the $testvar defined in the python code above
+    inform($testvar1);
+    inform($testvar2);
+}
+"""
+

cf_example

-from cfbuild import *
-
-class Service(BasicService):
-    "test service"
-    names = ("testservice", )
-    required_services = ( "ip", )
-
-    # These params come in from services.xml
-    # There are different types of Parms, outlined in CfServiceParms
-    parms = RecordParm(make_map(
-            test = StringParm(),
-        ))
-
-    # These params come in from the host template (whatever is calling it).
-    hostparms = RecordParm(make_map(
-            test1 = StringParm(required=1),
-            test2 = StringParm(required=1),
-    ))
-
-    def assemble(self):
-        hostvars = {}
-        # We're going to use pretty printer 
-        # so we can see whats going on.
-        import pprint
-        pp = pprint.PrettyPrinter(indent=4)
-        # This creates the testservice/site.ini
-        # sets some basic vars needed at runtime.
-        sitevars = self.auto_sitevars()
-        for host, hargs in self.host_args.items():
-            # Define host variable
-            # will end up in testservice/site.ini
-            # and will be available in runtime script.
-            # It should be noted that these vars get evaluated in by Perl at run time,
-            # so be careful what you put in here (quotes an backticks will be bad)
-            hostvars["testvar1"] = hargs.test1
-            hostvars["testvar2"] = hargs.test1
-            print pp.pprint(host)
-            print pp.pprint(hargs.test1)
-            print pp.pprint(hargs.test2)
-            # Set the vars we defined above
-            self.set_hostvars(host, hostvars)
-        # Create script to be executed on the host when cf is executed.
-        self.add_file("configure.pl", configure_pl)
-
-# This is the code that gets executed on the host at runtime
-configure_pl = r"""#
-# $Id: $
-use strict;
-
-# This will be run on the host when CF is executed
-sub configure {
-    my ($o) = get_options({}, @_);
-    # Do fun stuff   
- 
-    # This will print out the $testvar defined in the python code above
-    warning($testvar1);
-    warning($testvar2);
-}
-"""
-Now, add this to services.xml with the arguments defined above in the parms Record.
-
-
-<testservice test="test"/>
-
-And finally, in a host template (anyweb, for example) call the service:
-
-
-<testservice test1="test_one" test2="test_two"/>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.