2012-11-28 13:28:14 +00:00
|
|
|
# Copyright 2012 Managed I.T.
|
|
|
|
#
|
|
|
|
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
|
|
|
#
|
|
|
|
# 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.
|
2013-12-16 15:41:51 +01:00
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
import logging
|
2013-12-16 15:41:51 +01:00
|
|
|
|
2013-06-09 21:18:36 +01:00
|
|
|
from designateclient.cli import base
|
|
|
|
from designateclient.v1.servers import Server
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ListServersCommand(base.ListCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""List Servers"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
2013-04-11 12:50:28 +01:00
|
|
|
columns = ['id', 'name']
|
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.servers.list()
|
|
|
|
|
|
|
|
|
|
|
|
class GetServerCommand(base.GetCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Get Server"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(GetServerCommand, self).get_parser(prog_name)
|
|
|
|
|
2015-09-24 08:56:07 +09:00
|
|
|
parser.add_argument('id', help="Server ID.")
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.servers.get(parsed_args.id)
|
|
|
|
|
|
|
|
|
|
|
|
class CreateServerCommand(base.CreateCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Create Server"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(CreateServerCommand, self).get_parser(prog_name)
|
|
|
|
|
2015-09-24 08:56:07 +09:00
|
|
|
parser.add_argument('--name', help="Server name.", required=True)
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
server = Server(
|
|
|
|
name=parsed_args.name,
|
|
|
|
)
|
|
|
|
|
|
|
|
return self.client.servers.create(server)
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateServerCommand(base.UpdateCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Update Server"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(UpdateServerCommand, self).get_parser(prog_name)
|
|
|
|
|
2015-09-24 08:56:07 +09:00
|
|
|
parser.add_argument('id', help="Server ID.")
|
|
|
|
parser.add_argument('--name', help="Server name.")
|
2012-12-14 13:04:30 -08:00
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
2013-06-09 15:06:11 +01:00
|
|
|
# TODO(kiall): API needs updating.. this get is silly
|
2012-11-28 13:28:14 +00:00
|
|
|
server = self.client.servers.get(parsed_args.id)
|
|
|
|
|
2012-12-14 13:04:30 -08:00
|
|
|
if parsed_args.name:
|
|
|
|
server.name = parsed_args.name
|
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
return self.client.servers.update(server)
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteServerCommand(base.DeleteCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Delete Server"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeleteServerCommand, self).get_parser(prog_name)
|
|
|
|
|
2015-09-24 08:56:07 +09:00
|
|
|
parser.add_argument('id', help="Server ID.")
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.servers.delete(parsed_args.id)
|