コード例 #1
0
ファイル: dhcp.py プロジェクト: zhuzhichaoTM/neutron-diagnose
 def get_parser(self, prog_name):
     parser = super(CheckVmIp, self).get_parser(prog_name)
     parser.add_argument(
         'instance_id',
         metavar='<instance-id>',
         help=_('the instance uuid.'),
     )
     parser.add_argument(
         'fixed_ip',
         metavar='<fixed-ip>',
         help=_('the fixed ip of instance.'),
     )
     return parser
コード例 #2
0
 def get_parser(self, prog_name):
     parser = super(CheckVmFloatingIP, self).get_parser(prog_name)
     parser.add_argument(
         'floatingip-id',
         metavar='<floatingip-id>',
         help=_('the floatingip uuid.'),
     )
     return parser
コード例 #3
0
 def get_parser(self, prog_name):
     parser = super(CheckRouterBrainSplit, self).get_parser(prog_name)
     parser.add_argument(
         'router_id',
         metavar='<router-id>',
         help=_('the router uuid.'),
     )
     return parser
コード例 #4
0
def build_option_parser(parser):
    """Hook to add global options"""
    parser.add_argument(
        '--ssh-key-file',
        metavar='<ssh-key-file>',
        default=constants.SSH_PRIVATE_KEY,
        help=_("The ssh key file."))
    return parser
コード例 #5
0
 def get_parser(self, prog_name):
     parser = super(CheckSgRule, self).get_parser(prog_name)
     parser.add_argument(
         'port-id',
         metavar='<port-id>',
         help=_('the port uuid.'),
     )
     return parser
コード例 #6
0
def build_option_parser(parser):
    """Hook to add global options"""
    parser.add_argument('--os-network-api-version',
                        metavar='<network-api-version>',
                        default=utils.env('OS_NETWORK_API_VERSION'),
                        help=_("Network API version, default=%s "
                               "(Env: OS_NETWORK_API_VERSION)") %
                        DEFAULT_API_VERSION)
    return parser
コード例 #7
0
def build_option_parser(parser):
    """Hook to add global options"""
    parser.add_argument('--os-compute-api-version',
                        metavar='<compute-api-version>',
                        default=utils.env('OS_COMPUTE_API_VERSION'),
                        help=_("Compute API version, default=%s "
                               "(Env: OS_COMPUTE_API_VERSION)") %
                        DEFAULT_API_VERSION)
    return parser
コード例 #8
0
def build_option_parser(parser):
    """Hook to add global options"""
    parser.add_argument(
        '--os-identity-api-version',
        metavar='<identity-api-version>',
        default=utils.env('OS_IDENTITY_API_VERSION'),
        help=_('Identity API version, default=%s '
               '(Env: OS_IDENTITY_API_VERSION)') % DEFAULT_API_VERSION,
    )
    return parser
コード例 #9
0
class CheckRouterBrainSplit(commandmanager.ShowOne):
    _description = _("Check whether the specified router brain split.")

    def get_parser(self, prog_name):
        parser = super(CheckRouterBrainSplit, self).get_parser(prog_name)
        parser.add_argument(
            'router_id',
            metavar='<router-id>',
            help=_('the router uuid.'),
        )
        return parser

    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        network_client = self.app.client_manager.network
        ssh_client = self.app.client_manager.ssh
        result = {}
        return commandmanager.set_result(result)
コード例 #10
0
class CheckVmFloatingIP(commandmanager.ShowOne):
    _description = _("Check whether the specified instance floating "
                     "ip is ok.")

    def get_parser(self, prog_name):
        parser = super(CheckVmFloatingIP, self).get_parser(prog_name)
        parser.add_argument(
            'floatingip-id',
            metavar='<floatingip-id>',
            help=_('the floatingip uuid.'),
        )
        return parser

    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        network_client = self.app.client_manager.network
        ssh_client = self.app.client_manager.ssh
        result = {}
        return commandmanager.set_result(result)
