2 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
16 # @author: David Blaisonneau <david.blaisonneau@orange.com>
17 # @author: Arnaud Morin <arnaud1.morin@orange.com>
19 from opensteak.foreman_objects.objects import ForemanObjects
22 class Subnets(ForemanObjects):
29 def checkAndCreate(self, key, payload, domainId):
30 """ Function checkAndCreate
31 Check if a subnet exists and create it if not
33 @param key: The targeted subnet
34 @param payload: The targeted subnet description
35 @param domainId: The domainId to be attached wiuth the subnet
36 @return RETURN: The id of the subnet
43 #~ Ensure subnet contains the domain
45 for domain in self[key]['domains']:
46 subnetDomainIds.append(domain['id'])
47 if domainId not in subnetDomainIds:
48 subnetDomainIds.append(domainId)
49 self[key]["domain_ids"] = subnetDomainIds
50 if len(self[key]["domains"]) is not len(subnetDomainIds):
54 def removeDomain(self, subnetId, domainId):
55 """ Function removeDomain
56 Delete a domain from a subnet
58 @param subnetId: The subnet Id
59 @param domainId: The domainId to be attached wiuth the subnet
60 @return RETURN: boolean
63 for domain in self[subnetId]['domains']:
64 subnetDomainIds.append(domain['id'])
65 subnetDomainIds.remove(domainId)
66 self[subnetId]["domain_ids"] = subnetDomainIds
67 return len(self[subnetId]["domains"]) is len(subnetDomainIds)