You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2020/03/03 15:19:52 UTC

[GitHub] [libcloud] grimpy opened a new pull request #1437: Implement g8 provider for libcloud

grimpy opened a new pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437
 
 
   Signed-off-by: Jo De Boeck <de...@gmail.com>
   
   ## Changes Title (replace this with a logical title for your changes)
   
   ### Description
   
   Implement driver for https://gig.tech/ it's G8
   
   ### Status
   
   - done, ready for review
   
   ### Checklist (tick everything that applies)
   
   - [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide) (required, can be done after the PR checks)
   - [ ] Documentation
   - [x] [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)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami merged pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami merged pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r394664919
 
 

 ##########
 File path: libcloud/compute/drivers/gig_g8.py
 ##########
 @@ -269,12 +273,14 @@ def ex_create_network(self, name, private_network="192.168.103.0/24",
                                     {"cloudspaceId": networkid})
         return self._to_network(network)
 
-    def ex_destroy_network(self, network):
+    def ex_destroy_network(self, ex_network):
 
 Review comment:
   Sorry, I should have made this more clear in my original comment - ``ex_`` argument name prefix is only needed if the method name itself doesn't contain it.
   
   If the method name already contains the prefix, then argument itself doesn't need to contain it.
   
   I can address this when merging the PR.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r389310635
 
 

 ##########
 File path: libcloud/compute/drivers/gig_g8.py
 ##########
 @@ -0,0 +1,501 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""
