Kami commented on a change in pull request #1476:
URL: https://github.com/apache/libcloud/pull/1476#discussion_r479778214



##########
File path: libcloud/compute/drivers/outscale.py
##########
@@ -0,0 +1,1018 @@
+# 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.
+"""
+Outscale SDK
+"""
+
+import json
+
+import requests
+
+from libcloud.compute.base import NodeDriver
+from libcloud.compute.types import Provider
+from libcloud.common.osc import OSCRequestSignerAlgorithmV4
+from libcloud.common.base import ConnectionUserAndKey
+from libcloud.compute.base import \
+    Node,\
+    NodeImage, \
+    KeyPair, \
+    StorageVolume, \
+    VolumeSnapshot, \
+    NodeLocation
+from libcloud.compute.types import NodeState
+
+
+class OutscaleNodeDriver(NodeDriver):
+    """
+    Outscale SDK node driver
+    """
+
+    type = Provider.OUTSCALE
+    name = 'Outscale API'
+    website = 'http://www.outscale.com'
+
+    def __init__(self,
+                 key: str = None,
+                 secret: str = None,
+                 region: str = 'eu-west-2',
+                 service: str = 'api',
+                 version: str = 'latest'
+                 ):
+        self.key = key
+        self.secret = secret
+        self.region = region
+        self.connection = ConnectionUserAndKey(self.key, self.secret)
+        self.connection.region_name = region
+        self.connection.service_name = service
+        self.service_name = service
+        self.version = version
+        self.signer = OSCRequestSignerAlgorithmV4(
+            access_key=self.key,
+            access_secret=self.secret,
+            version=self.version,
+            connection=self.connection
+        )
+        self.NODE_STATE = {
+            'pending': NodeState.PENDING,
+            'running': NodeState.RUNNING,
+            'shutting-down': NodeState.UNKNOWN,
+            'terminated': NodeState.TERMINATED,
+            'stopped': NodeState.STOPPED
+        }
+
+    def list_locations(self, ex_dry_run: bool = False):
+        """
+        Lists available regions details.
+        :param      ex_dry_run: If true, checks whether you have the required
+        permissions to perform the action.
+        :type       ex_dry_run: ``bool``
+        :return: regions details
+        :rtype: ``dict``
+        """
+        action = "ReadRegions"
+        data = json.dumps({"DryRun": ex_dry_run})
+        response = self._call_api(action, data)
+        return self._to_locations(response.json()["Regions"])
+
+    def ex_create_public_ip(self, dry_run: bool = False):
+        """
+        Create a new public ip.
+
+        :param      dry_run: If true, checks whether you have the required
+        permissions to perform the action.
+        :type       dry_run: ``bool``
+
+        :return: the created public ip
+        :rtype: ``dict``
+            """
+        action = "CreatePublicIp"
+        data = json.dumps({"DryRun": dry_run})
+        if self._call_api(action, data).status_code == 200:
+            return True
+        return False
+
+    def ex_delete_public_ip(self,
+                            dry_run: bool = False,
+                            public_ip: str = None,
+                            public_ip_id: str = None):
+        """
+        Delete instances.
+
+        :param      dry_run: If true, checks whether you have the required
+        permissions to perform the action.
+        :type       dry_run: ``bool``
+
+        :param      public_ip: The EIP. In the public Cloud, this parameter is
+        required.
+        :type       public_ip: ``str``
+
+        :param      public_ip_id: The ID representing the association of the
+        EIP with the VM or the NIC. In a Net,
+        this parameter is required.
+        :type       public_ip_id: ``str``
+
+        :return: request
+        :rtype: ``dict``
+        """
+        action = "DeletePublicIp"
+        data = {"DryRun": dry_run}
+        if public_ip is not None:
+            data.update({"PublicIp": public_ip})
+        if public_ip_id is not None:
+            data.update({"PublicIpId": public_ip_id})
+        data = json.dumps(data)
+        if self._call_api(action, data).status_code == 200:
+            return True
+        return False
+
+    def ex_list_public_ips(self, data: str = "{}"):
+        """
+        List all nodes.
+
+        :param      data: json stringify following the outscale api
+        documentation for filter
+        :type       data: ``string``
+
+        :return: nodes
+        :rtype: ``dict``
+        """
+        action = "ReadPublicIps"
+        return self._call_api(action, data)
+
+    def ex_list_public_ip_ranges(self, dry_run: bool = False):
+        """
+        Lists available regions details.
+
+        :param      dry_run: If true, checks whether you have the
+        required permissions to perform the action.
+        :type       dry_run: ``bool``
+
+        :return: regions details
+        :rtype: ``dict``
+        """
+        action = "ReadPublicIpRanges"
+        data = json.dumps({"DryRun": dry_run})
+        return self._call_api(action, data)
+
+    def ex_attach_public_ip(self,
+                            allow_relink: bool = None,
+                            dry_run: bool = False,
+                            nic_id: str = None,
+                            vm_id: str = None,
+                            public_ip: str = None,
+                            public_ip_id: str = None,
+                            ):
+        """
+        Attach a volume.
+
+        :param      allow_relink: If true, allows the EIP to be associated
+        with the VM or NIC that you specify even if
+        it is already associated with another VM or NIC.
+        :type       allow_relink: ``bool``
+
+        :param      dry_run: If true, checks whether you have the required
+        permissions to perform the action.
+        :type       dry_run: ``bool``
+
+        :param      nic_id:(Net only) The ID of the NIC. This parameter is
+        required if the VM has more than one NIC attached. Otherwise,
+        you need to specify the VmId parameter instead.
+        You cannot specify both parameters
+        at the same time.
+        :type       nic_id: ``str``
+
+        :param      vm_id: the ID of the VM
+        :type       nic_id: ``str``
+
+        :param      public_ip: The EIP. In the public Cloud, this parameter
+        is required.
+        :type       public_ip: ``str``
+
+        :param      public_ip_id: The allocation ID of the EIP. In a Net,
+        this parameter is required.
+        :type       public_ip_id: ``str``
+
+        :return: the attached volume
+        :rtype: ``dict``
+        """
+        action = "LinkPublicIp"
+        data = {"DryRun": dry_run}
+        if public_ip is not None:
+            data.update({"PublicIp": public_ip})
+        if public_ip_id is not None:
+            data.update({"PublicIpId": public_ip_id})
+        if nic_id is not None:
+            data.update({"NicId": nic_id})
+        if vm_id is not None:
+            data.update({"VmId": vm_id})
+        if allow_relink is not None:
+            data.update({"AllowRelink": allow_relink})
+        data = json.dumps(data)
+        if self._call_api(action, data).status_code == 200:
+            return True
+        return False
+
+    def ex_detach_public_ip(self,
+                            public_ip: str = None,
+                            link_public_ip_id: str = None,
+                            dry_run: bool = False):
+        """
+        Detach a volume.
+
+        :param      public_ip: (Required in a Net) The ID representing the
+        association of the EIP with the VM or the NIC
+        :type       public_ip: ``str``
+
+        :param      link_public_ip_id: (Required in a Net) The ID
+        representing the association of the EIP with the
+        VM or the NIC.
+        :type       link_public_ip_id: ``str``
+
+        :param      dry_run: If true, checks whether you have the required
+        permissions to perform the action.
+        :type       dry_run: ``bool``
+
+        :return: the attached volume
+        :rtype: ``dict``
+        """
+        action = "UnlinkPublicIp"
+        data = {"DryRun": dry_run}
+        if public_ip is not None:
+            data.update({"PublicIp": public_ip})
+        if link_public_ip_id is not None:
+            data.update({"LinkPublicIpId": link_public_ip_id})
+        data = json.dumps(data)
+        if self._call_api(action, data).status_code == 200:
+            return True
+        return False
+
+    def create_node(self,
+                    ex_image_id: str,
+                    ex_dry_run: bool = False,
+                    ex_block_device_mapping: dict = None,
+                    ex_boot_on_creation: bool = True,
+                    ex_bsu_optimized: bool = True,
+                    ex_client_token: str = None,
+                    ex_deletion_protection: bool = False,
+                    ex_keypair_name: str = None,
+                    ex_max_vms_count: int = None,
+                    ex_min_vms_count: int = None,
+                    ex_nics: dict = None,
+                    ex_performance: str = None,
+                    ex_placement: dict = None,
+                    ex_private_ips: [str] = None,
+                    ex_security_group_ids: [str] = None,
+                    ex_security_groups: [str] = None,
+                    ex_subnet_id: str = None,
+                    ex_user_data: str = None,
+                    ex_vm_initiated_shutdown_behavior: str = None,
+                    ex_vm_type: str = None
+                    ):
+        """
+        Create a new instance.
+
+        :param      ex_image_id: The ID of the OMI used to create the VM.

Review comment:
       That's fine for now, but ideally this method would comply with the 
standard API in the future - this means take name, image and size arguments.
   
   This would make it much easier for users to switch from other providers to 
this one without needing to change much code.




----------------------------------------------------------------
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:
[email protected]


Reply via email to