def create_deployment(self, name, blueprint_name, inputs=None, ignored_modules=None): blueprint = self.get_blueprint(blueprint_name) deployment_plan, nodes, node_instances = _parse_plan( blueprint['plan'], inputs, ignored_modules) workflows = [] for wf_name, wf in deployment_plan.get('workflows', {}).items(): wf = wf.copy() wf['name'] = wf_name workflows.append(wf) deployment = { 'id': name, 'blueprint_id': blueprint['id'], 'plan': deployment_plan, 'nodes': {n.id: n for n in nodes}, 'created_at': datetime.utcnow(), 'inputs': inputs, 'workflows': workflows, 'scaling_groups': deployment_plan['scaling_groups'], } self.store_deployment(name, deployment) for instance in node_instances: self.store_instance(name, NodeInstance(instance))
def _make_instance(self, **kwargs): instance = { 'id': 'node1_1', 'node_id': 'node1', 'relationships': [], } instance.update(kwargs) return NodeInstance(instance)
def __init__(self, node_instances): self.update(node_instances) self['added_and_related'] = [ NodeInstance(instance) for instance in self.get('added_and_related', []) ] self['removed_and_related'] = [ NodeInstance(instance) for instance in self.get('removed_and_related', []) ] self['before_modification'] = [ NodeInstance(instance) for instance in self.get('before_modification', []) ] self['before_rollback'] = [ NodeInstance(instance) for instance in self.get('before_rollback', []) ]
def mock_get_node_instances(self): return [ NodeInstance({'node_id': 'mock_node', 'runtime_properties': { 'provider': 'mock_provider', 'manager_ip': 'mock_manager_ip', 'ssh_user': '******', 'ssh_key_path': 'mock_ssh_key_path', 'rest_port': 'mock_rest_port'}}) ]
def _node_instance(tenant_name, ni_id, node_id, dep_id, state='started'): return NodeInstance({ 'tenant_name': tenant_name, 'id': ni_id, 'host_id': ni_id, 'node_id': node_id, 'deployment_id': dep_id, 'state': state })
def put_node_instance(node_instance_id, state='started', runtime_properties=None, relationships=None): node_instances[node_instance_id] = NodeInstance({ 'id': node_instance_id, 'state': state, 'version': 0, 'runtime_properties': runtime_properties, 'relationships': relationships })
def node_instance_get_mock(): return NodeInstance({ 'id': uuid4(), 'deployment_id': 'deployment_id', 'host_id': 'host_id', 'node_id': 'node_id', 'state': 'started', 'runtime_properties': { 'floating_ip': '127.0.0.1' } })
def _parse_plan(blueprint_path, inputs, ignored_modules): if dsl_parser is None: raise ImportError('cloudify-dsl-parser must be installed to ' 'execute local workflows. ' '(e.g. "pip install cloudify-dsl-parser")') plan = dsl_tasks.prepare_deployment_plan( dsl_parser.parse_from_path(blueprint_path), inputs=inputs) nodes = [Node(node) for node in plan['nodes']] node_instances = [ NodeInstance(instance) for instance in plan['node_instances'] ] _prepare_nodes_and_instances(nodes, node_instances, ignored_modules) return plan, nodes, node_instances
def node_instance_get_mock(): return NodeInstance({ 'id': uuid4(), 'deployment_id': 'deployment_id', 'host_id': 'host_id', 'node_id': 'node_id', 'state': 'started', 'runtime_properties': { 'floating_ip': '127.0.0.1' }, 'permission': 'creator', 'created_by': 'admin', 'tenant_name': DEFAULT_TENANT_NAME })
def put_node_instance(node_instance_id, node_id=None, state='started', runtime_properties=None, relationships=None, index=None): node_instances[node_instance_id] = NodeInstance({ 'id': node_instance_id, 'node_id': node_id or node_instance_id, 'state': state, 'version': 0, 'runtime_properties': runtime_properties, 'relationships': relationships, 'index': index or 0, })
def _parse_plan(blueprint_path, inputs, ignored_modules, resolver, validate_version): if dsl_parser is None: raise ImportError('cloudify-dsl-parser must be installed to ' 'execute local workflows. ' '(e.g. "pip install cloudify-dsl-parser") [{0}]' .format(_import_error)) plan = dsl_tasks.prepare_deployment_plan( dsl_parser.parse_from_path( dsl_file_path=blueprint_path, resolver=resolver, validate_version=validate_version), inputs=inputs) nodes = [Node(node) for node in plan['nodes']] node_instances = [NodeInstance(instance) for instance in plan['node_instances']] _prepare_nodes_and_instances(nodes, node_instances, ignored_modules) return plan, nodes, node_instances
def _load_instance(self, node_instance_id): with self._lock(node_instance_id): with open(self._instance_path(node_instance_id)) as f: return NodeInstance(json.loads(f.read()))
def _load_instance(self, node_instance_id): with self._lock(node_instance_id): with open(self._instance_path(node_instance_id)) as f: return NodeInstance( json.loads(f.read(), object_hook=load_datetime))
def load_instance(self, deployment_id, node_instance_id): with open(self._instance_path(deployment_id, node_instance_id)) as f: return NodeInstance(json.load(f, object_hook=load_datetime))