コード例 #11
0
class CheckSgRule(commandmanager.ShowOne):
    _description = _("Compare the security group rule in DataBase with "
                     "iptables rules in related compute node.")

    def get_parser(self, prog_name):
        parser = super(CheckSgRule, self).get_parser(prog_name)
        parser.add_argument(
            'port-id',
            metavar='<port-id>',
            help=_('the port uuid.'),
        )
        return parser

    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        network_client = self.app.client_manager.network
        ssh_client = self.app.client_manager.ssh
        result = {}
        return commandmanager.set_result(result)
コード例 #12
0
def check_api_version(check_version):
    """Validate version supplied by user

    Returns:
    * True if version is OK
    * False if the version has not been checked and the previous plugin
      check should be performed
    * throws an exception if the version is no good

    TODO(dtroyer): make the exception thrown a version-related one
    """

    # Defer client imports until we actually need them
    import novaclient
    from novaclient import api_versions

    global _compute_api_version

    # Copy some logic from novaclient 3.3.0 for basic version detection
    # NOTE(dtroyer): This is only enough to resume operations using API
    #                version 2.0 or any valid version supplied by the user.
    _compute_api_version = api_versions.get_api_version(check_version)

    # Bypass X.latest format microversion
    if not _compute_api_version.is_latest():
        if _compute_api_version > api_versions.APIVersion("2.0"):
            if not _compute_api_version.matches(
                    novaclient.API_MIN_VERSION,
                    novaclient.API_MAX_VERSION,
            ):
                msg = _("versions supported by client: %(min)s - %(max)s") % {
                    "min": novaclient.API_MIN_VERSION.get_string(),
                    "max": novaclient.API_MAX_VERSION.get_string(),
                }
                raise exceptions.CommandError(msg)
    return True
コード例 #13
0
ファイル: dhcp.py プロジェクト: zhuzhichaoTM/neutron-diagnose
class CheckVmIp(commandmanager.ShowOne):
    _description = _("Check the the reason that specified "
                     "instance can't get ip address.")

    def get_parser(self, prog_name):
        parser = super(CheckVmIp, self).get_parser(prog_name)
        parser.add_argument(
            'instance_id',
            metavar='<instance-id>',
            help=_('the instance uuid.'),
        )
        parser.add_argument(
            'fixed_ip',
            metavar='<fixed-ip>',
            help=_('the fixed ip of instance.'),
        )
        return parser

    def take_action(self, parsed_args):
        utils.validate_uuid(parsed_args.instance_id)
        utils.validate_ip_address(parsed_args.fixed_ip)

        compute_client = self.app.client_manager.compute
        network_client = self.app.client_manager.network
        ssh_client = self.app.client_manager.ssh

        server = compute_client.servers.get(parsed_args.instance_id)
        project_id = server.tenant_id
        host = server._info.get('OS-EXT-SRV-ATTR:host')
        if not host:
            raise exceptions.DiagnoseException('the instance: %s has no host.',
                                               server.id)
        network_name = None
        port_mac = None
        port_id = None
        for network, details in server._info.get('addresses', dict()).items():
            for ip_infs in details:
                if ip_infs.get('addr') == parsed_args.fixed_ip:
                    network_name = network_name
                    port_mac = ip_infs.get('OS-EXT-IPS-MAC:mac_addr')
        port_filters = {
            'device_owner': 'compute:nova',
            'device_id': server.id,
            'mac_address': port_mac,
            'project_id': project_id
        }
        ports = network_client.ports(**port_filters)
        port_len = 0
        for port in ports:
            port_len += 1
            fixed_ips = port.fixed_ips
            for ip_info in fixed_ips:
                if ip_info['ip_address'] == parsed_args.fixed_ip:
                    port_id = port.id
                    break

        if port_len > 1:
            raise exceptions.DiagnoseException(
                'The tenant: %s has more one instances use same IP and MAC,'
                'it does not support in current version.' % project_id)
        if not port_id:
            raise exceptions.DiagnoseException(
                "Can't retrieve related Neutron port id.")
        result = {
            'host': host,
            'port id': port_id,
        }
        return commandmanager.set_result(result)