Qc#@sdZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddk l Z ddk l Z ddk l Z ddkZddkZddkiZddklZddklZddkZddklZdd klZdd klZdd klZdd klZdd klZddklZddkl Z ddkl!Z!ei"Z"ei#Z#dZ$e i%Z&e i'Z(dZ)dddgZ*ei+de&e(dei,dddei,de-dei,de-dei.de/d ei+d!d"d"d#d$d%d&fd'ei+d(d)d)d*gd+ei.d,e/d-ei.d.e0d/ei1d0d1d2d3d4ei1d5d6d7d8d9ei,d:e-d;ei1d<d=d>d3d?d@e2fdAYZ3dBe3fdCYZ4dDe5fdEYZ6dFe5fdGYZ7dHei8fdIYZ9dJei:fdKYZ;dLe;fdMYZ<dS(Ns>Base command types for interacting with Google Compute Engine.iN(t discovery(terrors(tmodel(tapp(t appcommands(t auth_helper(t flags_cache(tgcutil_logging(t metadata_lib(tscopes(t thread_pool(tutils(tversion(ttable_formatters,google-api-client-python-compute-cmdline/1.0tglobaltstandardthighcputhighmemtservice_versions#Google computation service version.tapi_hostshttps://www.googleapis.com/s API host nametprojects.The name of the Google Compute Engine project.t project_idsQThe name of the Google Compute Engine project. Deprecated, use --project instead.t print_jsonsEOutput JSON instead of tabular format. Deprecated, use --format=json.tformatttabletsparsetjsontcsvtnamessFormat for command output. Options include: table: formatted table output sparse: simpler table output json: raw json output (formerly --print_json) csv: csv format with header names: list of resource names only, no headertlong_values_display_formattelidedtfulls-The display preference for long table values.tfetch_discoverys9If true, grab the API description from the discovery API.tsynchronous_modes5If false, return immediately after posting a request.tsleep_between_pollsis9The time to sleep between polls to the server in seconds.iiXt max_wait_timeisNThe maximum time to wait for an asynchronous operation to complete in seconds.iit trace_tokens>Trace the API requests using a trace token provided by Google.tconcurrent_operationsi sThe maximum number of concurrent operations to have in progress at once. Increasing this number will probably result in hitting rate limits.itErrorcBseZdZRS(s>The base class for this tool's error reporting infrastructure.(t__name__t __module__t__doc__(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR&st CommandErrorcBseZdZRS(s+Raised when a command hits a general error.(R'R(R)(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR*st TracedApicBseZdZdZRS(s,Wrap an Api to add a trace keyword argument.csifd}xSti|tiD]<}|didp"t||d||dq%q%WdS(Ncsfd}|S(Ncs"o|dR;t_requestt_commandt_wait_for_operationt_collection_name(R8trequesttcommandtwait_for_operationtcollection_name((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR;s    cCsf|ii}|iid|}|io4|ii|iit|d|d|i}n|S(s)Execute the request on a separate thread.thttpRG( RAt CreateHttpR@texecuteRBtWaitForOperationtGetFlagsttimeRC(R8RHtresult((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytRuns  N(R'R(R)tNoneR;RO(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR>s tGoogleComputeCommandcBseZdZdZdZd_d`dadbdcdddedfdgf ZdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdyfZeZd#Z d$Z dzedzdzd%Z edzdzd&Z d'Zd(Zd)Zd*Zd+Zd,Zedzd-Zdzd.Zd/Zd0Zd1Zd2Zed3Zed4Zed5Zd6Zd7Zd8Z d9Z!d:Z"d;Z#d<Z$ed=Z%d>Z&d?Z'd@Z(dAZ)dBZ*dCZ+dDZ,dEZ-dFZ.dGZ/dHZ0dzdIZ1dzdzdJZ2dzdKZ3dLZ4dMZ5dNZ6dOZ7dPZ8dQZ9dRZ:dSZ;dTZ<dUZ=dVZ>dWZ?dXZ@dYZAdZZBd[ZCd\ZDd]ZEd^ZFRS({s~Base class for commands that interact with the Google Compute Engine API. Overriding classes must override the SetApi and Handle methods. Attributes: GOOGLE_PROJECT_PATH: The common 'google' project used for storage of shared images and kernels. operation_detail_fields: A set of tuples of (json field name, human readable name) used to generate a pretty-printed detailed description of an operation resource. supported_versions: The list of API versions supported by this tool. safety_prompt: A boolean indicating whether the command requires user confirmation prior to executing. sprojects/googles insert-timetnametzonetstatussstatus-messaget statusMessagettargett targetLinkt insertTimesoperation-typet operationTypeterrorserror.errors.codetwarnings warnings.codes creation-timetcreationTimestamptprogresss target-idttargetIdsclient-operation-idtclientOperationIdtusers start-timet startTimesend-timetendTimes error-codethttpErrorStatusCodes error-messagethttpErrorMessageswarning-messageswarnings.messagecCsitt|i||d|_t|_t|do*ti dt d|i d|ddndS(sInitializes a new instance of a GoogleComputeCommand. Args: name: The name of the command. flag_values: The values of command line flags to be used by the command. t safety_prompttforcesOverride the "%s" promptt flag_valuest short_nametfN( R?RQR;RPt _credentialtSUPPORTED_VERSIONStsupported_versionsthasattrtflagst DEFINE_booltFalseRe(R8RRRg((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR;s    cCsfx_toWtdi}y"t|}||jo|SWntj onXd|GHqWdS(Ns>>> s3Invalid selection, please choose one of the listed (tTruet raw_inputtstriptintt ValueError(R8tmenut menu_namet userinputt selection((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_ReadInSelectedItems   cCs<ti|i|p|id}|i|||||S(sePrompt the user to select an entry from an API collection. Args: collection_api: The API collection wrapper. collection_name: The name of the collection used in building the prompts. project: A project whose collection to use. Defaults to self._project. auto_select: If True and the collection has a single element then that element is chosen without prompting the user. extract_resource_prompt: A function that takes a resource JSON and returns the resource prompt. If not provided, the resource's 'name' field is going to be used as the default prompt text. additional_key_func: Lambda resource_name -> int. If supplied, this function will be used as the first sort key of the name. Returns: A collection entry as selected by the user or None if the collection is empty; titems(R tAlltlistt_projectt_PromptForChoice(R8tcollection_apiRGRt auto_selecttextract_resource_prompttadditional_key_functchoices((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForEntry!s# c s|djod}|}n|pdS|o`t|djoMd||ddfGHd|djotid|ddn|dSg}|D]C}d|jo0|ddd jo|||d |fqq~} | id d g} |D]*}d|jo| |||fqq~ }ofd } n d} |id | |i| x3t|D]%\} \} }d| d| fGHqW|itdt|d|d}||ddS(sPrompts user to select one of the resources from the choices list. The function will create list of prompts from the list of choices. If caller passed extract_resource_prompt function, the extract_resource_prompt will be called on each resource to generate appropriate prompt text. Prompt strings are sorted alphabetically and offered to the user to select the desired option. The selected resource is then returned to the caller. If the list of choices is empty, None is returned. If there is only one available choice and auto_select is True, user is not prompted but rather, the only available option is returned. Args: choices: List of Google Compute Engine resources from which user should choose. collection_name: Name of the collection to present to the user. auto_select: Boolean. If set to True and only one resource is available in the list of choices, user will not be prompted but rather, the only available option will be chosen. extract_resource_prompt: Lambda resource -> string. If supplied, this function will be called on each resource to generate the prompt string for the resource. additional_key_func: Lambda resource_name -> int. If supplied, this function will be used as the first sort key of the name. Returns: The resource user selected. Returns the actual resource as the JSON object model represented as Python dictionary. cSs|diddS(NRRt/i(tsplit(tresource((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytExtractResourcePrompt]sis#Selecting the only available %s: %siRRt deprecatedsWarning: %s is deprecated!tstatet DEPRECATEDs (DEPRECATED)tkeycSs|dS(i((tpair((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytoscs|d|dfS(i((R(R(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRtscSs|dS(i((R((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRvss%d: %stsN( RPtlentLOGGERtwarntsorttextendt enumerateRztrange(R8RRGRRRRt_[1]tchtdeprecated_choicest_[2]tkey_functiRht unused_choiceRy((Rsa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR;s8    9-   #cs+fd}iiddd|S(sPrompt the user to select a kernel from the available kernels. Returns: A kernel resource selected by the user, or None if no kernels available. cs iidd|dS(NtgoogletkernelsRR(t_PresentElementtNormalizeGlobalResourceName(tkernel(R8(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytExtractKernelPromptsRRR(Rt _kernels_api(R8R((R8sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForKernelscs^tiiiddtiiiid}fd}i|dt|S(NRR{csi|dS(NtselfLink(R(timage(R8(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytExtractImagePromptsR(R R|t _images_apiR}R~RRq(R8RR((R8sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForImages cs7tiifd}|i|idd|S(syPrompt the user to select a zone from the current list. Returns: A zone resource as selected by the user. cs|didd}ti|}|d j o|jo d}no|}|tiddjo d }nB|idjo d}n(|idjo d }nd |i}|od ||fSn|S( s7Creates a text prompt for a zone resource. Includes maintenance information for zones that enter maintenance in less than two weeks. Args: zone: The Google Compute Engine zone resource. Returns: string to represent a specific zone choice to present to the user. RRRiscurrently in maintenancetweeksiis(maintenance starts in less than 24 hourssmaintenance starts in 1 daysmaintenance starts in %s dayss%s (%s)N(RRQt_GetNextMaintenanceStartRPtdatetimet timedeltatdays(RSRRt maintenancetmsgtdelta(tnow(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytExtractZonePrompts         RSR(RtutcnowRt _zones_api(R8R((Rsa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForZonescCs|i|iddtS(syPrompt the user to select a disk from the current list. Returns: A disk resource as selected by the user. tdiskR(Rt _disks_apiRp(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForDiskscCs=x0tttD]}t||jo|SqWttS(s Returns a score for the given machine type to be used in sorting. This is used to ensure that the lower cost machine types are the first ones displayed to the user. Args: value: The name of a machine type. Returns: An integer that defines a sort order. (RRtMACHINE_TYPE_ORDERING(R8tvalueR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt!_GetMachineTypeSecondarySortScores  cCs|i|idd|iS(sPrompt the user to select a machine type from the current list. Returns: A machine type resource as selected by the user. s machine typeR(Rt_machine_types_apiR(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PromptForMachineTypes cCsd}|djotii}n|id}d}|ox|D]}|id}|o$||}||joqLqn|id}|o4||}|djp ||jo |}qqLqLWn|S(NcSsti|iddS(Nttzinfo(tiso8601t parse_datetreplaceRP(tdate((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt ParseDatestmaintenanceWindowsRbt beginTime(RPRRtget(RSRRRt next_windowtmwtendtbegin((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs&      cCsL|djo|i}|d}n"|idd}|iid|id|i}tii}t i ||}|dj o||jo d}n||}|ti ddjo d}nB|i d jo d }n(|i d jo d }nd |i }|od |}n|ot id||qHn|S(sNotifies the user if the given zone will enter maintenance soon. The given zone can be None in which case the user is prompted for a zone. This method is intended to provide a warning to the user if he or she seeks to create a disk or instance in a zone that will enter maintenance in less than two weeks. Args: zone: The name of the zone chosen, or None. Returns: The given zone or the zone chosen through the prompt. RRRiRRSs!is unavailable due to maintenanceRiisless than 24 hourss1 days%s dayss0will become unavailable due to maintenance in %ss%s %s.N(RPRRRRR~RJRRRQRRRRR(R8RSt zone_resourceRtnext_winRR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_GetZones2            cCsti|ii|iS(s}Retrieves the full list of zones available to this project. Returns: List of zones available to this project. (R tAllNamesRR}R~(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt _GetZones5scCsP|ip6ti|i|_|iptdq@n|ii|S(sAdds the OAuth token into http request. Args: http: An instance of httplib2.Http or something that acts like it. Returns: httplib2.Http like object. Raises: CommandError: If the credentials can't be found. s(Could not get valid credentials for API.(RjRtGetCredentialFromStoret,_GoogleComputeCommand__GetRequiredAuthScopesR*t authorize(R8RH((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_AuthenticateWrapper=s  cCs|iorz]y)|i}|it||}Wn-titifj o}t|nXWd|i|Xnti |i }|i ot |i nd}|i d}|dt |d!}|t |d} t ||t |joR|t |} g} | D]} | d| q~ } tddi| nxGt||D]6\} }|idotd|| fqeqeW| oat|d t oM|i oBg}| D]} |d| q~} td di| n|dS( sdParses the command line arguments for the command. This method matches up positional arguments based on the signature of the Handle method. It also parses the flags found on the command line. argv will contain,
, positional-arguments, flags... Args: flag_values: The flags list to update argv: The command line argument list Returns: The list of position arguments for the given command. Raises: CommandError: If any problems occur with parsing the commands (e.g., type mistmatches, out of bounds, unknown commands, ...). Niis"%s"s"Positional argument %s is missing.s, s--s9Invalid positional argument value '%s' for argument '%s' t has_varargssUnknown argument: %s(tsort_args_and_flagst IsGnuGetOptt UseGnuGetOptRqRntIllegalFlagValuetUnrecognizedFlagErrorR*R3t getargspectHandletdefaultsRR-tjointzipR6tgetattrRptvarargs(R8Rgtargvt old_gnu_modetetargspect default_countt pos_arg_namestpos_arg_valuest unparsed_argst missing_argsRtaRRRR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_ParseArgumentsAndFlagsRs>     %  %c Csdttjo tin ti}tio<tid}|iti dti d|d|d|St i i t i itdti }y)t|d}|i}|iWn#tj otd |nX|iti|d tid|d|Sd S( sBuilds the Google Compute Engine API to use. Args: http: a httplib2.Http like object for communication. Returns: The API object to use. tLoggingJsonModels)discovery/v1/apis/{api}/{apiVersion}/resttcomputeRHtdiscoveryServiceUrlRscompute/%s.jsontrsUCould not load discovery document from disk. Perhaps try --fetch_discovery. File: %stbaseN(tdirRRt JsonModeltFLAGSR RtWrapApiIfNeededRtbuildRtostpathRtdirnamet__file__tfiletreadtclosetIOErrorR*tbuild_from_document(R8RHt json_modelt discovery_uritdiscovery_file_nametdiscovery_filet discovery_doc((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_BuildComputeApis6          cCs#tiot|dtiS|S(s+Wraps the API to enable logging or tracing.stoken:%s(RR$R<(tapi((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs cCs|ididdS(sReturn the relative name for the given resource. Args: resource_name: The name of the resource. This can be either relative or absolute. Returns: The name of the resource relative to its enclosing collection. Ri(Rst rpartition(t resource_name((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytDenormalizeResourceNames cCs|ip|i}|ptdn(|i|jotd|n|id}|ido|td}nd|jotdn||_d|_dS(sDenormalize the 'project' entry in the given FlagValues instance. Args: flag_values: The FlagValues instance to update. Raises: CommandError: If the project is missing or malformed. s;You must specify a project name using the "--project" flag.s1Characters in project name must be lowercase: %s.Rs projects/sFProject names can contain a '/' only when they begin with 'projects/'.N(RRR*tlowerRsR6RRP(RgR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytDenormalizeProjectNames    cCsd|ii|iifS(sGet the base API URL given the current flag_values. Returns: The base API URL. For example, https://www.googleapis.com/compute/v1beta14. s %scompute/%s(t_flagsRR(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_GetBaseApiUrlscCs,|i|jod|i|fS|S(sAdd the base URL to a resource_path if required by the service_version. Args: resource_path: The resource path to add the URL to. Returns: A full API-usable reference to the given resource_path. s%s/%s(R(R8t resource_path((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_AddBaseUrlIfNecessarys cCs0dti|iid}ti|d|S(s/Removes the a base URL from the string if it exists. Note that right now the server may not return exactly the right base URL so we strip off stuff that looks like a base URL. Args: value: The string to strip the base URL from. Returns: A string without the base URL. t^s compute/\w*/t(tretescapeRRtsub(R8Rtpattern((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt _StripBaseUrls cCs|id}|djo*d|ijo|ido d}n|idp*|i|dp|i|iio|i|Sd|||f}|ido!|od||||f}n|i|S( sReturn the full name for the given resource. Args: project: The name of the project containing the resource. scope_name: The scope of the collection containing the resource. collection_name: The name of the collection containing the resource. resource_name: The name of the resource. This can be either relative or absolute. Returns: The full URL of the resource. Rs machine-typestv1beta13t machineTypess projects/sprojects/%s/%s/%stv1beta14sprojects/%s/%s/%s/%s(RsRlt_IsUsingAtLeastApiVersionR6RRR(R8Rt scope_nameRGR t absolute_name((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytNormalizeResourceName$s$   cCs|i|d||S(sQReturn the full name for the given resource. Args: project: The name of the project containing the resource. collection: The name of the collection containing the resource. resource: The name of the resource. This can be either relative or absolute. Returns: The full URL of the resource. N(RRP(R8Rt collectionR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytNormalizeTopLevelResourceNameJs cCs|i|d||S(sQReturn the full name for the given resource. Args: project: The name of the project containing the resource. collection: The name of the collection containing the resource. resource: The name of the resource. This can be either relative or absolute. Returns: The full URL of the resource. R(R(R8RR R((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR[s cCs|i|d|||S(sReturn the full name for the given resource. Args: project: The name of the project containing the resource. zone: The name of the zone containing the resource. collection: The name of the collection containing the resource. resource: The name of the resource. This can be either relative or absolute. Returns: The full URL of the resource. szones/%s(R(R8RRSR R((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytNormalizePerZoneResourceNamels c Cs|pdS|i|id}t|djo+|ddjo|ddjo |dS|iitjodS|iio |iiSti|i |g}g}xW|i D]I}ti |i |i ddd|d |}|i|id gqWt|d joY|i|dd }tid t|t|pttid|pt|S|otd|ndSdS(sGets the unqualified zone name for a given resource. The function first tries to use 'zone' parameter if set, but falls back to searching for the resource name across zones. Args: api: The API service that must expose 'list' method. resource_name: Name of the resource to find. fail_if_not_found: Raise an error when the resource is not found. Returns: Unqualified name of the zone the resource belongs to. Raises: CommandError: If the zone for the resource cannot be resolved. Riitprojectsitzonest max_resultstfilterRSR{iRsZone for %s detected as %s.saConsider passing '--zone=%s' to avoid the unnecessary zone lookup which requires extra API calls.s%Could not determine the zone of '%s'.N(RPRRRRRStGLOBAL_ZONE_NAMER tRegexesToFilterExpressionR RR|R}R~RRt_GetZoneFromSelfLinkRtinfotreprR[R*( R8RR tfail_if_not_foundtresource_name_partstfilter_expressionR{RSt sub_result((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytGetZoneForResource~sB        cCsd|i|}|id}t|djo+|ddjo|ddjo |dSdSdS(s=Parses the given self-link and returns per-project zone name.RiiR#iR$N(RRRRP(R8t self_linkR tparts((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR)s 5 cCst|do|iip|i}|od|di|f}nd|GHtd}|p d}n|id i}|djptSqnt S( sIf a safety prompt is present on the class, handle it now. By defining a field 'safety_prompt', derived classes can request that the user confirm a dangerous operation prior to execution, e.g. deleting a resource. Users may override this check by passing the --force flag on the command line. Args: positional_arguments: A list of positional argument strings. Returns: True if the command should continue, False if not. Res%s %ss, s %s? [y/N]s>>> tnity( RmRRfReRRrtlstripR RpRq(R8tpositional_argumentstpromptRx((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_HandleSafetyPrompts       cCs||ijo|ii|ijp td||iifnxQt|iD]@\}}||iijo |}n||jo |}qVqVW||jS(sGDetermine if in-use API version is at least the specified version. Args: required_version: The API version to test. Returns: True if the given API version is equal or newer than the in-use API version, False otherwise. Raises: CommandError: If the specified API version is not known. sAPI version %s/%s unknown(RlRRR*R(R8trequired_versiontindext known_versiont current_indext given_index((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs    cCsd|S(sDetermine the API version driven resource 'kind'. Args: resource: The resource type to generate a 'kind' string for. Returns: A string containing the API 'kind' s compute#%s((R8R((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_GetResourceApiKinds cCsg}|i|o |g}n'|i|o|idg}nx?|D]7}|iio$|idhidgotSqPWtS(s6Return True if a result should be considered an error.R{RZR(tIsResultAnOperationt IsResultAListRRR!RqRp(R8RNtopstop((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_ErrorInResult s   c Csy|it|}titi}|i|i|it|i tt }t }x|oy|i |i |\}}t }|i||i||i|o t }nxD|D]<}t|tio#|p |q tidPqqWWqhtij o3} |pntidt| t }qhXqhWt|p|} | p|in| SWntij o} |i| dStij o nKti i!ddi"t#i$ti%ti&ti't#i(dSXdS(sRun the command, printing the result. Args: argv: The arguments to the command. Returns: 0 if the command completes successfully, otherwise 1. sfRefresh error when running multiple operations. Not automatically retrying as some requests succeeded.s+OAuth2 token refresh error (%s), retrying. is%s s N()RRRt SetupLoggingRt FlagsCachetSynchronizeFlagstSetFlagDefaultsR tSetFlagsRqRptRunWithFlagsAndPositionalArgsRt PrintResultt LogExceptionsRCt isinstancet oauth2_clienttAccessTokenRefreshErrorRR[R*tstrtbooltUpdateCacheFileRt HttpErrort LogHttpErrorRt UsageErrortsyststderrtwriteRt tracebacktformat_exception_onlytexc_typet exc_valuetdebugt format_exc( R8RRtflags_cache_objt auth_retryterror_in_resultRNt exceptionst exceptionRt has_errorst http_error((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyROs\              cCsti}|i|}|S(sConstruct an HTTP object to use with an API call. This is useful when doing multithreaded work as httplib2 Http objects aren't threadsafe. Returns: An object that implements the httplib2.Http interface (thttplib2tHttpR(R8RH((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRIds cCs|i}|i|}|ido"|i|_|i|_n|i|_|i||i |pt dng}|i |}t |t o|\}}n|iio|i|t|}nt |to|i|d}n||fS(sQRun the command with the parsed flags and positional arguments. This method is what a subclass should override if they do not want to use the REST API. Args: flag_values: The parsed FlagValues instance. pos_arg_values: The positional arguments for the Handle method. Raises: CommandError: If user choses to not proceed with the command at safety prompt. Returns: A tuple (result, exceptions) where results is a JSON-serializable result and exceptions is a list of exceptions that were thrown when running this command. RsOperation abortedt operationList(RIRRtzoneOperationst_zone_operations_apitglobalOperationst_global_operations_apit operationstSetApiR8R*RRLttupleRR!RKRMR}tMakeListResult(R8RgRRHt compute_apiRaRN((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRIqs$   cCs=y"d|jo|didSWntj otSXdS(s/Determine if the result object is an operation.tkinds #operationN(tendswitht TypeErrorRp(R8RN((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR?s  cCs=y"d|jo|didSWntj otSXdS(s6Determine if the result object is a list of some sort.RqtListN(RrRsRp(R8RN((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR@s  cCs"h|i|d6|d6dd6S(sGiven an array of results, create an list object for those results. Args: results: The list of results. kind_base: The kind of list to create Returns: A synthetic list resource created from the list of individual results. RqR{sWThis JSON result is based on multiple API calls. This object was created in the client.tnote(R>(R8tresultst kind_base((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRos c Csti|ii}g}xF|D]>}t|||iid|}|i||i|q"W|ig}g}xr|D]j}|i o|i|i qt |i t o|i |i q|i|i qW||fS(sExecute a list of requests in a thread pool. Args: requests: A list of requests objects to execute. collection_name: The name of the collection. This is optional and is useful for subclasses that mutate more than one resource type. Returns: A tuple with (results, exceptions) where result list is the list of all results and exceptions is any exceptions that were raised. RG(R t ThreadPoolRR%R>R!tappendtAddt WaitShutdowntRaisedExceptiontResultRLR}R( R8trequestsRGttpRARDRBRvRa((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pytExecuteRequestss(     cCsZd}|i|p|S|i}|d}|didd} x|ddjo@|i||ijo&tid|| |d|dPn|pt|d d}|o#ti |} d | | f} n| } ti d || |i |i |i h|i d 6|dd 6} |i} |ido5|i|d}|o|| d<|i} qwn| i| }|id|}qKW|ddjovd|joi|d}|i}|i|dd\}}d|ijo djnoti|}q$n|dj o%g}|i||i||S|S(sWait for a potentially asynchronous operation to complete. Args: flag_values: The parsed FlagValues instance. timer: An implementation of the time object, providing time and sleep methods. result: The result of the request, potentially containing an operation. http: An optional httplib2.Http object to use for requests. Returns: The synchronous return value, usually an operation object. RYRWRiRTtDONEsPTimeout reached. %s of %s has not yet completed. The operation (%s) is still %s.RRtresource_collection_names%s %ss'Waiting for %s of %s. Sleeping for %ss.Rt operationRRRSRHtdeleteRZR:tGETii+N(RPR?RMRR#RRRR t SingularizeR*R"tsleepR~RkRR)RiRRJRIRDRTRtloadsRy(R8RgttimerRNRHRGRt start_timetoperation_typeRVtsingular_collection_nametqualified_nameR.tpoll_apitoperation_zoneRDt target_linktresponsetdataRv((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRKsX          !   cCs/tt|i||}d||ifS(sDGet help for command. Args: unused_argv: Remaining command line flags and arguments after parsing command (that is a copy of sys.argv at the time of the function call with all parsed flags removed); unused in this implementation. cmd_names: By default, if help is being shown for more than one command, and this command defines _all_commands_help, then _all_commands_help will be displayed instead of the class doc. cmd_names is used to determine the number of commands being displayed and if only a single command is display then the class doc is returned. Returns: __doc__ property for command function or a message stating there is no help. s %s Usage: %s(R?RQtCommandGetHelpt _GetUsage(R8t unused_argvt cmd_namesthelp_str((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR)scCsWdtiitid|if}t|dd}|od||f}n|S(s}Get the usage string for the command, used to print help messages. Returns: The usage string for the command. s(%s [--global_flags] %s [--command_flags]itpositional_argss%s %sN(RRtbasenameRURt _command_nameRRP(R8tresR-((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR@s #cCs tdS(sActual implementation of the command. Derived classes override this method, adding positional arguments to this method as required. Returns: Either a single JSON-serializable result or a tuple of a result and a list of exceptions that are thrown. N(tNotImplementedError(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyROs cCs||_|ii|_dS(sdSet the flags to be used by the command. Args: flag_values: The parsed flags values. N(RRR~(R8Rg((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRH[s cCs|iS(s)Get the flags object used by the command.(R(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRLdscCs tdS(sSet the Google Compute Engine API for the command. Derived classes override this method, pulling the necessary domain specific API out of the global API. Args: api: The Google Compute Engine API used by this command. N(R(R8R((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRmhs cCst|to|i|id}|id|ioG|id}t|djodi|d}q|d}n|i i djo(t|djo|d d|d Sn|S( s'Format a json value for tabular display. Strips off the project qualifier if present and elides the value if it won't fit inside of a max column size of 64 characters. Args: field_value: The json field value to be formatted. Returns: The formatted json value. Rs projects/iiRi@is..i( RLt basestringRRsR6R~RRRRR(R8t field_valuetfield_value_parts((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRss c sfdg}x|D]\}}t|to||id}n6x2|D]*}||id}|oPq^q^W|idig}|D]} |t| q~qW|S(s Convert a json instance to a dictionary for output. Args: instance_json: A JSON object represented as a python dict. name_map: A list of key, json-path object tuples where the json-path object is either a string or a list of strings. ('name', 'container.id') or ('name', ['container.id.new', 'container.id.old']) Returns: A list of extracted values selected by the associated JSON path. In addition, names are simplified to their shortest path components. cs|pi|gS|d|jof||d}t|to6tg}|D]}|||dqU~gS||dSgS(s3Extract and flatten a (possibly-repeated) field in a json object. Args: json_object: A JSON object represented as a python dict. subkey: a list of path elements, e.g. ['container', 'id']. Returns: [element1, element2, ...] or [] if the subkey could not be found. ii(RRLR}tsum(t json_objecttsubkeytelementRtx(R8tExtractSubKeys(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs 6t.t,(RLRRRyRRO( R8t instance_jsontname_mapR=t unused_keytpathstelementsRRR((R8Rsa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_FlattenObjectToLists  ;cCsd|jor|id |id xU|ddD]A}|id |id|df|id|dfq6WndS( sAdd any errors present in the operation result to the output table. Args: result: The json dictionary returned by the server. table: The pretty printing table to be customized. RZRRs errortcodes messagetmessageN(RR(serrorsR(RR(tAddRow(R8RNRRZ((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt__AddErrorsForOperations    cCsxx|D]p}t|tio|i|qt|to6tiiddit i t |i |qqWdS(s=Log a list of exceptions returned in multithreaded operation.s%s s N( RLRRRRSt ExceptionRURVRWRRXRYttypeR'(R8RaRb((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRKscCsd}|ii}yti|i}t}t|toM|idh}|||x+|idgD]}|||quWndi |}Wnt j onXt i i d|ti|iti|idS(s-Do specific logging when we hit an HttpError.cSs+|id}|o|i|ndS(NR(Rtadd(tmessagesRZR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt AddMessagesRZRs s Error: %s N(tresptreasonRRtcontenttsetRLtdictRRRuRURVRWRR\(R8RdRRRRRZ((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRSs"    cCs|iip|iidjoti|dtddGHdS|oV|iidjo|i|q|i|o|i|q|i |ndS(sPretty-print the result of the command. If a class defines a list of ('title', 'json.field.path') values named 'fields', this list will be used to print a table of results using prettytable. If self.fields does not exist, result will be printed as pretty JSON. Note that if the result is either an Operations object or an OperationsList, it will be special cased and formatted appropriately. Args: result: A JSON-serializable object to print. Rt sort_keystindentiNR( RRRRtdumpsRqt_PrintNamesOnlyR@t _PrintListt _PrintDetail(R8RN((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRJs cCsc|i|o|idg}n |g}x-|D]%}|id}|o |GHq6q6WdS(sPrints only names of the resources returned by Google Compute Engine API. Args: result: A GCE List resource to print. R{RRN(R@R(R8RNRvR9RR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs cCsJ|iidjo tiS|iidjo tiStiSdS(NRR(RRR tSparsePrettyFormattert CsvFormattertPrettyFormatter(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_CreateFormatters   cCsag}g}xH|idgD]4}|i|o|i|q|i|qW||fS(s?Partitions results into operations and non-operation resources.R{(RR?Ry(R8RNRRAR9((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt_PartitionResults&scCs|i|\}}|o|od}d}n d}}|p| o#|i||t|ddn|o|i|||indS(sPrints a result which is a Google Compute Engine List resource. For the result of batch operations, splits the result list into operations and other resources and possibly prints two tables. The operations typically represent errors (unless printing results of listoperations command) whereas the real resources typically represent successfully completed operations. Args: result: A GCE List resource to print. s Table of resources: s Table of operations: tsummary_fieldsN(RRPt_CreateAndPrintTableRtoperation_summary_fields(R8RNRRAt res_headert ops_header((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR1s     c Csg}|D]}||dq ~}g}|D]}||i||q0~} |i} | i|| i| |o |GHn| GHdS(sCreates a table representation of the list of resources and prints it. Args: values: List of resources to display. header: A header to print before the table (can be None). fields: Summary field definition for the table. iN(RRt AddColumnstAddRows( R8tvaluestheadertfieldsRRt column_namesRtrowtrowsR((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRMs%-    c Cs|i|o |i}nt|dd}|pdSg}|D]}||dqF~}|i}|id|i||}x1t|D]#\}} |i||| fqW|i|o|i ||n%t |do|i ||n|GHdS(svPrints a detail view of the result which is an individual resource. Args: result: A resource to print. t detail_fieldsNitpropertyRtCustomizePrintResult(spropertysvalue( R?toperation_detail_fieldsRRPRRRRRt,_GoogleComputeCommand__AddErrorsForOperationRmR( R8RNRRRt row_namesRt property_bagRtv((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR`s" %   cCstiS(s3Returns a list of scopes required for this command.(R tDEFAULT_AUTH_SCOPES(R8((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyt__GetRequiredAuthScopes~scCsidtijoRtdi oCy&ti}ttd|iWqetij oqeXndS(NR(RtFlagDicttpresentRtMetadataR7t GetProjectIdt MetadataError(R8tmetadata((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRGs " (snamesname(szoneszone(sstatussstatus(sstatus-messageRU(stargets targetLink(s insert-timeRX(soperation-types operationType(serrorserror.errors.code(swarnings warnings.code(snamesname(szoneszone(s creation-timeR\(sstatussstatus(R]R](sstatus-messageRU(stargets targetLink(s target-idR^(sclient-operation-idR_(s insert-timeRX(susersuser(s start-timeRa(send-timesendTime(soperation-types operationType(s error-codeRc(s error-messageRd(swarnings warnings.code(swarning-messageswarnings.messageN(GR'R(R)tGOOGLE_PROJECT_PATHtoperation_default_sort_fieldRRRqRR;RzRPRRRRRRRRt staticmethodRRRRRRRR R RRRRR!RR"R0R)R8RR>RCRORIRIR?R@RoRRKRRRRHRLRmRRRRKRSRJRRRRRRRRG(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRQs     F  *    .   Q +   &    >    L +    " I     1         tGoogleComputeListCommandcBs5eZdZeZeZdZdZdZ RS(sBase class for list commands.c Cstt|i||g}t|dgD]}||dq0~}|oUg}x,|D]$}|i||id|q^Wtidd|dd|ntiddd d d d|ti d dd d|ti dt dd|dS(sInitializes a new instance of a GoogleComputeListCommand. Args: name: The name of the command. flag_values: The values of command line flags to be used by the command. Rit-tsort_bysmSort output results by the given field name. Field names starting with a "-" will lead to a descending order.RgR%idsMaximum number of items to listt lower_boundiR&sFilter expression for filtering listed resources. See gcutil documentation for syntax of the filter expression here: http://developers.google.com/compute/docs/gcutil/tips#filteringtfetch_all_pagess/Whether to fetch all pages on truncated resultsN( R?RR;RRyRnt DEFINE_enumRPtDEFINE_integert DEFINE_stringRoRp(R8RRRgRRRt sort_fieldstfield((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyR;s41      c Cs|iip |iio d}n |ii}|ido7|io-d|ijoS|iioF|io |iit jo dg}q|i |iig}n5g}|io|i dn|i |i g}xz|D]r}|o |in |i}ti||i||ii|}|id}|i |idgqWh|d6|d6Sti|i|id|d|iiS(s.Returns the result of list on a resource type.RRSRqR{R%R&N(RRRRPR%Rtis_zone_level_collectionRStis_global_level_collectionR'R RyRRt ListZoneFunctListFuncR R|R~R&R(R8R%R$R{RSt list_funcR/Rq((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs>            c s`|idg}g}|iD]}||dq ~}g}|D]}||i||iqE~}|iipt|dd } | ot} | idot } | d} n| |jo4|i | t |dfdd| }qt i d | n|iip||ii }n|i} | i|| i|| GHd S( s'Prints a table for the given resources.R{itdefault_sort_fieldRiRcs|S(((R(t sort_col_idx(sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRstreversesInvalid sort column: N(RRRRRRRPRpR6RqR:tsortedRRRR%RRR( R8RNR{RRRRRRtsort_colRR((Rsa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs*()      ( R'R(R)RqRRpRR;RR(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyRs  ) 2(=R)RthttplibR3RRRRURMRXt apiclientRRRReRtoauth2client.clienttclientRMtgoogle.apputilsRRtgflagsRntgcutilRRRRR R R R R RRt CLIENT_IDt__default_api_version__tCURRENT_VERSIONt__supported_api_versions__RkR'RRRRPRoRpRqRRR&R*tobjectR+R<t OperationR>tCmdRQR(((sa/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.pyts