+GiG G8 Driver
+
+"""
+import json
+from libcloud.compute.base import NodeImage, NodeSize, Node
+from libcloud.compute.base import NodeDriver, UuidMixin
+from libcloud.compute.base import StorageVolume, NodeAuthSSHKey
+from libcloud.compute.types import Provider, NodeState
+from libcloud.common.gig_g8 import G8Connection
+
+
+class G8PortForward(UuidMixin):
+    def __init__(self, network, node_id, publicport,
+                 privateport, protocol, driver):
+        self.node_id = node_id
+        self.network = network
+        self.publicport = publicport
+        self.privateport = privateport
+        self.protocol = protocol
+        self.driver = driver
+        UuidMixin.__init__(self)
+
+    def destroy(self):
+        self.driver.ex_delete_portforward(self)
+
+
+class G8Network(UuidMixin):
+    """
+    G8 Network object class.
+
+    This class maps to a cloudspace
+
+    """
+
+    def __init__(self, id, name, cidr, publicipaddress, driver, extra=None):
+        self.id = id
+        self.name = name
+        self._cidr = cidr
+        self.driver = driver
+        self.publicipaddress = publicipaddress
+        self.extra = extra
+        UuidMixin.__init__(self)
+
+    @property
+    def cidr(self):
+        """
+        Cidr is not part of the list result
+        we will lazily fetch it with a get request
+        """
+        if self._cidr is None:
+            networkdata = self.driver._api_request("/cloudspaces/get",
+                                                   {"cloudspaceId": self.id})
+            self._cidr = networkdata["privatenetwork"]
+        return self._cidr
+
+    def list_nodes(self):
+        return self.driver.list_nodes(self)
+
+    def destroy(self):
+        return self.driver.ex_destroy_network(self)
+
+    def list_portforwards(self):
+        return self.driver.ex_list_portforwards(self)
+
+    def create_portforward(self, node, publicport,
+                           privateport, protocol='tcp'):
+        return self.driver.ex_create_portforward(self, node, publicport,
+                                                 privateport, protocol)
+
+
+class G8NodeDriver(NodeDriver):
+    """
+    GiG G8 node driver
+
+    """
+
+    NODE_STATE_MAP = {'VIRTUAL': NodeState.PENDING,
+                      'HALTED': NodeState.STOPPED,
+                      'RUNNING': NodeState.RUNNING,
+                      'DESTROYED': NodeState.TERMINATED,
+                      'DELETED': NodeState.TERMINATED,
+                      'PAUSED': NodeState.PAUSED,
+                      'ERROR': NodeState.ERROR,
+
+                      # transition states
+                      'DEPLOYING': NodeState.PENDING,
+                      'STOPPING': NodeState.STOPPING,
+                      'MOVING': NodeState.MIGRATING,
+                      'RESTORING': NodeState.PENDING,
+                      'STARTING': NodeState.STARTING,
+                      'PAUSING': NodeState.PENDING,
+                      'RESUMING': NodeState.PENDING,
+                      'RESETTING': NodeState.REBOOTING,
+                      'DELETING': NodeState.TERMINATED,
+                      'DESTROYING': NodeState.TERMINATED,
+                      'ADDING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_DISK': NodeState.RECONFIGURING,
+                      'DETACHING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_NIC': NodeState.RECONFIGURING,
+                      'DETTACHING_NIC': NodeState.RECONFIGURING,
+                      'DELETING_DISK': NodeState.RECONFIGURING,
+                      'CHANGING_DISK_LIMITS': NodeState.RECONFIGURING,
+                      'CLONING': NodeState.PENDING,
+                      'RESIZING': NodeState.RECONFIGURING,
+                      'CREATING_TEMPLATE': NodeState.PENDING,
+                      }
+
+    name = "GiG G8 Node Provider"
+    website = 'https://gig.tech'
+    type = Provider.GIG_G8
+    connectionCls = G8Connection
+
+    def __init__(self, apiurl, token, account_id):
+        """
+        :param  apiurl: G8 api url
+        :type   apiurl: ``str``
+        :param  token: Token to use for api (jwt)
+        :type   token: ``str``
+        :param  account_id: Id of the account to connect to
+        :type   account_id: ``int``
+
+        :rtype: ``None``
+        """
+        self._apiurl = apiurl.rstrip("/")
+        super(G8NodeDriver, self).__init__(key=token)
+        self._account_id = account_id
+        self._location_data = None
+
+    def _ex_connection_class_kwargs(self):
+        return {"url": self._apiurl}
+
+    def _api_request(self, endpoint, params=None):
+        return self.connection.request(endpoint.lstrip("/"),
+                                       data=json.dumps(params),
+                                       method="POST").object
+
+    @property
+    def _location(self):
+        if self._location_data is None:
+            self._location_data = self._api_request("/locations/list")[0]
+        return self._location_data
+
+    def create_node(self, name, size, image, network,
+                    description, auth=None, ex_create_attr=None):
+        """
+        Create a node.
+
+        The `ex_create_attr` parameter can include the following dictionary
+        key and value pairs:
+
+        * `memory`: ``int`` Memory in MiB
+                    (only used if size is None and vcpus is passed
+        * `vcpus`: ``int`` Amount of vcpus
+                   (only used if size is None and memory is passed)
+        * `disk_size`: ``int`` Size of bootdisk
+                       defaults to minimumsize of the image
+        * `user_data`: ``str`` for cloud-config data
+        * `private_ip`: ``str`` Private Ip inside network
+        * `data_disks`: ``list(int)`` Extra data disks to assign
+                        to vm list of disk sizes in GiB
+
+        :param name: the name to assign the vm
+        :type  name: ``str``
+
+        :param size: the plan size to create
+                       mutual exclusive with `memory` `vcpus`
+        :type  size: :class:`NodeSize`
+
+        :param image: which distribution to deploy on the vm
+        :type  image: :class:`NodeImage`
+
+        :param network: G8 Network to place vm in
+        :type  size: :class:`G8Network`
+
+        :param description: Descripton of vm
+        :type  size: : ``str``
+
+        :param auth: an SSH key
+        :type  auth: :class:`NodeAuthSSHKey`
+
+        :param ex_create_attr: A dictionary of optional attributes for
+                                 vm creation
+        :type  ex_create_attr: ``dict``
+
+        :return: The newly created node.
+        :rtype: :class:`Node`
+        """
+        params = {"name": name,
+                  "imageId": int(image.id),
+                  "cloudspaceId": int(network.id),
+                  "description": description}
+
+        ex_create_attr = ex_create_attr or {}
+        if size:
+            params["sizeId"] = int(size.id)
+        else:
+            params["memory"] = ex_create_attr["memory"]
+            params["vcpus"] = ex_create_attr["vcpus"]
+        if "user_data" in ex_create_attr:
+            params["userdata"] = ex_create_attr["user_data"]
+        if "data_disks" in ex_create_attr:
+            params["datadisks"] = ex_create_attr["data_disks"]
+        if "private_ip" in ex_create_attr:
+            params["privateIp"] = ex_create_attr["private_ip"]
+        if "disk_size" in ex_create_attr:
+            params["disksize"] = ex_create_attr["disk_size"]
+        else:
+            params["disksize"] = image.extra["min_disk_size"]
+        if auth and isinstance(auth, NodeAuthSSHKey):
+            userdata = params.get("userdata", {})
+            users = userdata.setdefault("users", [])
+            root = None
+            for user in users:
+                if user["name"] == "root":
+                    root = user
+                    break
+            else:
+                root = {"name": "root", "shell": "/bin/bash"}
+                users.append(root)
+            keys = root.setdefault("ssh-authorized-keys", [])
+            keys.append(auth.pubkey)
+        elif auth:
+            error = "Auth type {} is not implemented".format(type(auth))
+            raise NotImplementedError(error)
+
+        machineId = self._api_request("/machines/create", params)
+        machine = self._api_request("/machines/get",
+                                    params={"machineId": machineId})
+        return self._to_node(machine)
+
+    def ex_create_network(self, name, private_network="192.168.103.0/24",
+                          type="vgw"):
+        """
+        Create network also known as cloudspace
+
+        :param name: the name to assing to the network
+        :type  name: ``str``
+
+        :param private_network: subnet used as private network
+        :type  private_network: ``str``
+
+        :param type: type of the gateway vgw or routeros
+        :type  type: ``str``
+        """
+        userinfo = self._api_request("../system/usermanager/whoami")
+        params = {"accountId": self._account_id,
+                  "privatenetwork": private_network,
+                  "access": userinfo["name"],
+                  "name": name,
+                  "location": self._location["locationCode"],
+                  "type": type}
+        networkid = self._api_request("/cloudspaces/create", params)
+        network = self._api_request("/cloudspaces/get",
+                                    {"cloudspaceId": networkid})
+        return self._to_network(network)
+
+    def ex_destroy_network(self, network):
+        self._api_request("/cloudspaces/delete",
+                          {"cloudspaceId": int(network.id)})
+        return True
+
+    def stop_node(self, node):
+        """
+        Stop virtual machine
+        """
+        node.state = NodeState.STOPPING
+        self._api_request("/machines/stop", {"machineId": int(node.id)})
+        node.state = NodeState.STOPPED
+        return True
+
+    def ex_list_portforwards(self, network):
+        data = self._api_request("/portforwarding/list",
+                                 {"cloudspaceId": int(network.id)})
+        forwards = []
+        for forward in data:
+            forwards.append(self._to_port_forward(forward, network))
+        return forwards
+
+    def ex_create_portforward(self, network, node, publicport,
+                              privateport, protocol="tcp"):
+        params = {"cloudspaceId": int(network.id),
+                  "machineId": int(node.id),
+                  "localPort": privateport,
+                  "publicPort": publicport,
+                  "publicIp": network.publicipaddress,
+                  "protocol": protocol}
+        self._api_request("/portforwarding/create", params)
+        return self._to_port_forward(params, network)
+
+    def ex_delete_portforward(self, portforward):
+        params = {"cloudspaceId": int(portforward.network.id),
+                  "publicIp": portforward.network.publicipaddress,
+                  "publicPort": portforward.publicport,
+                  "proto": portforward.protocol}
+        self._api_request("/portforwarding/deleteByPort", params)
+        return True
+
+    def start_node(self, node):
+        """
+        Start virtual machine
+        """
+        node.state = NodeState.STARTING
+        self._api_request("/machines/start", {"machineId": int(node.id)})
+        node.state = NodeState.RUNNING
+        return True
+
+    def ex_list_networks(self):
+        """
+        Return the list of networks.
+
+        :return: A list of network objects.
+        :rtype: ``list`` of :class:`G8Network`
+        """
+        networks = []
+        for network in self._api_request("/cloudspaces/list"):
+            if network["accountId"] == self._account_id:
+                networks.append(self._to_network(network))
+        return networks
+
+    def list_sizes(self):
+        """
+        Returns a list of node sizes as a cloud provider might have
+
+        """
+        location = self._location["locationCode"]
+
+        sizes = []
+        for size in self._api_request("/sizes/list", {"location": location}):
+            sizes.extend(self._to_size(size))
+        return sizes
+
+    def list_nodes(self, network=None):
 
 Review comment:
   ``network`` argument is not part of the base API so please prefix it with ``ex_``.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594021101
 
 
   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=h1) Report
   > Merging [#1437](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=desc) into [trunk](https://codecov.io/gh/apache/libcloud/commit/62c9c855f4fb8b409307cdc2f8358dda8f36f58a?src=pr&el=desc) will **increase** coverage by `0.07%`.
   > The diff coverage is `86.53%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1437/graphs/tree.svg?width=650&token=PYoduksh69&height=150&src=pr)](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1437      +/-   ##
   ==========================================
   + Coverage   86.11%   86.18%   +0.07%     
   ==========================================
     Files         370      373       +3     
     Lines       77586    78042     +456     
     Branches     7658     7677      +19     
   ==========================================
   + Hits        66814    67262     +448     
   - Misses       7876     7879       +3     
   - Partials     2896     2901       +5
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [libcloud/compute/providers.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9wcm92aWRlcnMucHk=) | `87.5% <ø> (ø)` | :arrow_up: |
   | [libcloud/test/compute/test\_gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21wdXRlL3Rlc3RfZ2lnX2c4LnB5) | `100% <100%> (ø)` | |
   | [libcloud/compute/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS90eXBlcy5weQ==) | `100% <100%> (+1.11%)` | :arrow_up: |
   | [libcloud/common/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dpZ19nOC5weQ==) | `100% <100%> (ø)` | |
   | [libcloud/compute/drivers/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9kcml2ZXJzL2dpZ19nOC5weQ==) | `79.71% <79.71%> (ø)` | |
   | [libcloud/common/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL3R5cGVzLnB5) | `97.01% <0%> (-2.99%)` | :arrow_down: |
   | [libcloud/test/common/test\_openstack\_identity.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21tb24vdGVzdF9vcGVuc3RhY2tfaWRlbnRpdHkucHk=) | `97.7% <0%> (-0.37%)` | :arrow_down: |
   | [libcloud/dns/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvZG5zL3R5cGVzLnB5) | `100% <0%> (ø)` | :arrow_up: |
   | [libcloud/test/dns/test\_base.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9kbnMvdGVzdF9iYXNlLnB5) | `100% <0%> (ø)` | :arrow_up: |
   | [libcloud/container/base.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29udGFpbmVyL2Jhc2UucHk=) | `89.06% <0%> (ø)` | :arrow_up: |
   | ... and [20 more](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=footer). Last update [62c9c85...b177828](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594021101
 
 
   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=h1) Report
   > Merging [#1437](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=desc) into [trunk](https://codecov.io/gh/apache/libcloud/commit/62c9c855f4fb8b409307cdc2f8358dda8f36f58a&el=desc) will **increase** coverage by `0.03%`.
   > The diff coverage is `78.65%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1437/graphs/tree.svg?width=650&height=150&src=pr&token=PYoduksh69)](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1437      +/-   ##
   ==========================================
   + Coverage   86.11%   86.15%   +0.03%     
   ==========================================
     Files         370      373       +3     
     Lines       77586    78104     +518     
     Branches     7658     7687      +29     
   ==========================================
   + Hits        66814    67291     +477     
   - Misses       7876     7909      +33     
   - Partials     2896     2904       +8     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [libcloud/compute/providers.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9wcm92aWRlcnMucHk=) | `87.50% <ø> (ø)` | |
   | [libcloud/compute/drivers/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9kcml2ZXJzL2dpZ19nOC5weQ==) | `69.72% <69.72%> (ø)` | |
   | [libcloud/common/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dpZ19nOC5weQ==) | `100.00% <100.00%> (ø)` | |
   | [libcloud/compute/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS90eXBlcy5weQ==) | `100.00% <100.00%> (+1.11%)` | :arrow_up: |
   | [libcloud/test/compute/test\_gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21wdXRlL3Rlc3RfZ2lnX2c4LnB5) | `100.00% <100.00%> (ø)` | |
   | [libcloud/common/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL3R5cGVzLnB5) | `97.01% <0.00%> (-2.99%)` | :arrow_down: |
   | [libcloud/test/common/test\_openstack\_identity.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21tb24vdGVzdF9vcGVuc3RhY2tfaWRlbnRpdHkucHk=) | `97.76% <0.00%> (-0.31%)` | :arrow_down: |
   | [libcloud/dns/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvZG5zL3R5cGVzLnB5) | `100.00% <0.00%> (ø)` | |
   | [libcloud/common/azure.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2F6dXJlLnB5) | `84.76% <0.00%> (ø)` | |
   | [libcloud/common/google.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dvb2dsZS5weQ==) | `65.94% <0.00%> (ø)` | |
   | ... and [22 more](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=footer). Last update [62c9c85...5e68465](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-601419473
 
 
   Thanks for addressing the feedback.
   
   I will go ahead and merge those changes into trunk.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594132850
 
 
   Thanks for the contribution.
   
   In the mean time, while we review it, can you please work on filling your ICLA?
   
   Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594591866
 
 
   @grimpy Please email it to secretary@apache.org as per https://www.apache.org/licenses/contributor-agreements.html#submitting
   
   (I need to update ICLA link in the issue template, it looks like the page got moved around)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r389310886
 
 

 ##########
 File path: libcloud/compute/drivers/gig_g8.py
 ##########
 @@ -0,0 +1,501 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""
+GiG G8 Driver
+
+"""
+import json
+from libcloud.compute.base import NodeImage, NodeSize, Node
+from libcloud.compute.base import NodeDriver, UuidMixin
+from libcloud.compute.base import StorageVolume, NodeAuthSSHKey
+from libcloud.compute.types import Provider, NodeState
+from libcloud.common.gig_g8 import G8Connection
+
+
+class G8PortForward(UuidMixin):
+    def __init__(self, network, node_id, publicport,
+                 privateport, protocol, driver):
+        self.node_id = node_id
+        self.network = network
+        self.publicport = publicport
+        self.privateport = privateport
+        self.protocol = protocol
+        self.driver = driver
+        UuidMixin.__init__(self)
+
+    def destroy(self):
+        self.driver.ex_delete_portforward(self)
+
+
+class G8Network(UuidMixin):
+    """
+    G8 Network object class.
+
+    This class maps to a cloudspace
+
+    """
+
+    def __init__(self, id, name, cidr, publicipaddress, driver, extra=None):
+        self.id = id
+        self.name = name
+        self._cidr = cidr
+        self.driver = driver
+        self.publicipaddress = publicipaddress
+        self.extra = extra
+        UuidMixin.__init__(self)
+
+    @property
+    def cidr(self):
+        """
+        Cidr is not part of the list result
+        we will lazily fetch it with a get request
+        """
+        if self._cidr is None:
+            networkdata = self.driver._api_request("/cloudspaces/get",
+                                                   {"cloudspaceId": self.id})
+            self._cidr = networkdata["privatenetwork"]
+        return self._cidr
+
+    def list_nodes(self):
+        return self.driver.list_nodes(self)
+
+    def destroy(self):
+        return self.driver.ex_destroy_network(self)
+
+    def list_portforwards(self):
+        return self.driver.ex_list_portforwards(self)
+
+    def create_portforward(self, node, publicport,
+                           privateport, protocol='tcp'):
+        return self.driver.ex_create_portforward(self, node, publicport,
+                                                 privateport, protocol)
+
+
+class G8NodeDriver(NodeDriver):
+    """
+    GiG G8 node driver
+
+    """
+
+    NODE_STATE_MAP = {'VIRTUAL': NodeState.PENDING,
+                      'HALTED': NodeState.STOPPED,
+                      'RUNNING': NodeState.RUNNING,
+                      'DESTROYED': NodeState.TERMINATED,
+                      'DELETED': NodeState.TERMINATED,
+                      'PAUSED': NodeState.PAUSED,
+                      'ERROR': NodeState.ERROR,
+
+                      # transition states
+                      'DEPLOYING': NodeState.PENDING,
+                      'STOPPING': NodeState.STOPPING,
+                      'MOVING': NodeState.MIGRATING,
+                      'RESTORING': NodeState.PENDING,
+                      'STARTING': NodeState.STARTING,
+                      'PAUSING': NodeState.PENDING,
+                      'RESUMING': NodeState.PENDING,
+                      'RESETTING': NodeState.REBOOTING,
+                      'DELETING': NodeState.TERMINATED,
+                      'DESTROYING': NodeState.TERMINATED,
+                      'ADDING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_DISK': NodeState.RECONFIGURING,
+                      'DETACHING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_NIC': NodeState.RECONFIGURING,
+                      'DETTACHING_NIC': NodeState.RECONFIGURING,
+                      'DELETING_DISK': NodeState.RECONFIGURING,
+                      'CHANGING_DISK_LIMITS': NodeState.RECONFIGURING,
+                      'CLONING': NodeState.PENDING,
+                      'RESIZING': NodeState.RECONFIGURING,
+                      'CREATING_TEMPLATE': NodeState.PENDING,
+                      }
+
+    name = "GiG G8 Node Provider"
+    website = 'https://gig.tech'
+    type = Provider.GIG_G8
+    connectionCls = G8Connection
+
+    def __init__(self, apiurl, token, account_id):
 
 Review comment:
   For consistency with the base API, constructor argument should look something like this:
   
   ```python
   def __init__(self, user_id, key, api_url, ....
   ```
   
   And in this case, user_id would be account id.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] grimpy commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
