@rest_initialiser(version_check=True)
def execute(self, opts):
    flags_used = sum([opts.set, opts.list, opts.remove])
    if (flags_used != 1):
        _exit_if_errors(['Use exactly one of --set, --list or --remove'])
    if (opts.set or opts.remove):
        if (not opts.node):
            _exit_if_errors(['--node has to be set when using --set or --remove'])
        (hostname, port) = self._get_host_port(opts.node)
        url = urllib.parse.urlparse(opts.cluster)
        if url.scheme:
            scheme = url.scheme
            if (url.port and (not port)):
                port = url.port
        elif (not port):
            (_, old_port) = self._get_host_port(opts.cluster)
            if old_port:
                port = old_port
        if scheme:
            cluster = f'{scheme}://'
        cluster += hostname
        if port:
            cluster += f':{port}'
        opts.cluster = cluster
        self.rest = ClusterManager(opts.cluster, opts.username, opts.password, opts.ssl, opts.ssl_verify, opts.cacert, opts.debug)
    if opts.set:
        (ports, error) = self._parse_ports(opts.ports)
        _exit_if_errors(error)
        (_, error) = self.rest.set_alternate_address(opts.alternate_hostname, ports)
        _exit_if_errors(error)
    if opts.remove:
        (_, error) = self.rest.delete_alternate_address()
        _exit_if_errors(error)
        _success('Alternate address configuration deleted')
    if opts.list:
        (add, error) = self.rest.get_alternate_address()
        _exit_if_errors(error)
        if (opts.output == 'standard'):
            port_names = set()
            for node in add:
                if (('alternateAddresses' in node) and ('ports' in node['alternateAddresses']['external'])):
                    for port in node['alternateAddresses']['external']['ports'].keys():
                        port_names.add(port)
            print('{:20}{:20}{}'.format('Hostname', 'Alternate Address', 'Ports (Primary/Alternate)'))
            print('{:40}'.format(' '), end='')
            port_names = sorted(port_names)
            for port in port_names:
                column_size = (len(port) + 1)
                if (column_size < 11):
                    column_size = 11
                print(f'{port:{column_size}}', end='')
            print()
            for node in add:
                if ('alternateAddresses' in node):
                    try:
                        print(f"{node['hostname']:20}{node['alternateAddresses']['external']['hostname']:20}", end='')
                    except KeyError:
                        host = 'UNKNOWN'
                        print(f"{host:20}{node['alternateAddresses']['external']['hostname']:20}", end='')
                    for port in port_names:
                        column_size = (len(port) + 1)
                        if (column_size < 11):
                            column_size = 11
                        ports = ' '
                        if (port in node['alternateAddresses']['external']['ports']):
                            ports = f"{str(node['services'][port])}/{str(node['alternateAddresses']['external']['ports'][port])}"
                        print(f'{ports:{column_size}}', end='')
                    print()
                else:
                    try:
                        print(f"{node['hostname']}")
                    except KeyError:
                        print('UNKNOWN')
        else:
            print(json.dumps(add))
@rest_initialiser(version_check=True)
def execute(self, opts):
    flags_used = sum([opts.set, opts.list, opts.remove])
    if (flags_used != 1):
        _exit_if_errors(['Use exactly one of --set, --list or --remove'])
    if (opts.set or opts.remove):
        if (not opts.node):
            _exit_if_errors(['--node has to be set when using --set or --remove'])
        (hostname, port) = self._get_host_port(opts.node)
        url = urllib.parse.urlparse(opts.cluster)
        if url.scheme:
            scheme = url.scheme
            if (url.port and (not port)):
                port = url.port
        elif (not port):
            (_, old_port) = self._get_host_port(opts.cluster)
            if old_port:
                port = old_port
        if scheme:
            cluster = f'{scheme}://'
        cluster += hostname
        if port:
            cluster += f':{port}'
        opts.cluster = cluster
        self.rest = ClusterManager(opts.cluster, opts.username, opts.password, opts.ssl, opts.ssl_verify, opts.cacert, opts.debug)
    if opts.set:
        (ports, error) = self._parse_ports(opts.ports)
        _exit_if_errors(error)
        (_, error) = self.rest.set_alternate_address(opts.alternate_hostname, ports)
        _exit_if_errors(error)
    if opts.remove:
        (_, error) = self.rest.delete_alternate_address()
        _exit_if_errors(error)
        _success('Alternate address configuration deleted')
    if opts.list:
        (add, error) = self.rest.get_alternate_address()
        _exit_if_errors(error)
        if (opts.output == 'standard'):
            port_names = set()
            for node in add:
                if (('alternateAddresses' in node) and ('ports' in node['alternateAddresses']['external'])):
                    for port in node['alternateAddresses']['external']['ports'].keys():
                        port_names.add(port)
            print('{:20}{:20}{}'.format('Hostname', 'Alternate Address', 'Ports (Primary/Alternate)'))
            print('{:40}'.format(' '), end=)
            port_names = sorted(port_names)
            for port in port_names:
                column_size = (len(port) + 1)
                if (column_size < 11):
                    column_size = 11
                print(f'{port:{column_size}}', end=)
            print()
            for node in add:
                if ('alternateAddresses' in node):
                    try:
                        print(f"{node['hostname']:20}{node['alternateAddresses']['external']['hostname']:20}", end=)
                    except KeyError:
                        host = 'UNKNOWN'
                        print(f"{host:20}{node['alternateAddresses']['external']['hostname']:20}", end=)
                    for port in port_names:
                        column_size = (len(port) + 1)
                        if (column_size < 11):
                            column_size = 11
                        ports = ' '
                        if (port in node['alternateAddresses']['external']['ports']):
                            ports = f"{str(node['services'][port])}/{str(node['alternateAddresses']['external']['ports'][port])}"
                        print(f'{ports:{column_size}}', end=)
                    print()
                else:
                    try:
                        print(f"{node['hostname']}")
                    except KeyError:
                        print('UNKNOWN')
        else:
            print(json.dumps(add))