From ce5851c073308f4ccc0fe488a226008518a5f401 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Wed, 27 May 2015 15:24:08 +0200 Subject: [PATCH] Add entities for commited/staging pipeline - remove deployment module --- cli.py | 2 +- config.yaml | 4 ++ solar/solar/state.py | 91 ++++++++++++++++++++++++++++++++++++++++++++ state/commit_log | 0 state/commited_data | 0 state/inprogress_log | 0 state/stage_log | 0 state/staged_data | 0 8 files changed, 96 insertions(+), 1 deletion(-) mode change 100644 => 100755 cli.py create mode 100644 solar/solar/state.py create mode 100644 state/commit_log create mode 100644 state/commited_data create mode 100644 state/inprogress_log create mode 100644 state/stage_log create mode 100644 state/staged_data diff --git a/cli.py b/cli.py old mode 100644 new mode 100755 index ccc30c8b..9f8b5a6a --- a/cli.py +++ b/cli.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python import click import json #import matplotlib @@ -8,7 +9,6 @@ import os import subprocess from solar.core import actions as xa -from solar.core import deployment as xd from solar.core import resource as xr from solar.core import signals as xs diff --git a/config.yaml b/config.yaml index d52c879b..3af564ca 100644 --- a/config.yaml +++ b/config.yaml @@ -10,5 +10,9 @@ file-system-db: storage-path: /vagrant/tmp/storage template-dir: /vagrant/templates + resources-files-mask: /vagrant/resources/*/*.yaml node_resource_template: /vagrant/resources/ro_node/ + +state: /vagrant/state/ + diff --git a/solar/solar/state.py b/solar/solar/state.py new file mode 100644 index 00000000..148509ec --- /dev/null +++ b/solar/solar/state.py @@ -0,0 +1,91 @@ +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import collections +from collections import deque + +from solar import utils + +import dictdiffer as dd + + +def create(resource, staged_data, commited_data): + """ + :param resource: Resource obj + :param staged_data: dict + :param commited_data: dict + """ + diff = dd.diff( + staged_data[resource.uid], commited_data[resource.uid]) + return LogItem(utils.generate_uuid(), resource.uid, diff) + + +class LogItem(object): + + def __init__(self, uid, res_uid, diff): + self.uid = uid + self.res = res_uid + self.diff = diff + + def to_yaml(self): + return utils.yaml_dump(self.to_dict()) + + def to_dict(self): + return {'uid': self.uid, + 'res': self.res_uid, + 'diff': self.diff} + + def __str__(self): + return self.to_yaml() + + def __repr__(self): + return self.to_yaml() + + +class Log(object): + + def __init__(self, path): + self.path = path + self.items = deque([LogItem(**l) for + l in utils.yaml_load(path)]) + + def add(self, logitem): + self.items.append(logitem) + utils.yaml_dump_to(self.items, path) + + def popleft(self): + item = self.items.popleft() + utils.yaml_dump_to(self.items, path) + return item + + def __repr__(self): + return 'Log({0})'.format(self.path) + + +class Data(collections.MutableMapping): + + def __init__(self, path): + self.path = path + self.store = utils.yaml_load(path) + + def __getitem__(self, key): + return self.store[key] + + def __setitem__(self, key, value): + self.store[key] = value + utils.yaml_dump_to(self.store, path) + + def __delitem__(self, key): + self.store.pop(key) + utils.yaml_dump_to(self.store, path) diff --git a/state/commit_log b/state/commit_log new file mode 100644 index 00000000..e69de29b diff --git a/state/commited_data b/state/commited_data new file mode 100644 index 00000000..e69de29b diff --git a/state/inprogress_log b/state/inprogress_log new file mode 100644 index 00000000..e69de29b diff --git a/state/stage_log b/state/stage_log new file mode 100644 index 00000000..e69de29b diff --git a/state/staged_data b/state/staged_data new file mode 100644 index 00000000..e69de29b