libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bchazalet <...@git.apache.org>
Subject [GitHub] libcloud pull request #1165: Allow shared vpc in gce
Date Thu, 18 Jan 2018 13:26:05 GMT
GitHub user bchazalet opened a pull request:

    https://github.com/apache/libcloud/pull/1165

    Allow shared vpc in gce

    ## Allow for use of shared network (vpc) and subnetwork in GCE
    
    ### Description
    
    It's currently not possible to create an GCE instance within a [shared VPC](https://cloud.google.com/vpc/docs/shared-vpc)
and a shared subnet via ansible although it's possible from the google compute console (see
https://github.com/ansible/ansible/issues/30759).
    
    In the code, the problem seems to be that even if a fully qualified resource URL is passed
for a network (or subnetwork), it is parsed into parts and then reconstructed assuming the
resource is under the configured gcloud project. But since we're using a shared VPC, the resource
is under a different project.
    
     For example, say, I have two projects, `my-main-project` which hosts a shared vpc named
`sharedvpc` and `my-other-project` which has shared access to `sharedvpc`. What I want to
do is to create a GCE instance under `my-other-project` and within the `sharedvpc` project.
    
    So in the gce module, I pass the resource URLs:
    ```yml
      - name: Create instance
          gce:
            instance_names: "{{ instance_name }}"
            machine_type: "{{ machine_type }}"
            image: "{{ image_name }}"
            network: https://www.googleapis.com/compute/v1/projects/my-main-project/global/networks/sharedvpc
            subnetwork: https://www.googleapis.com/compute/v1/projects/my-main-project/regions/europe-west2/subnetworks/default"
            zone: "{{ zone }}"
            tags: app-servers
            state: present
    ```
    
    But, in the module's code, the resource URLs will be parsed and transform respectively
to `/global/networks/sharedvpc` and `/regions/europe-west2/subnetworks/default` which implicitly
refer to the project configured by glcoud, i.e. `my-other-project`. As a result, I get a `ResourceNotFound`
error.
    
    Instead, if a resource (network or subnetwork) is fully qualified via a resource URL (i.e.
it starts with `https://`), we can simply use it in the underlying google request. This is
what the new code does.
    
    ### Status
    
    Done, ready for review. I'm new to libcloud, so I'll happily take feedback and amend the
PR.
    
    ### Checklist (tick everything that applies)
    
    - [ ] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide)
(required, can be done after the PR checks)
    - [ ] Documentation
    - [ ] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
    - [ ] [ICLA](http://libcloud.readthedocs.org/en/latest/development.html#contributing-bigger-changes)
(required for bigger changes)


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/bchazalet/libcloud wip/hack-to-allow-shared-vpc-in-gce

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/libcloud/pull/1165.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1165
    
----
commit f71da15c372a0d69a9d705e073a5a4cadfd897c1
Author: Boris Chazalet <bchazalet@...>
Date:   2018-01-18T09:05:29Z

    Allow shared network/subnetwork
    
    If they come as fully qualified resource URLs (https://)

commit 408ac7bbd9def69499434fdd389ef93b3c5f804e
Author: Boris Chazalet <bchazalet@...>
Date:   2018-01-18T09:18:36Z

    Make sure simply qualified subnet works too

----


---

Mime
View raw message