blob: 91d4380ccc206aacfb9fa7fdbe5c8767c450e6ae [file] [log] [blame]
Matteo Scandolo5b7a5d42017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Saleil Bhat1c5593d2017-01-06 15:25:57 -080017import os
18import sys
19from django.db.models import Q, F
Saleil Bhatfda62d42017-02-18 15:07:23 -080020from services.vmme.models import VMMEService, VMMETenant
Saleil Bhat1c5593d2017-01-06 15:25:57 -080021from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
22
23parentdir = os.path.join(os.path.dirname(__file__), "..")
24sys.path.insert(0, parentdir)
25
26class SyncVMMETenant(SyncInstanceUsingAnsible):
27
28 provides = [VMMETenant]
29
30 observes = VMMETenant
31
32 requested_interval = 0
33
34 template_name = "vmmetenant_playbook.yaml"
35
36 service_key_name = "/opt/xos/synchronizers/vmme/vmme_private_key"
37
38 def __init__(self, *args, **kwargs):
39 super(SyncVMMETenant, self).__init__(*args, **kwargs)
40
41 def fetch_pending(self, deleted):
42
43 if (not deleted):
44 objs = VMMETenant.get_tenant_objects().filter(
45 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
46 else:
47 # If this is a deletion we get all of the deleted tenants..
48 objs = VMMETenant.get_deleted_tenant_objects()
49
50 return objs
51
52 def get_vmmeservice(self, o):
53 if not o.provider_service:
54 return None
55
56 vmmeservice = VMMEService.get_service_objects().filter(id=o.provider_service.id)
57
58 if not vmmeservice:
59 return None
60
61 return vmmeservice[0]
62
63 # Gets the attributes that are used by the Ansible template but are not
64 # part of the set of default attributes.
65 def get_extra_attributes(self, o):
66 fields = {}
67 fields['tenant_message'] = o.tenant_message
Saleil Bhat22afba82017-01-21 23:10:09 -080068 fields['image_name'] = o.image_name
Saleil Bhat1c5593d2017-01-06 15:25:57 -080069 return fields
70