Added abstract Driver class in drs/drivers/nttcis
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/adcf3bdb Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/adcf3bdb Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/adcf3bdb Branch: refs/heads/trunk Commit: adcf3bdb938bc9093a0a0772cd71b02adfedb10c Parents: 15ce000 Author: mitch <[email protected]> Authored: Fri Oct 26 16:08:44 2018 -0400 Committer: mitch <[email protected]> Committed: Fri Oct 26 16:08:44 2018 -0400 ---------------------------------------------------------------------- .gitignore | 2 +- libcloud/drs/__init__.py | 0 libcloud/drs/base.py | 194 ++++++++++++++++++++++++++++++++++ libcloud/drs/drivers/__init__.py | 18 ++++ libcloud/drs/drivers/nttcis.py | 39 +++++++ libcloud/drs/providers.py | 41 +++++++ libcloud/drs/types.py | 43 ++++++++ 7 files changed, 336 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 28c95d5..7b71b9b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,4 @@ pip-selfcheck.json report.html .pytest_cache tests/ -drs/ + http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/__init__.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/__init__.py b/libcloud/drs/__init__.py new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/base.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/base.py b/libcloud/drs/base.py new file mode 100644 index 0000000..157fe5a --- /dev/null +++ b/libcloud/drs/base.py @@ -0,0 +1,194 @@ + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from libcloud.common.base import ConnectionKey, BaseDriver +from libcloud.common.types import LibcloudError + + +class DRSConsistencyGroup(object): + """ + Provide a common interface for handling DRS. + """ + + def __init__(self, id, name, description, journalSizeGB, serverPairSourceServerId, serverPairtargetServerId, + driver, extra=None): + """ + :param id: Load balancer ID. + :type id: ``str`` + + :param name: Load balancer name. + :type name: ``str`` + + :param state: State this loadbalancer is in. + :type state: :class:`libcloud.loadbalancer.types.State` + + :param ip: IP address of this loadbalancer. + :type ip: ``str`` + + :param port: Port of this loadbalancer. + :type port: ``int`` + + :param driver: Driver this loadbalancer belongs to. + :type driver: :class:`.Driver` + + :param extra: Provider specific attributes. (optional) + :type extra: ``dict`` + """ + self.id = str(id) if id else None + self.name = name + self.description = description + self.journalSizeGB = journalSizeGB + + self.serverPairSourceServerId = serverPairSourceServerId + self.serverPairtargetServerId = serverPairtargetServerId + self.driver = driver + self.extra = extra or {} + + +class Driver(BaseDriver): + """ + A base Driver class to derive from + + This class is always subclassed by a specific driver. + """ + + name = None + website = None + + connectionCls = ConnectionKey + + def __init__(self, key, secret=None, secure=True, host=None, + port=None, **kwargs): + super(Driver, self).__init__(key=key, secret=secret, secure=secure, + host=host, port=port, **kwargs) + + def create_consistency_group(self, name, journal_sz_gb, + source_server_id, target_server_id): + """ + :param name: Name of the consistency group to create + :type name: ``str`` + :param journal_sz_gb: Size in 10 Gb increments of the consistency + group's journal + :type journal_sz_gb: ``str`` + :param source_server_id: The id of the server to copy from + :type source_server_id: ``str`` + :param target_server_id: The id of the server to copy to + :type target_server_id: ``str`` + :return: :class: `ConsistencyGroup` + """ + raise NotImplementedError( + 'create_consistency_group not implemented for this driver') + + def list_consistency_groups(self): + """ + List all consistency groups + + :rtype: ``list`` of :class:`ConsistencyGroup` + """ + raise NotImplementedError( + 'list_consistency_groups not implemented for this driver') + + def get_consistency_group(self, consistency_group_id): + """ + Return a :class:`ConsistencyGroup` object. + + :param consistency_group_id: id of a consistency group you want to fetch + :type consistency_group_id: ``str`` + + :rtype: :class:`ConsistencyGroup` + """ + + raise NotImplementedError( + 'get_consistency_group not implemented for this driver') + + def delete_consistency_group(self, consistency_group_id): + """ + Delete a consistency group + + :param consistency_group_id: Id of consistency group to delete + :type consistency_group_id: ``str`` + + :return: ``True`` For successful deletion, otherwise ``False``. + :rtype: ``bool`` + """ + + raise NotImplementedError( + 'delete_consistency_group not implemented for this driver') + + def list_consistency_group_snapshots(self, consistency_group_id): + """ + Return a list of consistency group snapshots. + + :param consistency_group_id: id of a consistency group to fetch + snapshots from. + :type consistency_group_id: ``str`` + :rtype: ``list`` + """ + + raise NotImplementedError( + 'list_consistency_group_snapshots not implemented for this driver') + + def expand_journal(self, consistency_group_id, size_gb): + """ + :param consistency_group_id: consistency group's id with journal + to expand + :type consistency_group_id: ``str`` + :param size_gb: Size in increments of 10 Gb to expand journal. + :return: ``True`` For successful deletion, otherwise ``False``. + :rtype: ``bool`` + """ + + raise NotImplementedError( + 'expand_journal not implemented for this driver') + + def start_failover_preview(self, consistency_group_id, snapshot_id): + """ + :param consistency_group_id: consistency group's id with journal + to expand + :type consistency_group_id: ``str `` + :param snapshot_id: Snapshot Id to bring into preview mode. + :type snapshot_id: ``str`` + :return: ``True`` For successful deletion, otherwise ``False``. + :rtype: ``bool`` + """ + + raise NotImplementedError( + 'start_failover_preview not implemented for this driver') + + def stop_failover_preview(self, consistency_group_id): + """ + :param consistency_group_id: Consistency group id of consistency + group to brought out of + PREVIEWING_SNAHSHOT and into DRS_MODE. + :type consistency_group_id: ``str`` + :return: ``True`` For successful deletion, otherwise ``False``. + :rtype: ``bool`` + """ + + raise NotImplementedError( + 'stop_failover_preview not implemented for this driver') + + def initiate_failover(self, consistency_group_id): + """ + :param consistency_group_id: Consistency group id of consistency + group on which to initiate failover. + :type consistency_group_id: ``str`` + :return: ``True`` For successful deletion, otherwise ``False``. + :rtype: ``bool`` + """ + + raise NotImplementedError( + 'initiate_failover not implemented for this driver') \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/drivers/__init__.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/drivers/__init__.py b/libcloud/drs/drivers/__init__.py new file mode 100644 index 0000000..f2f9f29 --- /dev/null +++ b/libcloud/drs/drivers/__init__.py @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__all__ = [ + 'nttcis' +] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/drivers/nttcis.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/drivers/nttcis.py b/libcloud/drs/drivers/nttcis.py new file mode 100644 index 0000000..3467277 --- /dev/null +++ b/libcloud/drs/drivers/nttcis.py @@ -0,0 +1,39 @@ +from libcloud.utils.py3 import ET +from libcloud.common.nttcis import NttCisConnection +from libcloud.common.nttcis import API_ENDPOINTS +from libcloud.common.nttcis import DEFAULT_REGION +from libcloud.drs.types import Provider +from libcloud.drs.base import Driver +from libcloud.common.types import LibcloudError + + +class NttCisDRSDriver(Driver): + """ + NttCis node driver. + """ + + selected_region = None + connectionCls = NttCisConnection + name = 'NTTC-CIS DRS Consistencty Groups' + website = 'https://cloud.nttcis.com/' + type = Provider.NTTCIS + api_version = 1.0 + + network_domain_id = None + + def __init__(self, key, secret=None, secure=True, host=None, port=None, + api_version=None, region=DEFAULT_REGION, **kwargs): + + if region not in API_ENDPOINTS and host is None: + raise ValueError( + 'Invalid region: %s, no host specified' % (region)) + if region is not None: + self.selected_region = API_ENDPOINTS[region] + + super(NttCisDRSDriver, self).__init__(key=key, + secret=secret, + secure=secure, host=host, + port=port, + api_version=api_version, + region=region, + **kwargs) http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/providers.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/providers.py b/libcloud/drs/providers.py new file mode 100644 index 0000000..d214d17 --- /dev/null +++ b/libcloud/drs/providers.py @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from libcloud.loadbalancer.types import Provider +from libcloud.loadbalancer.types import OLD_CONSTANT_TO_NEW_MAPPING +from libcloud.common.providers import get_driver as _get_provider_driver +from libcloud.common.providers import set_driver as _set_provider_driver + +__all__ = [ + "Provider", + "DRIVERS", + "get_driver", +] + +DRIVERS = { + Provider.NTTCIS: + ('libcloud.drs.drivers.nttcis', 'NttCisDRSDriver'), +} + + +def get_driver(provider): + deprecated_constants = OLD_CONSTANT_TO_NEW_MAPPING + return _get_provider_driver(drivers=DRIVERS, provider=provider, + deprecated_constants=deprecated_constants) + + +def set_driver(provider, module, klass): + return _set_provider_driver(drivers=DRIVERS, provider=provider, + module=module, klass=klass) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/adcf3bdb/libcloud/drs/types.py ---------------------------------------------------------------------- diff --git a/libcloud/drs/types.py b/libcloud/drs/types.py new file mode 100644 index 0000000..b902f74 --- /dev/null +++ b/libcloud/drs/types.py @@ -0,0 +1,43 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__all__ = [ + "Provider", + "LibcloudDRSError", + "LibcloudDRSImmutableError", + +] + +from libcloud.common.types import LibcloudError + + +class LibcloudDRSError(LibcloudError): + pass + + +class LibcloudDRSImmutableError(LibcloudDRSError): + pass + + +class Provider(object): + """ + Defines for each of the supported providers + + Non-Dummy drivers are sorted in alphabetical order. Please preserve this + ordering when adding new drivers. + + :cvar ALIYUN_SLB: Aliyun SLB loadbalancer driver + """ + NTTCIS = 'nttcis'
