def testFromArgsWithIapTunnelingEnabled(self, internal_ip_flag_available, iap_tunneling_flag_available): if internal_ip_flag_available: ssh_surface.AddInternalIPArg(self.parser) if iap_tunneling_flag_available: iap_tunnel.AddSshTunnelArgs(self.parser, self.parser) expected_tunnel_args = self._GenExpectedTunnelArgs() if iap_tunneling_flag_available: # Implicit enabled cases self.assertEqual(self._FromArgs([], include_external_nic=False), expected_tunnel_args) # Explicit enabled cases self.assertEqual(self._FromArgs(['--tunnel-through-iap']), expected_tunnel_args) self.assertEqual( self._FromArgs(['--tunnel-through-iap'], include_external_nic=False), expected_tunnel_args) if internal_ip_flag_available and iap_tunneling_flag_available: # Implicit enabled cases self.assertEqual( self._FromArgs(['--no-internal-ip'], include_external_nic=False), expected_tunnel_args) # Explicit enabled cases self.assertEqual( self._FromArgs(['--no-internal-ip', '--tunnel-through-iap']), expected_tunnel_args) self.assertEqual( self._FromArgs(['--no-internal-ip', '--tunnel-through-iap'], include_external_nic=False), expected_tunnel_args)
def Args(parser): """Set up arguments for this command. Args: parser: An argparse.ArgumentParser. """ super(ScpBeta, ScpBeta).Args(parser) mutex_scope = parser.add_mutually_exclusive_group() mutex_scope.add_argument('--internal-ip', default=False, action='store_true', help="""\ Connect to instances using their internal IP addresses rather than their external IP addresses. Use this to connect from one instance to another on the same VPC network, over a VPN connection, or between two peered VPC networks. For this connection to work, you must configure your networks and firewall to allow SSH connections to the internal IP address of the instance to which you want to connect. To learn how to use this flag, see [](https://cloud.google.com/compute/docs/instances/connecting-advanced#sshbetweeninstances). """) iap_tunnel.AddSshTunnelArgs(parser, mutex_scope)
def Args(parser): ssh_utils.BaseSSHCLIHelper.Args(parser) AddCommandArg(parser) AddSSHArgs(parser) AddContainerArg(parser) flags.AddZoneFlag(parser, resource_type='instance', operation_type='connect to') mutex_scope = parser.add_mutually_exclusive_group() AddInternalIPArg(mutex_scope) iap_tunnel.AddSshTunnelArgs(parser, mutex_scope)
def testFromArgsWithIapTunnelingDisabled(self, internal_ip_flag_available, iap_tunneling_flag_available): if internal_ip_flag_available: ssh_surface.AddInternalIPArg(self.parser) if iap_tunneling_flag_available: iap_tunnel.AddSshTunnelArgs(self.parser, self.parser) # Implicit disabled cases self.assertIsNone(self._FromArgs([])) if not iap_tunneling_flag_available: self.assertIsNone(self._FromArgs([], include_external_nic=False)) if iap_tunneling_flag_available: # Explicit disabled cases self.assertIsNone(self._FromArgs(['--no-tunnel-through-iap'])) self.assertIsNone( self._FromArgs(['--no-tunnel-through-iap'], include_external_nic=False)) if internal_ip_flag_available: # Implicit disabled cases self.assertIsNone(self._FromArgs(['--internal-ip'])) self.assertIsNone( self._FromArgs(['--internal-ip'], include_external_nic=False)) self.assertIsNone(self._FromArgs(['--no-internal-ip'])) if internal_ip_flag_available and iap_tunneling_flag_available: # Not allowed to use both --internal-ip and --tunnel-through-iap flags, # but --internal-ip trumps --tunnel-through-iap and IAP tunneling is # disabled. self.assertIsNone( self._FromArgs(['--internal-ip', '--tunnel-through-iap'])) self.assertIsNone( self._FromArgs(['--internal-ip', '--tunnel-through-iap'], include_external_nic=False)) # For completeness, other combinations with IAP tunneling explicitly # disabled. self.assertIsNone( self._FromArgs(['--internal-ip', '--no-tunnel-through-iap'])) self.assertIsNone( self._FromArgs(['--internal-ip', '--no-tunnel-through-iap'], include_external_nic=False)) self.assertIsNone( self._FromArgs(['--no-internal-ip', '--no-tunnel-through-iap'])) self.assertIsNone( self._FromArgs(['--no-internal-ip', '--no-tunnel-through-iap'], include_external_nic=False))
def Args(parser): """Set up arguments for this command. Args: parser: An argparse.ArgumentParser. """ ssh_utils.BaseSSHCLIHelper.Args(parser) AddCommandArg(parser) AddSSHArgs(parser) AddContainerArg(parser) flags.AddZoneFlag( parser, resource_type='instance', operation_type='connect to') routing_group = parser.add_mutually_exclusive_group() AddInternalIPArg(routing_group) iap_tunnel.AddSshTunnelArgs(parser, routing_group)
def Args(cls, parser): """Set up arguments for this command. Args: parser: An argparse.ArgumentParser. """ scp_utils.BaseScpHelper.Args(parser) parser.add_argument('--port', help='The port to connect to.') parser.add_argument('--recurse', action='store_true', help='Upload directories recursively.') parser.add_argument('--compress', action='store_true', help='Enable compression.') parser.add_argument( '--scp-flag', action='append', help='Extra flag to be sent to scp. This flag may be repeated.') ssh_utils.AddVerifyInternalIpArg(parser) routing_group = parser.add_mutually_exclusive_group() routing_group.add_argument('--internal-ip', default=False, action='store_true', help="""\ Connect to instances using their internal IP addresses rather than their external IP addresses. Use this to connect from one instance to another on the same VPC network, over a VPN connection, or between two peered VPC networks. For this connection to work, you must configure your networks and firewall to allow SSH connections to the internal IP address of the instance to which you want to connect. To learn how to use this flag, see [](https://cloud.google.com/compute/docs/instances/connecting-advanced#sshbetweeninstances). """) iap_tunnel.AddSshTunnelArgs(parser, routing_group) # TODO(b/190426150): Move this to Beta and then GA. if cls.enable_host_based_flags: iap_tunnel.AddHostBasedTunnelArgs(parser)
def testFromArgsWithPassThroughArgs(self): ssh_surface.AddInternalIPArg(self.parser) iap_tunnel.AddSshTunnelArgs(self.parser, self.parser) expected_tunnel_args = self._GenExpectedTunnelArgs() expected_tunnel_args.pass_through_args = [ '--iap-tunnel-url-override=https://none' ] self.assertEqual( self._FromArgs([ '--tunnel-through-iap', '--iap-tunnel-url-override=https://none' ]), expected_tunnel_args) expected_tunnel_args.pass_through_args = [ '--iap-tunnel-insecure-disable-websocket-cert-check' ] self.assertEqual( self._FromArgs([ '--tunnel-through-iap', '--iap-tunnel-insecure-disable-websocket-cert-check' ]), expected_tunnel_args) expected_tunnel_args.pass_through_args = [ '--iap-tunnel-url-override=https://none', '--iap-tunnel-insecure-disable-websocket-cert-check' ] self.assertEqual( self._FromArgs([ '--tunnel-through-iap', '--iap-tunnel-url-override=https://none', '--iap-tunnel-insecure-disable-websocket-cert-check' ]), expected_tunnel_args) expected_tunnel_args.pass_through_args = [] self.assertEqual( self._FromArgs([ '--tunnel-through-iap', '--no-iap-tunnel-insecure-disable-websocket-cert-check' ]), expected_tunnel_args)
def Args(cls, parser): """Set up arguments for this command. Args: parser: An argparse.ArgumentParser. """ ssh_utils.BaseSSHCLIHelper.Args(parser) AddCommandArg(parser) AddSSHArgs(parser) AddContainerArg(parser) AddTroubleshootArg(parser) # TODO(b/190426150): Move this to Beta and then GA. if cls.enable_host_based_flags: iap_tunnel.AddHostBasedTunnelArgs(parser) flags.AddZoneFlag( parser, resource_type='instance', operation_type='connect to') ssh_utils.AddVerifyInternalIpArg(parser) routing_group = parser.add_mutually_exclusive_group() AddInternalIPArg(routing_group) iap_tunnel.AddSshTunnelArgs(parser, routing_group)