Matteo Scandolo | ede125b | 2017-08-08 13:05:25 -0700 | [diff] [blame^] | 1 | |
| 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 | |
Scott Baker | c41914d | 2017-06-26 14:00:52 -0700 | [diff] [blame] | 17 | def CreateOrFind(kind, args): |
| 18 | objs=ListAll(kind, args.copy()) |
| 19 | if objs: |
| 20 | id_name = {"ServiceProvider": "service_provider_id", |
| 21 | "ContentProvider": "content_provider_id", |
| 22 | "OriginServer": "origin_server_id", |
| 23 | "CDNPrefix": "cdn_prefix_id"} |
| 24 | print kind, "exists with args", args |
| 25 | return objs[0].get(id_name[kind]) |
| 26 | else: |
| 27 | print "create", kind, "with args", args |
| 28 | return Create(kind, args) |
| 29 | sp=CreateOrFind("ServiceProvider", {"account": "cord", "name": "cord", "enabled": True}) |
| 30 | cp=CreateOrFind("ContentProvider", {"account": "test", "name": "test", "enabled": True, "service_provider_id": sp}) |
| 31 | ors=CreateOrFind("OriginServer", {"url": "http://www.cs.arizona.edu", "content_provider_id": cp, "service_type": "HyperCache"}) |
| 32 | pre=CreateOrFind("CDNPrefix", {"service": "HyperCache", "enabled": True, "content_provider_id": cp, "cdn_prefix": "test.vicci.org", "default_origin_server": "http://www.cs.arizona.edu"}) |
| 33 | cp=CreateOrFind("ContentProvider", {"account": "onlab", "name": "onlab", "enabled": True, "service_provider_id": sp}) |
| 34 | ors=CreateOrFind("OriginServer", {"url": "http://onlab.vicci.org", "content_provider_id": cp, "service_type": "HyperCache"}) |
| 35 | pre=CreateOrFind("CDNPrefix", {"service": "HyperCache", "enabled": True, "content_provider_id": cp, "cdn_prefix": "onlab.vicci.org", "default_origin_server": "http://onlab.vicci.org"}) |