Scott Baker | 62c7eaf | 2018-05-22 15:59:26 -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 | |
| 17 | from distutils.version import LooseVersion |
| 18 | from synchronizers.new_base.syncstep import SyncStep |
| 19 | |
| 20 | class NewOpenStackSyncStep(SyncStep): |
| 21 | """ XOS Sync step for copying data to OpenStack |
| 22 | """ |
| 23 | |
| 24 | def __init__(self, *args, **kwargs): |
| 25 | # super() does not work here... |
| 26 | SyncStep.__init__(self, *args, **kwargs) |
| 27 | |
| 28 | def connect_openstack_admin(self, service, required_version=None): |
| 29 | import openstack |
| 30 | |
| 31 | if required_version: |
| 32 | if LooseVersion(openstack.version.__version__) < LooseVersion(required_version): |
| 33 | raise Exception("Insufficient OpenStack library version", |
| 34 | installed_version=openstack.version__version__, |
| 35 | required_version=required_version) |
| 36 | |
| 37 | conn = openstack.connect(auth_url=service.auth_url, |
| 38 | project_name="admin", |
| 39 | username=service.admin_user, |
| 40 | password=service.admin_password, |
| 41 | user_domain_name="Default", |
| 42 | project_domain_name="Default") |
| 43 | return conn |
| 44 | |
| 45 | def connect_openstack_slice(self, slice, required_version=None): |
| 46 | import openstack |
| 47 | |
| 48 | trust_domain = slice.trust_domain |
| 49 | service = trust_domain.owner.leaf_model |
| 50 | |
| 51 | if required_version: |
| 52 | if LooseVersion(openstack.version.__version__) < LooseVersion(required_version): |
| 53 | raise Exception("Insufficient OpenStack library version", |
| 54 | installed_version=openstack.version__version__, |
| 55 | required_version=required_version) |
| 56 | |
| 57 | # This is not working yet... |
| 58 | |
| 59 | conn = openstack.connect(auth_url=service.auth_url, |
| 60 | project_name=slice.name, |
| 61 | username=service.admin_user, |
| 62 | password=service.admin_password, |
| 63 | user_domain_name="Default", |
| 64 | project_domain_name=trust_domain.name) |
| 65 | return conn |
| 66 | |
| 67 | # TODO(smbaker): This should be explained. |
| 68 | def __call__(self, **args): |
| 69 | return self.call(**args) |