grimpy commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594738180
 
 
   @Kami ICLA has been send

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r389310469
 
 

 ##########
 File path: libcloud/test/compute/test_gig_g8.py
 ##########
 @@ -0,0 +1,151 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import sys
+import unittest
+
+from libcloud.utils.py3 import httplib
+from libcloud.test import MockHttp
+from libcloud.compute.base import NodeImage, NodeSize, Node, StorageVolume
+from libcloud.compute.drivers.gig_g8 import G8NodeDriver, G8Network, G8PortForward
+from libcloud.test.file_fixtures import ComputeFileFixtures
+
+
+class G8MockHttp(MockHttp):
+    """Fixtures needed for tests related to rating model"""
+    fixtures = ComputeFileFixtures('gig_g8')
+
+    def __getattr__(self, key):
+        def method(method, path, params, headers):
+            response = self.fixtures.load('{}.json'.format(key.lstrip("_")))
 
 Review comment:
   I know a lot of existing test cases don't do that, but it's also preferred to check HTTP method as well (perhaps you could add it to the filename, e.g. ``POST_machines_create.json`` or similar.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-596135842
 
 
   If you get a chance it would also be great to add type annotations for all the new methods and classes.
   
   Here is an example of how that's handled on the base driver class - https://github.com/apache/libcloud/blob/trunk/libcloud/compute/base.py#L190.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594021101
 
 
   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=h1) Report
   > Merging [#1437](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=desc) into [trunk](https://codecov.io/gh/apache/libcloud/commit/62c9c855f4fb8b409307cdc2f8358dda8f36f58a&el=desc) will **increase** coverage by `0.03%`.
   > The diff coverage is `78.65%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1437/graphs/tree.svg?width=650&height=150&src=pr&token=PYoduksh69)](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1437      +/-   ##
   ==========================================
   + Coverage   86.11%   86.15%   +0.03%     
   ==========================================
     Files         370      373       +3     
     Lines       77586    78104     +518     
     Branches     7658     7687      +29     
   ==========================================
   + Hits        66814    67291     +477     
   - Misses       7876     7909      +33     
   - Partials     2896     2904       +8     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [libcloud/compute/providers.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9wcm92aWRlcnMucHk=) | `87.50% <ø> (ø)` | |
   | [libcloud/compute/drivers/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9kcml2ZXJzL2dpZ19nOC5weQ==) | `69.72% <69.72%> (ø)` | |
   | [libcloud/common/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dpZ19nOC5weQ==) | `100.00% <100.00%> (ø)` | |
   | [libcloud/compute/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS90eXBlcy5weQ==) | `100.00% <100.00%> (+1.11%)` | :arrow_up: |
   | [libcloud/test/compute/test\_gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21wdXRlL3Rlc3RfZ2lnX2c4LnB5) | `100.00% <100.00%> (ø)` | |
   | [libcloud/common/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL3R5cGVzLnB5) | `97.01% <0.00%> (-2.99%)` | :arrow_down: |
   | [libcloud/test/common/test\_openstack\_identity.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21tb24vdGVzdF9vcGVuc3RhY2tfaWRlbnRpdHkucHk=) | `97.76% <0.00%> (-0.31%)` | :arrow_down: |
   | [libcloud/dns/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvZG5zL3R5cGVzLnB5) | `100.00% <0.00%> (ø)` | |
   | [libcloud/common/azure.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2F6dXJlLnB5) | `84.76% <0.00%> (ø)` | |
   | [libcloud/common/google.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dvb2dsZS5weQ==) | `65.94% <0.00%> (ø)` | |
   | ... and [22 more](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=footer). Last update [62c9c85...9fff275](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] grimpy commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
grimpy commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594424335
 
 
   @Kami I filled the ICLA where do I send it to?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] codecov-io commented on issue #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#issuecomment-594021101
 
 
   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=h1) Report
   > Merging [#1437](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=desc) into [trunk](https://codecov.io/gh/apache/libcloud/commit/62c9c855f4fb8b409307cdc2f8358dda8f36f58a?src=pr&el=desc) will **increase** coverage by `0.06%`.
   > The diff coverage is `86.53%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1437/graphs/tree.svg?width=650&token=PYoduksh69&height=150&src=pr)](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1437      +/-   ##
   ==========================================
   + Coverage   86.11%   86.17%   +0.06%     
   ==========================================
     Files         370      373       +3     
     Lines       77586    78030     +444     
     Branches     7658     7674      +16     
   ==========================================
   + Hits        66814    67244     +430     
   - Misses       7876     7883       +7     
   - Partials     2896     2903       +7
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [libcloud/compute/providers.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9wcm92aWRlcnMucHk=) | `87.5% <ø> (ø)` | :arrow_up: |
   | [libcloud/test/compute/test\_gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9jb21wdXRlL3Rlc3RfZ2lnX2c4LnB5) | `100% <100%> (ø)` | |
   | [libcloud/compute/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS90eXBlcy5weQ==) | `100% <100%> (+1.11%)` | :arrow_up: |
   | [libcloud/common/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2dpZ19nOC5weQ==) | `100% <100%> (ø)` | |
   | [libcloud/compute/drivers/gig\_g8.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tcHV0ZS9kcml2ZXJzL2dpZ19nOC5weQ==) | `79.71% <79.71%> (ø)` | |
   | [libcloud/common/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL3R5cGVzLnB5) | `97.01% <0%> (-2.99%)` | :arrow_down: |
   | [libcloud/dns/types.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvZG5zL3R5cGVzLnB5) | `100% <0%> (ø)` | :arrow_up: |
   | [libcloud/test/dns/test\_base.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvdGVzdC9kbnMvdGVzdF9iYXNlLnB5) | `100% <0%> (ø)` | :arrow_up: |
   | [libcloud/container/base.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29udGFpbmVyL2Jhc2UucHk=) | `89.06% <0%> (ø)` | :arrow_up: |
   | [libcloud/common/azure.py](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree#diff-bGliY2xvdWQvY29tbW9uL2F6dXJlLnB5) | `84.76% <0%> (ø)` | :arrow_up: |
   | ... and [18 more](https://codecov.io/gh/apache/libcloud/pull/1437/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=footer). Last update [62c9c85...b14aec1](https://codecov.io/gh/apache/libcloud/pull/1437?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r389310690
 
 

 ##########
 File path: libcloud/compute/drivers/gig_g8.py
 ##########
 @@ -0,0 +1,501 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""
+GiG G8 Driver
+
+"""
+import json
+from libcloud.compute.base import NodeImage, NodeSize, Node
+from libcloud.compute.base import NodeDriver, UuidMixin
+from libcloud.compute.base import StorageVolume, NodeAuthSSHKey
+from libcloud.compute.types import Provider, NodeState
+from libcloud.common.gig_g8 import G8Connection
+
+
+class G8PortForward(UuidMixin):
+    def __init__(self, network, node_id, publicport,
+                 privateport, protocol, driver):
+        self.node_id = node_id
+        self.network = network
+        self.publicport = publicport
+        self.privateport = privateport
+        self.protocol = protocol
+        self.driver = driver
+        UuidMixin.__init__(self)
+
+    def destroy(self):
+        self.driver.ex_delete_portforward(self)
+
+
+class G8Network(UuidMixin):
+    """
+    G8 Network object class.
+
+    This class maps to a cloudspace
+
+    """
+
+    def __init__(self, id, name, cidr, publicipaddress, driver, extra=None):
+        self.id = id
+        self.name = name
+        self._cidr = cidr
+        self.driver = driver
+        self.publicipaddress = publicipaddress
+        self.extra = extra
+        UuidMixin.__init__(self)
+
+    @property
+    def cidr(self):
+        """
+        Cidr is not part of the list result
+        we will lazily fetch it with a get request
+        """
+        if self._cidr is None:
+            networkdata = self.driver._api_request("/cloudspaces/get",
+                                                   {"cloudspaceId": self.id})
+            self._cidr = networkdata["privatenetwork"]
+        return self._cidr
+
+    def list_nodes(self):
+        return self.driver.list_nodes(self)
+
+    def destroy(self):
+        return self.driver.ex_destroy_network(self)
+
+    def list_portforwards(self):
+        return self.driver.ex_list_portforwards(self)
+
+    def create_portforward(self, node, publicport,
+                           privateport, protocol='tcp'):
+        return self.driver.ex_create_portforward(self, node, publicport,
+                                                 privateport, protocol)
+
+
+class G8NodeDriver(NodeDriver):
+    """
+    GiG G8 node driver
+
+    """
+
+    NODE_STATE_MAP = {'VIRTUAL': NodeState.PENDING,
+                      'HALTED': NodeState.STOPPED,
+                      'RUNNING': NodeState.RUNNING,
+                      'DESTROYED': NodeState.TERMINATED,
+                      'DELETED': NodeState.TERMINATED,
+                      'PAUSED': NodeState.PAUSED,
+                      'ERROR': NodeState.ERROR,
+
+                      # transition states
+                      'DEPLOYING': NodeState.PENDING,
+                      'STOPPING': NodeState.STOPPING,
+                      'MOVING': NodeState.MIGRATING,
+                      'RESTORING': NodeState.PENDING,
+                      'STARTING': NodeState.STARTING,
+                      'PAUSING': NodeState.PENDING,
+                      'RESUMING': NodeState.PENDING,
+                      'RESETTING': NodeState.REBOOTING,
+                      'DELETING': NodeState.TERMINATED,
+                      'DESTROYING': NodeState.TERMINATED,
+                      'ADDING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_DISK': NodeState.RECONFIGURING,
+                      'DETACHING_DISK': NodeState.RECONFIGURING,
+                      'ATTACHING_NIC': NodeState.RECONFIGURING,
+                      'DETTACHING_NIC': NodeState.RECONFIGURING,
+                      'DELETING_DISK': NodeState.RECONFIGURING,
+                      'CHANGING_DISK_LIMITS': NodeState.RECONFIGURING,
+                      'CLONING': NodeState.PENDING,
+                      'RESIZING': NodeState.RECONFIGURING,
+                      'CREATING_TEMPLATE': NodeState.PENDING,
+                      }
+
+    name = "GiG G8 Node Provider"
+    website = 'https://gig.tech'
+    type = Provider.GIG_G8
+    connectionCls = G8Connection
+
+    def __init__(self, apiurl, token, account_id):
+        """
+        :param  apiurl: G8 api url
+        :type   apiurl: ``str``
+        :param  token: Token to use for api (jwt)
+        :type   token: ``str``
+        :param  account_id: Id of the account to connect to
+        :type   account_id: ``int``
+
+        :rtype: ``None``
+        """
+        self._apiurl = apiurl.rstrip("/")
+        super(G8NodeDriver, self).__init__(key=token)
+        self._account_id = account_id
+        self._location_data = None
+
+    def _ex_connection_class_kwargs(self):
+        return {"url": self._apiurl}
+
+    def _api_request(self, endpoint, params=None):
+        return self.connection.request(endpoint.lstrip("/"),
+                                       data=json.dumps(params),
+                                       method="POST").object
+
+    @property
+    def _location(self):
+        if self._location_data is None:
+            self._location_data = self._api_request("/locations/list")[0]
+        return self._location_data
+
+    def create_node(self, name, size, image, network,
+                    description, auth=None, ex_create_attr=None):
+        """
+        Create a node.
+
+        The `ex_create_attr` parameter can include the following dictionary
+        key and value pairs:
+
+        * `memory`: ``int`` Memory in MiB
+                    (only used if size is None and vcpus is passed
+        * `vcpus`: ``int`` Amount of vcpus
+                   (only used if size is None and memory is passed)
+        * `disk_size`: ``int`` Size of bootdisk
+                       defaults to minimumsize of the image
+        * `user_data`: ``str`` for cloud-config data
+        * `private_ip`: ``str`` Private Ip inside network
+        * `data_disks`: ``list(int)`` Extra data disks to assign
+                        to vm list of disk sizes in GiB
+
+        :param name: the name to assign the vm
+        :type  name: ``str``
+
+        :param size: the plan size to create
+                       mutual exclusive with `memory` `vcpus`
+        :type  size: :class:`NodeSize`
+
+        :param image: which distribution to deploy on the vm
+        :type  image: :class:`NodeImage`
+
+        :param network: G8 Network to place vm in
+        :type  size: :class:`G8Network`
+
+        :param description: Descripton of vm
+        :type  size: : ``str``
+
+        :param auth: an SSH key
+        :type  auth: :class:`NodeAuthSSHKey`
+
+        :param ex_create_attr: A dictionary of optional attributes for
+                                 vm creation
+        :type  ex_create_attr: ``dict``
+
+        :return: The newly created node.
+        :rtype: :class:`Node`
+        """
+        params = {"name": name,
+                  "imageId": int(image.id),
+                  "cloudspaceId": int(network.id),
+                  "description": description}
+
+        ex_create_attr = ex_create_attr or {}
+        if size:
+            params["sizeId"] = int(size.id)
+        else:
+            params["memory"] = ex_create_attr["memory"]
+            params["vcpus"] = ex_create_attr["vcpus"]
+        if "user_data" in ex_create_attr:
+            params["userdata"] = ex_create_attr["user_data"]
+        if "data_disks" in ex_create_attr:
+            params["datadisks"] = ex_create_attr["data_disks"]
+        if "private_ip" in ex_create_attr:
+            params["privateIp"] = ex_create_attr["private_ip"]
+        if "disk_size" in ex_create_attr:
+            params["disksize"] = ex_create_attr["disk_size"]
+        else:
+            params["disksize"] = image.extra["min_disk_size"]
+        if auth and isinstance(auth, NodeAuthSSHKey):
+            userdata = params.get("userdata", {})
+            users = userdata.setdefault("users", [])
+            root = None
+            for user in users:
+                if user["name"] == "root":
+                    root = user
+                    break
+            else:
+                root = {"name": "root", "shell": "/bin/bash"}
+                users.append(root)
+            keys = root.setdefault("ssh-authorized-keys", [])
+            keys.append(auth.pubkey)
+        elif auth:
+            error = "Auth type {} is not implemented".format(type(auth))
+            raise NotImplementedError(error)
+
+        machineId = self._api_request("/machines/create", params)
+        machine = self._api_request("/machines/get",
+                                    params={"machineId": machineId})
+        return self._to_node(machine)
+
+    def ex_create_network(self, name, private_network="192.168.103.0/24",
+                          type="vgw"):
+        """
+        Create network also known as cloudspace
+
+        :param name: the name to assing to the network
+        :type  name: ``str``
+
+        :param private_network: subnet used as private network
+        :type  private_network: ``str``
+
+        :param type: type of the gateway vgw or routeros
+        :type  type: ``str``
+        """
+        userinfo = self._api_request("../system/usermanager/whoami")
+        params = {"accountId": self._account_id,
+                  "privatenetwork": private_network,
+                  "access": userinfo["name"],
+                  "name": name,
+                  "location": self._location["locationCode"],
+                  "type": type}
+        networkid = self._api_request("/cloudspaces/create", params)
+        network = self._api_request("/cloudspaces/get",
+                                    {"cloudspaceId": networkid})
+        return self._to_network(network)
+
+    def ex_destroy_network(self, network):
+        self._api_request("/cloudspaces/delete",
+                          {"cloudspaceId": int(network.id)})
+        return True
+
+    def stop_node(self, node):
+        """
+        Stop virtual machine
+        """
+        node.state = NodeState.STOPPING
+        self._api_request("/machines/stop", {"machineId": int(node.id)})
+        node.state = NodeState.STOPPED
+        return True
+
+    def ex_list_portforwards(self, network):
+        data = self._api_request("/portforwarding/list",
+                                 {"cloudspaceId": int(network.id)})
+        forwards = []
+        for forward in data:
+            forwards.append(self._to_port_forward(forward, network))
+        return forwards
+
+    def ex_create_portforward(self, network, node, publicport,
+                              privateport, protocol="tcp"):
+        params = {"cloudspaceId": int(network.id),
+                  "machineId": int(node.id),
+                  "localPort": privateport,
+                  "publicPort": publicport,
+                  "publicIp": network.publicipaddress,
+                  "protocol": protocol}
+        self._api_request("/portforwarding/create", params)
+        return self._to_port_forward(params, network)
+
+    def ex_delete_portforward(self, portforward):
+        params = {"cloudspaceId": int(portforward.network.id),
+                  "publicIp": portforward.network.publicipaddress,
+                  "publicPort": portforward.publicport,
+                  "proto": portforward.protocol}
+        self._api_request("/portforwarding/deleteByPort", params)
+        return True
+
+    def start_node(self, node):
+        """
+        Start virtual machine
+        """
+        node.state = NodeState.STARTING
+        self._api_request("/machines/start", {"machineId": int(node.id)})
+        node.state = NodeState.RUNNING
+        return True
+
+    def ex_list_networks(self):
+        """
+        Return the list of networks.
+
+        :return: A list of network objects.
+        :rtype: ``list`` of :class:`G8Network`
+        """
+        networks = []
+        for network in self._api_request("/cloudspaces/list"):
+            if network["accountId"] == self._account_id:
+                networks.append(self._to_network(network))
+        return networks
+
+    def list_sizes(self):
+        """
+        Returns a list of node sizes as a cloud provider might have
+
+        """
+        location = self._location["locationCode"]
+
+        sizes = []
+        for size in self._api_request("/sizes/list", {"location": location}):
+            sizes.extend(self._to_size(size))
+        return sizes
+
+    def list_nodes(self, network=None):
+        """
+        List the nodes known to a particular driver;
+        There are two default nodes created at the beginning
+        """
+        if network:
+            networks = [network]
+        else:
+            networks = self.ex_list_networks()
+        nodes = []
+        for network in networks:
+            nodes_list = self._api_request("/machines/list",
+                                           params={"cloudspaceId": network.id})
+            for nodedata in nodes_list:
+                nodes.append(self._to_node(nodedata))
+        return nodes
+
+    def reboot_node(self, node):
+        """
+        Reboot node
+        returns True as if the reboot had been successful.
+        """
+        node.state = NodeState.REBOOTING
+        self._api_request("/machines/reboot", {"machineId": int(node.id)})
+        node.state = NodeState.RUNNING
+        return True
+
+    def destroy_node(self, node):
+        """
+        Destroy node
+        """
+        self._api_request("/machines/delete", {"machineId": int(node.id)})
+        return True
+
+    def list_images(self):
+        """
+        Returns a list of images as a cloud provider might have
+
+        @inherits: :class:`NodeDriver.list_images`
+        """
+        images = []
+        for image in self._api_request("/images/list",
+                                       {"accountId": self._account_id}):
+            images.append(self._to_image(image))
+        return images
+
+    def list_volumes(self):
+        volumes = []
+        for disk in self._api_request("/disks/list",
+                                      {"accountId": self._account_id}):
+            if disk["status"] not in ["ASSIGNED", "CREATED"]:
+                continue
+            volumes.append(self._to_volume(disk))
+        return volumes
+
+    def create_volume(self, size, name, description, disk_type="D"):
 
 Review comment:
   ``description`` and ``disky_type`` arguments are not part of the base API so please prefix them with ``ex_``.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on a change in pull request #1437: Implement g8 provider for libcloud

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1437: Implement g8 provider for libcloud
URL: https://github.com/apache/libcloud/pull/1437#discussion_r394665372
 
 

 ##########
 File path: libcloud/compute/drivers/gig_g8.py
 ##########
 @@ -269,12 +273,14 @@ def ex_create_network(self, name, private_network="192.168.103.0/24",
                                     {"cloudspaceId": networkid})
         return self._to_network(network)
 
-    def ex_destroy_network(self, network):
+    def ex_destroy_network(self, ex_network):
 
 Review comment:
   EDIT: I see you just pushed some more changes so perhaps you can address that and let me know when it's ready and I'll go ahead and merge it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services