Created yang_model bucklet.

Change-Id: I01986161ef40abe4f0df3a9d9a1e7bc43f0eba71
diff --git a/bucklets/yang.bucklet b/bucklets/yang.bucklet
index 9c15a51..3d68180 100644
--- a/bucklets/yang.bucklet
+++ b/bucklets/yang.bucklet
@@ -1,9 +1,73 @@
 include_defs('//onos.defs')
+include_defs('//bucklets/onos.bucklet')
+include_defs('//bucklets/onos_app.bucklet')
 
 def _get_name():
     base_path = get_base_path()
     return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
 
+YANG_TOOLS = [
+    '//apps/yang:onos-apps-yang',
+    '//lib:onos-yang-runtime',
+]
+
+def yang_model(
+    name = None,
+    app_name = None,
+    title = 'YANG Model',
+    url = 'http://onosproject.org',
+    description = None,
+    deps = [],
+    **kwargs
+    ):
+
+    if name is None:
+        name = _get_name()
+
+    yang = name + '-yang'
+    yangSrcs = yang + '#srcs'
+    schema = name + '-schema'
+    registrator = name + '-registrator'
+
+    yang_library(
+      name = yang,
+      srcs = glob(['src/**/*.yang']),
+    )
+
+    genrule(
+      name = schema,
+      srcs = [ ':' + yangSrcs ],
+      cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
+      out = 'yang'
+    )
+
+    genrule(
+      name = registrator,
+      srcs = [ ':' + yangSrcs ],
+      cmd = '$(location //buck-tools:yang-registrator) $OUT app_name $SRCS',
+      out = 'YangModelRegistrator.java'
+    )
+
+    osgi_jar(
+      name = 'onos-models-demo',
+      srcs = [ ':' + yangSrcs, ':' + registrator ],
+      deps = deps + YANG_TOOLS,
+      resources = [ ':' + schema ],
+      resources_root = ".",
+      do_checkstyle = False,
+      do_javadocs = False,
+    )
+
+    onos_app (
+      app_name = app_name,
+      title = title,
+      category = 'Model',
+      url = url,
+      description = description,
+      required_apps = [ 'org.onosproject.yang' ],
+    )
+
+
 def yang_osgi_jar(
     name = None,
     srcs = None,
diff --git a/models/demo/BUCK b/models/demo/BUCK
index 6b4456a..5fae4f6 100644
--- a/models/demo/BUCK
+++ b/models/demo/BUCK
@@ -2,56 +2,9 @@
   '//lib:CORE_DEPS',
 ]
 
-
-# The following will be wrapped into a macro to be used something like this:
-#
-# yang_model (
-#   app_name = 'org.onosproject.models.foobar',
-#   title = 'Demo YANG Model',
-#   url = 'http://onosproject.org',
-# )
-
-
-YANG_TOOLS = [
-  '//apps/yang:onos-apps-yang',
-  '//lib:onos-yang-runtime',
-]
-
-yang_library(
-  name = 'yang',
-  srcs = glob(['src/**/*.yang']),
-)
-
-genrule(
-  name = 'schema',
-  srcs = [ ':yang#srcs' ],
-  cmd = '$(location //buck-tools:yang-schema) $OUT $SRCS',
-  out = 'yang'
-)
-
-genrule(
-  name = 'registrator',
-  srcs = glob(['src/**/*.yang']),
-  cmd = '$(location //buck-tools:yang-registrator) $OUT org.onosproject.models.demo $SRCS',
-  out = 'YangModelRegistrator.java'
-)
-
-osgi_jar(
-  name = 'onos-models-demo',
-  # srcs = [ ':registrator' ],
-  srcs = [ ':yang#srcs', ':registrator' ],
-  deps = COMPILE_DEPS + YANG_TOOLS,
-  resources = [ ':schema' ],
-  resources_root = ".",
-  do_checkstyle = False,
-  do_javadocs = False,
-)
-
-onos_app (
+yang_model (
   app_name = 'org.onosproject.models.demo',
   title = 'Demo YANG Model',
-  category = 'Model',
   url = 'http://onosproject.org',
-  description = 'Demo YANG model extension.',
-  required_apps = [ 'org.onosproject.yang' ],
+  deps = COMPILE_DEPS,
 )