| 1 |
# Copyright (c) 2016 IBM |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# 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, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
from neutronclient._i18n import _ |
| 17 |
|
| 18 |
|
| 19 |
def add_dns_argument_create(parser, resource, attribute): |
| 20 |
# Add dns_name and dns_domain support to network, port and floatingip |
| 21 |
# create |
| 22 |
argument = '--dns-%s' % attribute |
| 23 |
parser.add_argument( |
| 24 |
argument, |
| 25 |
help=_('Assign DNS %(attribute)s to the %(resource)s ' |
| 26 |
'(requires DNS integration ' |
| 27 |
'extension)') % {'attribute': attribute, 'resource': resource}) |
| 28 |
|
| 29 |
|
| 30 |
def args2body_dns_create(parsed_args, resource, attribute): |
| 31 |
# Add dns_name and dns_domain support to network, port and floatingip |
| 32 |
# create |
| 33 |
destination = 'dns_%s' % attribute |
| 34 |
argument = getattr(parsed_args, destination) |
| 35 |
if argument: |
| 36 |
resource[destination] = argument |
| 37 |
|
| 38 |
|
| 39 |
def add_dns_argument_update(parser, resource, attribute): |
| 40 |
# Add dns_name and dns_domain support to network, port and floatingip |
| 41 |
# update |
| 42 |
argument = '--dns-%s' % attribute |
| 43 |
no_argument = '--no-dns-%s' % attribute |
| 44 |
dns_args = parser.add_mutually_exclusive_group() |
| 45 |
dns_args.add_argument( |
| 46 |
argument, |
| 47 |
help=_('Assign DNS %(attribute)s to the %(resource)s ' |
| 48 |
'(requires DNS integration ' |
| 49 |
'extension.)') % {'attribute': attribute, 'resource': resource}) |
| 50 |
dns_args.add_argument( |
| 51 |
no_argument, action='store_true', |
| 52 |
help=_('Unassign DNS %(attribute)s from the %(resource)s ' |
| 53 |
'(requires DNS integration ' |
| 54 |
'extension.)') % {'attribute': attribute, 'resource': resource}) |
| 55 |
|
| 56 |
|
| 57 |
def args2body_dns_update(parsed_args, resource, attribute): |
| 58 |
# Add dns_name and dns_domain support to network, port and floatingip |
| 59 |
# update |
| 60 |
destination = 'dns_%s' % attribute |
| 61 |
no_destination = 'no_dns_%s' % attribute |
| 62 |
argument = getattr(parsed_args, destination) |
| 63 |
no_argument = getattr(parsed_args, no_destination) |
| 64 |
if argument: |
| 65 |
resource[destination] = argument |
| 66 |
if no_argument: |
| 67 |
resource[destination] = "" |