forked from quattor/aquilon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quattor#83 in AQUILON_AQD/aqd from ~AQBLD/aqd:for_…
…merge/master/by_topic/shared_sa to master * commit 'b3aee3eae3a02513cfbc7ab1657740dc6cd1f11c': Support for shared-service-name resources in resourcegroups
- Loading branch information
Showing
16 changed files
with
579 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*- | ||
# ex: set expandtab softtabstop=4 shiftwidth=4: | ||
# | ||
# Copyright (C) 2019 Contributor | ||
# | ||
# Licensed 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 sqlalchemy import ( | ||
Boolean, | ||
Column, | ||
ForeignKey, | ||
) | ||
from sqlalchemy.orm import ( | ||
backref, | ||
relation, | ||
) | ||
|
||
from aquilon.aqdb.model import ( | ||
Fqdn, | ||
Resource, | ||
) | ||
|
||
_TN = 'shared_sn' | ||
|
||
|
||
class SharedServiceName(Resource): | ||
"""Shared service name resources""" | ||
__tablename__ = _TN | ||
|
||
resource_id = Column(ForeignKey(Resource.id, ondelete='CASCADE', | ||
name='shared_sn_resource_id_fk'), | ||
primary_key=True) | ||
|
||
# if true, indicates that address-aliases should be created from the FQDN | ||
# to particular service addresses in the same resourcegroup. | ||
sa_aliases = Column(Boolean, nullable=False) | ||
|
||
# FQDN is the 'shared service name' that is chosen -- must be a valid name | ||
# that the address-alias records can be created against | ||
fqdn_id = Column(ForeignKey(Fqdn.id), nullable=False, index=True) | ||
|
||
fqdn = relation(Fqdn, lazy=False, innerjoin=True, | ||
backref=backref('shared_service_names')) | ||
|
||
__table_args__ = ({'info': {'unique_fields': ['name', 'holder']}},) | ||
|
||
__mapper_args__ = {'polymorphic_identity': _TN} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*- | ||
# ex: set expandtab softtabstop=4 shiftwidth=4: | ||
# | ||
# Copyright (C) 2019 Contributor | ||
# | ||
# Licensed 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. | ||
"""Contains the logic for `aq add shared service name`.""" | ||
|
||
from aquilon.exceptions_ import ArgumentError | ||
from aquilon.worker.broker import BrokerCommand # noqa | ||
from aquilon.worker.commands.add_resource import CommandAddResource | ||
from aquilon.aqdb.model import ( | ||
AddressAlias, | ||
BundleResource, | ||
Fqdn, | ||
ResourceGroup, | ||
SharedServiceName, | ||
) | ||
|
||
|
||
class CommandAddSharedServiceName(CommandAddResource): | ||
|
||
required_parameters = ['fqdn', 'name', 'resourcegroup', 'sa_aliases'] | ||
resource_class = SharedServiceName | ||
resource_name = 'name' | ||
|
||
def render(self, **kwargs): | ||
# This command deliberately does not allow the resource holder to | ||
# be specified as anything other than a resource-group, so fill in | ||
# the missing ones here. | ||
for h in ('hostname', 'cluster', 'metacluster', 'personality', | ||
'archetype', 'eon_id', 'grn'): | ||
kwargs[h] = None | ||
|
||
super(CommandAddSharedServiceName, self).render(**kwargs) | ||
|
||
def setup_resource(self, session, logger, dbres, reason, | ||
fqdn, sa_aliases, dns_environment, **_): | ||
# ensure this belongs in a resource-group; use the fact the | ||
# holder is already determined | ||
if (not isinstance(dbres.holder, BundleResource) or | ||
not isinstance(dbres.holder.resourcegroup, ResourceGroup)): | ||
raise ArgumentError("{0} must be in a resource-group " | ||
"(got {1:c})".format(dbres, dbres.holder)) | ||
|
||
# ensure no other shared-service-name resource than ourself is present | ||
# in the group. | ||
for res in dbres.holder.resources: | ||
if isinstance(res, SharedServiceName) and (res != dbres): | ||
raise ArgumentError("{0} already has a {1:c} resource". | ||
format(dbres.holder.resourcegroup, res)) | ||
|
||
dbfqdn = Fqdn.get_or_create(session, dns_environment=dns_environment, | ||
fqdn=fqdn) | ||
|
||
# if sa_aliases is true, ensure the FQDN is unique except for | ||
# address-aliases; if sa_aliases is false, no DNS records using | ||
# that (LHS) may exist. | ||
for dnsrec in dbfqdn.dns_records: | ||
if not sa_aliases or not isinstance(dnsrec, AddressAlias): | ||
raise ArgumentError("{0:s} cannot be used as a shared " | ||
"service name FQDN, as {1} already " | ||
"exists".format(fqdn, dnsrec)) | ||
if dbfqdn.shared_service_names: | ||
raise ArgumentError("{0:s} cannot be used as a shared service " | ||
"name FQDN, as {1} already exists" | ||
.format(fqdn, dbfqdn.shared_service_names[0])) | ||
|
||
dbres.sa_aliases = sa_aliases | ||
dbres.fqdn = dbfqdn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*- | ||
# ex: set expandtab softtabstop=4 shiftwidth=4: | ||
# | ||
# Copyright (C) 2019 Contributor | ||
# | ||
# Licensed 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 aquilon.aqdb.model import ( | ||
DnsRecord, | ||
SharedServiceName, | ||
) | ||
from aquilon.worker.broker import BrokerCommand | ||
from aquilon.worker.dbwrappers.change_management import ChangeManagement | ||
from aquilon.worker.dbwrappers.resources import get_resource_holder | ||
|
||
|
||
class CommandDelSharedServiceName(BrokerCommand): | ||
required_parameters = ['name', 'resourcegroup'] | ||
resource_class = SharedServiceName | ||
resource_name = 'name' | ||
|
||
def render(self, session, logger, plenaries, name, | ||
resourcegroup, user, justification, reason, **kwargs): | ||
holder = get_resource_holder(session, logger, resgroup=resourcegroup, | ||
compel=False) | ||
|
||
# Validate change-management | ||
cm = ChangeManagement(session, user, justification, reason, | ||
logger, self.command, **kwargs) | ||
cm.consider(holder) | ||
cm.validate() | ||
|
||
dbssn = SharedServiceName.get_unique(session, name=name, | ||
holder=holder, compel=True) | ||
|
||
holder.resources.remove(dbssn) | ||
|
||
# delete the FQDN if it is orphaned | ||
dbfqdn = dbssn.fqdn | ||
|
||
q = session.query(DnsRecord) | ||
q = q.filter_by(fqdn=dbfqdn) | ||
|
||
if q.count() == 0: | ||
session.delete(dbfqdn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*- | ||
# ex: set expandtab softtabstop=4 shiftwidth=4: | ||
# | ||
# Copyright (C) 2019 Contributor | ||
# | ||
# Licensed 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. | ||
"""SharedServiceName Resource formatter.""" | ||
|
||
from aquilon.aqdb.model import SharedServiceName | ||
from aquilon.worker.formats.formatters import ObjectFormatter | ||
from aquilon.worker.formats.resource import ResourceFormatter | ||
|
||
|
||
class SharedServiceNameFormatter(ResourceFormatter): | ||
def extra_details(self, pn, indent=""): | ||
details = [] | ||
details.append(indent + " FQDN: %s" % pn.fqdn) | ||
details.append(indent + " SA Aliases: %s" % pn.sa_aliases) | ||
return details | ||
|
||
|
||
ObjectFormatter.handlers[SharedServiceName] = SharedServiceNameFormatter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.