Add floating IP associate/disassociate support

Change-Id: Ia3fb63e78a52f76b9c1d42c795ea1a3abfef6562
This commit is contained in:
Zhenguo Niu
2017-05-03 19:31:17 +08:00
parent f401db3b0f
commit 4555085289
3 changed files with 78 additions and 0 deletions

View File

@@ -537,3 +537,68 @@ class ShowServerNetworkInfo(command.Lister):
return (columns,
(utils.get_item_properties(
nic, columns, formatters=formatters) for nic in data))
class AddFloatingIP(command.Command):
_description = _("Add floating IP address to server")
def get_parser(self, prog_name):
parser = super(AddFloatingIP, self).get_parser(prog_name)
parser.add_argument(
"server",
metavar="<server>",
help=_("Server to receive the floating IP address (name or ID)"),
)
parser.add_argument(
"ip_address",
metavar="<ip-address>",
help=_("Floating IP address to assign to server (IP only)"),
)
parser.add_argument(
"--fixed-ip-address",
metavar="<ip-address>",
help=_("Fixed IP address to associate with this floating IP "
"address"),
)
return parser
def take_action(self, parsed_args):
bc_client = self.app.client_manager.baremetal_compute
server = utils.find_resource(
bc_client.server,
parsed_args.server,
)
bc_client.server.add_floating_ip(server.uuid,
parsed_args.ip_address,
parsed_args.fixed_ip_address)
class RemoveFloatingIP(command.Command):
_description = _("Remove floating IP address from server")
def get_parser(self, prog_name):
parser = super(RemoveFloatingIP, self).get_parser(prog_name)
parser.add_argument(
"server",
metavar="<server>",
help=_(
"Server to remove the floating IP address from (name or ID)"
),
)
parser.add_argument(
"ip_address",
metavar="<ip-address>",
help=_("Floating IP address to remove from server (IP only)"),
)
return parser
def take_action(self, parsed_args):
bc_client = self.app.client_manager.baremetal_compute
server = utils.find_resource(
bc_client.server,
parsed_args.server,
)
bc_client.server.remove_floating_ip(server.uuid,
parsed_args.ip_address)

View File

@@ -126,3 +126,14 @@ class ServerManager(base.ManagerWithFind):
def get_server_nics(self, server_id):
url = '/servers/%s/networks' % base.getid(server_id)
return self._list(url, response_key='nics')
def add_floating_ip(self, server_id, ip_address, fixed_ip_address):
url = '/servers/%s/networks/floatingips' % base.getid(server_id)
data = {'address': ip_address,
'fixed_address': fixed_ip_address}
return self._create(url, data=data)
def remove_floating_ip(self, server_id, ip_address):
url = '/servers/%(server)s/networks/floatingips/%(ip)s' % {
'server': base.getid(server_id), 'ip': ip_address}
return self._delete(url)

View File

@@ -48,6 +48,8 @@ openstack.baremetal_compute.v1 =
baremetal_server_update = moganclient.osc.v1.server:UpdateServer
baremetal_server_unlock = moganclient.osc.v1.server:UnLockServer
baremetal_server_netinfo = moganclient.osc.v1.server:ShowServerNetworkInfo
baremetal_server_add_floating_ip = moganclient.osc.v1.server:AddFloatingIP
baremetal_server_remove_floating_ip = moganclient.osc.v1.server:RemoveFloatingIP
baremetal_availability_zone_list = moganclient.osc.v1.availability_zone:ListAvailabilityZone
baremetal_keypair_create = moganclient.osc.v1.keypair:CreateKeyPair
baremetal_keypair_show = moganclient.osc.v1.keypair:ShowKeyPair