Adding git + pip as source engine

Change-Id: I811a0876d806cfcd213ddf746b8ec89f4909fe64
diff --git a/.kitchen.yml b/.kitchen.yml
index 3f2cfaa..b795dac 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -57,6 +57,16 @@
       pillars-from-files:
         reclass.sls: tests/pillar/storage_local.sls
 
+  - name: storage_git
+    provisioner:
+      pillars-from-files:
+        reclass.sls: tests/pillar/storage_git.sls
+
+  - name: storage_pip
+    provisioner:
+      pillars-from-files:
+        reclass.sls: tests/pillar/storage_pip.sls
+
   - name: storage_nodes_uri
     provisioner:
       pillars-from-files:
diff --git a/README.rst b/README.rst
index 66883b8..aab9378 100644
--- a/README.rst
+++ b/README.rst
@@ -3,7 +3,7 @@
 Reclass Formula
 ===============
 
-reclass is an “external node classifier” (ENC) as can be used with automation
+reclass is an "external node classifier" (ENC) as can be used with automation
 tools, such as Puppet, Salt, and Ansible. It is also a stand-alone tool for
 merging data sources recursively.
 
@@ -11,6 +11,33 @@
 Sample Metadata
 ===============
 
+Install sources from [repository, git, pip]
+
+
+.. code-block:: yaml
+
+    salt:
+      source:
+        engine: pkg
+    ...
+      source:
+        engine: git
+        repo: git+https://github.com/salt-formulas/reclass
+        branch: master
+    ...
+      source:
+        engine: pip
+    ...
+
+If reclass is pre-installed, set the engine to None to avoid updates.
+
+.. code-block:: yaml
+
+    salt:
+      source:
+        engine: None
+
+
 Reclass storage with data fetched from git
 
 .. literalinclude:: tests/pillar/storage_git.sls
diff --git a/metadata/service/storage/source/git.yml b/metadata/service/storage/source/git.yml
new file mode 100644
index 0000000..ef62183
--- /dev/null
+++ b/metadata/service/storage/source/git.yml
@@ -0,0 +1,7 @@
+parameters:
+  reclass:
+    storage:
+      source:
+        engine: git
+        repo: git+https://github.com/salt-formulas/reclass
+        branch: master
diff --git a/reclass/map.jinja b/reclass/map.jinja
index 5e3bd19..9915c0c 100644
--- a/reclass/map.jinja
+++ b/reclass/map.jinja
@@ -3,18 +3,27 @@
         'base_dir': '/etc/reclass/base',
         'storage_type': 'yaml_fs',
         'repeat_replace_symbol': '<<count>>',
-        'class_mappings':  {},
+        'class_mappings': {},
         'ignore_class_notfound': False,
         'propagate_pillar_data_to_reclass': False,
         'data_source': {
             'engine': 'local'
         },
+        'source': {
+            'engine': 'pkg'
+        },
         'version': '1.4.1',
     },
     'Debian': {
         'pkgs': ['reclass', 'python-reclass'],
+        'dependency': {
+           'pkgs': ['git', 'python-pip'],
+        }
     },
     'RedHat': {
         'pkgs': ['reclass', 'python-reclass'],
+        'dependency': {
+           'pkgs': ['git', 'python-pip'],
+        }
     },
 }, grain='os_family', merge=salt['pillar.get']('reclass:storage'), base='default') %}
diff --git a/reclass/storage/service.sls b/reclass/storage/service.sls
index 31d33e8..5c43c4d 100644
--- a/reclass/storage/service.sls
+++ b/reclass/storage/service.sls
@@ -12,8 +12,41 @@
   - require:
     - file: reclass_conf_dir
 
+{%- if storage.source.engine == 'pkg' %}
 reclass_packages:
-  pkg.latest:
-  - names: {{ storage.pkgs }}
+  pkg.installed:
+    - names: {{ storage.pkgs }}
 
+{%- elif storage.source.engine == 'git' %}
+storage_install_git_python_pip:
+  pkg.installed:
+    - names:
+      - {{ storage.dependency.pkgs }}
+
+storage_install_reclass_git:
+  pip.installed:
+    - name: reclass
+    - editable: {{ storage.source.repo }}@{{ storage.source.branch }}#egg=reclass
+    - upgrade: True
+    - force_reinstall: True
+    - ignore_installed: True
+    - require:
+      - pkg: storage_install_git_python_pip
+
+{%- elif storage.source.engine == 'pip' %}
+storage_install_python_pip:
+  pkg.installed:
+    - names:
+      - {{ storage.dependency.pkgs }}
+
+storage_install_reclass_pip:
+  pip.installed:
+    - name: reclass
+    - upgrade: True
+    - force_reinstall: True
+    - ignore_installed: True
+    - require:
+      - pkg: storage_install_git_python_pip
+
+{%- endif %}
 {%- endif %}
diff --git a/tests/pillar/storage_git.sls b/tests/pillar/storage_git.sls
index 33b989d..7dd9aba 100644
--- a/tests/pillar/storage_git.sls
+++ b/tests/pillar/storage_git.sls
@@ -2,7 +2,7 @@
   storage:
     enabled: true
     base_dir: /srv/reclass
-    data_source:
+    source:
       engine: git
-      address: git@repo.domain.com:reclass/reclass-project.git
-      revision: master
+      repo: git+https://github.com/salt-formulas/reclass
+      branch: master
diff --git a/tests/pillar/storage_pip.sls b/tests/pillar/storage_pip.sls
new file mode 100644
index 0000000..96ee385
--- /dev/null
+++ b/tests/pillar/storage_pip.sls
@@ -0,0 +1,6 @@
+reclass:
+  storage:
+    enabled: true
+    base_dir: /srv/reclass
+    source:
+      engine: pip