prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Option to associate public ip address in ec2 run-instance
  There doesn't seem to be any way to associate a public ip address without also adding a network interface with the --network-interfaces parameter. Is it possible for this to be a top level parameter?
  
  
  </issue>
  <code>
  [start of awscli/customizations/ec2runinstances.py]
  1 # Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License"). You
  4 # may not use this file except in compliance with the License. A copy of
  5 # the License is located at
  6 #
  7 #     http://aws.amazon.com/apache2.0/
  8 #
  9 # or in the "license" file accompanying this file. This file is
  10 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  11 # ANY KIND, either express or implied. See the License for the specific
  12 # language governing permissions and limitations under the License.
  13 """
  14 This customization adds two new parameters to the ``ec2 run-instance``
  15 command.  The first, ``--secondary-private-ip-addresses`` allows a list
  16 of IP addresses within the specified subnet to be associated with the
  17 new instance.  The second, ``--secondary-ip-address-count`` allows you
  18 to specify how many additional IP addresses you want but the actual
  19 address will be assigned for you.
  20 
  21 This functionality (and much more) is also available using the
  22 ``--network-interfaces`` complex argument.  This just makes two of
  23 the most commonly used features available more easily.
  24 """
  25 from awscli.arguments import CustomArgument
  26 
  27 
  28 # --secondary-private-ip-address
  29 SECONDARY_PRIVATE_IP_ADDRESSES_DOCS = (
  30     '[EC2-VPC] A secondary private IP address for the network interface '
  31     'or instance. You can specify this multiple times to assign multiple '
  32     'secondary IP addresses.  If you want additional private IP addresses '
  33     'but do not need a specific address, use the '
  34     '--secondary-private-ip-address-count option.')
  35 
  36 # --secondary-private-ip-address-count
  37 SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS = (
  38     '[EC2-VPC] The number of secondary IP addresses to assign to '
  39     'the network interface or instance.')
  40 
  41 
  42 def _add_params(argument_table, operation, **kwargs):
  43     arg = SecondaryPrivateIpAddressesArgument(
  44         name='secondary-private-ip-addresses',
  45         help_text=SECONDARY_PRIVATE_IP_ADDRESSES_DOCS)
  46     argument_table['secondary-private-ip-addresses'] = arg
  47     arg = SecondaryPrivateIpAddressCountArgument(
  48         name='secondary-private-ip-address-count',
  49         help_text=SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS)
  50     argument_table['secondary-private-ip-address-count'] = arg
  51 
  52 
  53 def _check_args(parsed_args, **kwargs):
  54     # This function checks the parsed args.  If the user specified
  55     # the --network-interfaces option with any of the scalar options we
  56     # raise an error.
  57     arg_dict = vars(parsed_args)
  58     if arg_dict['network_interfaces']:
  59         for key in ('secondary_private_ip_addresses',
  60                     'secondary_private_ip_address_count'):
  61             if arg_dict[key]:
  62                 msg = ('Mixing the --network-interfaces option '
  63                        'with the simple, scalar options is '
  64                        'not supported.')
  65                 raise ValueError(msg)
  66 
  67 EVENTS = [
  68     ('building-argument-table.ec2.run-instances', _add_params),
  69     ('operation-args-parsed.ec2.run-instances', _check_args),
  70     ]
  71 
  72 
  73 def register_runinstances(event_handler):
  74     # Register all of the events for customizing BundleInstance
  75     for event, handler in EVENTS:
  76         event_handler.register(event, handler)
  77 
  78 
  79 def _build_network_interfaces(params, key, value):
  80     # Build up the NetworkInterfaces data structure
  81     if 'network_interfaces' not in params:
  82         params['network_interfaces'] = [{'DeviceIndex': 0}]
  83 
  84     if key == 'PrivateIpAddresses':
  85         if 'PrivateIpAddresses' not in params['network_interfaces'][0]:
  86             params['network_interfaces'][0]['PrivateIpAddresses'] = value
  87     else:
  88         params['network_interfaces'][0][key] = value
  89 
  90 
  91 class SecondaryPrivateIpAddressesArgument(CustomArgument):
  92 
  93     def add_to_parser(self, parser, cli_name=None):
  94         parser.add_argument(self.cli_name, dest=self.py_name,
  95                             default=self._default, nargs='*')
  96 
  97     def add_to_params(self, parameters, value):
  98         if value:
  99             value = [{'PrivateIpAddress': v, 'Primary': False} for
  100                      v in value]
  101             _build_network_interfaces(parameters,
  102                                       'PrivateIpAddresses',
  103                                       value)
  104 
  105 
  106 class SecondaryPrivateIpAddressCountArgument(CustomArgument):
  107 
  108     def add_to_parser(self, parser, cli_name=None):
  109         parser.add_argument(self.cli_name, dest=self.py_name,
  110                             default=self._default, type=int)
  111 
  112     def add_to_params(self, parameters, value):
  113         if value:
  114             _build_network_interfaces(parameters,
  115                                       'SecondaryPrivateIpAddressCount',
  116                                       value)
  117
  [end of awscli/customizations/ec2runinstances.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/awscli/customizations/ec2runinstances.py b/awscli/customizations/ec2runinstances.py
  --- a/awscli/customizations/ec2runinstances.py
  +++ b/awscli/customizations/ec2runinstances.py
  @@ -38,6 +38,12 @@
       '[EC2-VPC] The number of secondary IP addresses to assign to '
       'the network interface or instance.')
   
  +# --associate-public-ip-address
  +ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS = (
  +    '[EC2-VPC] If specified a public IP address will be assigned '
  +    'to the new instance in a VPC.')
  +
  +
   
   def _add_params(argument_table, operation, **kwargs):
       arg = SecondaryPrivateIpAddressesArgument(
  @@ -48,6 +54,16 @@
           name='secondary-private-ip-address-count',
           help_text=SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS)
       argument_table['secondary-private-ip-address-count'] = arg
  +    arg = AssociatePublicIpAddressArgument(
  +        name='associate-public-ip-address',
  +        help_text=ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS,
  +        action='store_true', group_name='associate_public_ip')
  +    argument_table['associate-public-ip-address'] = arg
  +    arg = NoAssociatePublicIpAddressArgument(
  +        name='no-associate-public-ip-address',
  +        help_text=ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS,
  +        action='store_false', group_name='associate_public_ip')
  +    argument_table['no-associate-public-ip-address'] = arg
   
   
   def _check_args(parsed_args, **kwargs):
  @@ -57,7 +73,8 @@
       arg_dict = vars(parsed_args)
       if arg_dict['network_interfaces']:
           for key in ('secondary_private_ip_addresses',
  -                    'secondary_private_ip_address_count'):
  +                    'secondary_private_ip_address_count',
  +                    'associate_public_ip_address'):
               if arg_dict[key]:
                   msg = ('Mixing the --network-interfaces option '
                          'with the simple, scalar options is '
  @@ -114,3 +131,21 @@
               _build_network_interfaces(parameters,
                                         'SecondaryPrivateIpAddressCount',
                                         value)
  +
  +
  +class AssociatePublicIpAddressArgument(CustomArgument):
  +
  +    def add_to_params(self, parameters, value):
  +        if value is True:
  +            _build_network_interfaces(parameters,
  +                                      'AssociatePublicIpAddress',
  +                                      value)
  +
  +
  +class NoAssociatePublicIpAddressArgument(CustomArgument):
  +
  +    def add_to_params(self, parameters, value):
  +        if value is False:
  +            _build_network_interfaces(parameters,
  +                                      'AssociatePublicIpAddress',
  +                                      value)
  
verification_info: {"golden_diff": "diff --git a/awscli/customizations/ec2runinstances.py b/awscli/customizations/ec2runinstances.py\n--- a/awscli/customizations/ec2runinstances.py\n+++ b/awscli/customizations/ec2runinstances.py\n@@ -38,6 +38,12 @@\n     '[EC2-VPC] The number of secondary IP addresses to assign to '\n     'the network interface or instance.')\n \n+# --associate-public-ip-address\n+ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS = (\n+    '[EC2-VPC] If specified a public IP address will be assigned '\n+    'to the new instance in a VPC.')\n+\n+\n \n def _add_params(argument_table, operation, **kwargs):\n     arg = SecondaryPrivateIpAddressesArgument(\n@@ -48,6 +54,16 @@\n         name='secondary-private-ip-address-count',\n         help_text=SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS)\n     argument_table['secondary-private-ip-address-count'] = arg\n+    arg = AssociatePublicIpAddressArgument(\n+        name='associate-public-ip-address',\n+        help_text=ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS,\n+        action='store_true', group_name='associate_public_ip')\n+    argument_table['associate-public-ip-address'] = arg\n+    arg = NoAssociatePublicIpAddressArgument(\n+        name='no-associate-public-ip-address',\n+        help_text=ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS,\n+        action='store_false', group_name='associate_public_ip')\n+    argument_table['no-associate-public-ip-address'] = arg\n \n \n def _check_args(parsed_args, **kwargs):\n@@ -57,7 +73,8 @@\n     arg_dict = vars(parsed_args)\n     if arg_dict['network_interfaces']:\n         for key in ('secondary_private_ip_addresses',\n-                    'secondary_private_ip_address_count'):\n+                    'secondary_private_ip_address_count',\n+                    'associate_public_ip_address'):\n             if arg_dict[key]:\n                 msg = ('Mixing the --network-interfaces option '\n                        'with the simple, scalar options is '\n@@ -114,3 +131,21 @@\n             _build_network_interfaces(parameters,\n                                       'SecondaryPrivateIpAddressCount',\n                                       value)\n+\n+\n+class AssociatePublicIpAddressArgument(CustomArgument):\n+\n+    def add_to_params(self, parameters, value):\n+        if value is True:\n+            _build_network_interfaces(parameters,\n+                                      'AssociatePublicIpAddress',\n+                                      value)\n+\n+\n+class NoAssociatePublicIpAddressArgument(CustomArgument):\n+\n+    def add_to_params(self, parameters, value):\n+        if value is False:\n+            _build_network_interfaces(parameters,\n+                                      'AssociatePublicIpAddress',\n+                                      value)\n", "issue": "Option to associate public ip address in ec2 run-instance\nThere doesn't seem to be any way to associate a public ip address without also adding a network interface with the --network-interfaces parameter. Is it possible for this to be a top level parameter?\n\n", "before_files": [{"content": "# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\n\"\"\"\nThis customization adds two new parameters to the ``ec2 run-instance``\ncommand.  The first, ``--secondary-private-ip-addresses`` allows a list\nof IP addresses within the specified subnet to be associated with the\nnew instance.  The second, ``--secondary-ip-address-count`` allows you\nto specify how many additional IP addresses you want but the actual\naddress will be assigned for you.\n\nThis functionality (and much more) is also available using the\n``--network-interfaces`` complex argument.  This just makes two of\nthe most commonly used features available more easily.\n\"\"\"\nfrom awscli.arguments import CustomArgument\n\n\n# --secondary-private-ip-address\nSECONDARY_PRIVATE_IP_ADDRESSES_DOCS = (\n    '[EC2-VPC] A secondary private IP address for the network interface '\n    'or instance. You can specify this multiple times to assign multiple '\n    'secondary IP addresses.  If you want additional private IP addresses '\n    'but do not need a specific address, use the '\n    '--secondary-private-ip-address-count option.')\n\n# --secondary-private-ip-address-count\nSECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS = (\n    '[EC2-VPC] The number of secondary IP addresses to assign to '\n    'the network interface or instance.')\n\n\ndef _add_params(argument_table, operation, **kwargs):\n    arg = SecondaryPrivateIpAddressesArgument(\n        name='secondary-private-ip-addresses',\n        help_text=SECONDARY_PRIVATE_IP_ADDRESSES_DOCS)\n    argument_table['secondary-private-ip-addresses'] = arg\n    arg = SecondaryPrivateIpAddressCountArgument(\n        name='secondary-private-ip-address-count',\n        help_text=SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS)\n    argument_table['secondary-private-ip-address-count'] = arg\n\n\ndef _check_args(parsed_args, **kwargs):\n    # This function checks the parsed args.  If the user specified\n    # the --network-interfaces option with any of the scalar options we\n    # raise an error.\n    arg_dict = vars(parsed_args)\n    if arg_dict['network_interfaces']:\n        for key in ('secondary_private_ip_addresses',\n                    'secondary_private_ip_address_count'):\n            if arg_dict[key]:\n                msg = ('Mixing the --network-interfaces option '\n                       'with the simple, scalar options is '\n                       'not supported.')\n                raise ValueError(msg)\n\nEVENTS = [\n    ('building-argument-table.ec2.run-instances', _add_params),\n    ('operation-args-parsed.ec2.run-instances', _check_args),\n    ]\n\n\ndef register_runinstances(event_handler):\n    # Register all of the events for customizing BundleInstance\n    for event, handler in EVENTS:\n        event_handler.register(event, handler)\n\n\ndef _build_network_interfaces(params, key, value):\n    # Build up the NetworkInterfaces data structure\n    if 'network_interfaces' not in params:\n        params['network_interfaces'] = [{'DeviceIndex': 0}]\n\n    if key == 'PrivateIpAddresses':\n        if 'PrivateIpAddresses' not in params['network_interfaces'][0]:\n            params['network_interfaces'][0]['PrivateIpAddresses'] = value\n    else:\n        params['network_interfaces'][0][key] = value\n\n\nclass SecondaryPrivateIpAddressesArgument(CustomArgument):\n\n    def add_to_parser(self, parser, cli_name=None):\n        parser.add_argument(self.cli_name, dest=self.py_name,\n                            default=self._default, nargs='*')\n\n    def add_to_params(self, parameters, value):\n        if value:\n            value = [{'PrivateIpAddress': v, 'Primary': False} for\n                     v in value]\n            _build_network_interfaces(parameters,\n                                      'PrivateIpAddresses',\n                                      value)\n\n\nclass SecondaryPrivateIpAddressCountArgument(CustomArgument):\n\n    def add_to_parser(self, parser, cli_name=None):\n        parser.add_argument(self.cli_name, dest=self.py_name,\n                            default=self._default, type=int)\n\n    def add_to_params(self, parameters, value):\n        if value:\n            _build_network_interfaces(parameters,\n                                      'SecondaryPrivateIpAddressCount',\n                                      value)\n", "path": "awscli/customizations/ec2runinstances.py"}]}