2020on the same internal VPC network.
2121"""
2222
23- # [START imports_and_variables]
2423import argparse
2524import logging
2625import subprocess
3837)
3938HEADERS = {"Metadata-Flavor" : "Google" }
4039
41- # [END imports_and_variables]
4240
43-
44- # [START run_command_local]
4541def execute (
4642 cmd : List [str ],
4743 cwd : Optional [str ] = None ,
4844 capture_output : bool = False ,
4945 env : Optional [dict ] = None ,
5046 raise_errors : bool = True ,
5147) -> (int , str ):
52- """
53- Execute an external command (wrapper for Python subprocess).
48+ """Execute an external command (wrapper for Python subprocess).
5449
5550 Args:
5651 cmd: command to be executed, presented as list of strings.
@@ -78,18 +73,13 @@ def execute(
7873 return returncode , output
7974
8075
81- # [END run_command_local]
82-
83-
84- # [START create_key]
8576def create_ssh_key (
8677 oslogin : googleapiclient .discovery .Resource ,
8778 account : str ,
8879 private_key_file : Optional [str ] = None ,
8980 expire_time : int = 300 ,
9081) -> str :
91- """
92- Generate an SSH key pair and apply it to the specified account.
82+ """Generate an SSH key pair and apply it to the specified account.
9383
9484 Args:
9585 oslogin: the OSLogin resource object, needed to communicate with API.
@@ -129,13 +119,8 @@ def create_ssh_key(
129119 return private_key_file
130120
131121
132- # [END create_key]
133-
134-
135- # [START run_command_remote]
136122def run_ssh (cmd : str , private_key_file : str , username : str , hostname : str ) -> List [str ]:
137- """
138- Run a command on a remote system.
123+ """Run a command on a remote system.
139124
140125 Args:
141126 cmd: the command to be run on remote system.
@@ -166,10 +151,6 @@ def run_ssh(cmd: str, private_key_file: str, username: str, hostname: str) -> Li
166151 return result if result else ssh .stderr .readlines ()
167152
168153
169- # [END run_command_remote]
170-
171-
172- # [START main]
173154def main (
174155 cmd : str ,
175156 project : str ,
@@ -179,8 +160,7 @@ def main(
179160 account : Optional [str ] = None ,
180161 hostname : Optional [str ] = None ,
181162) -> List [str ]:
182- """
183- Run a command on a remote system.
163+ """Run a command on a remote system.
184164
185165 This method will first create a new SSH key and then use it to
186166 execute a specified command over SSH on remote machine.
@@ -273,5 +253,3 @@ def main(
273253 account = args .account ,
274254 hostname = args .hostname ,
275255 )
276-
277- # [END main]
0 commit comments