From eb98445107dfe350ff3b7be78ec0cc8baf06f174 Mon Sep 17 00:00:00 2001 From: Juan Carlos Moreno Date: Fri, 12 Apr 2013 17:01:03 +0300 Subject: [PATCH 1/3] Update linode.py --- libcloud/common/linode.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libcloud/common/linode.py b/libcloud/common/linode.py index a490af3020..8b3c409b5b 100644 --- a/libcloud/common/linode.py +++ b/libcloud/common/linode.py @@ -31,19 +31,6 @@ API_HOST = 'api.linode.com' API_ROOT = '/' -# Constants that map a RAM figure to a PlanID (updated 6/28/10) -LINODE_PLAN_IDS = {512: '1', - 768: '2', - 1024: '3', - 1536: '4', - 2048: '5', - 4096: '6', - 8192: '7', - 12288: '8', - 16384: '9', - 20480: '10'} - - class LinodeException(Exception): """Error originating from the Linode API From 0b2642ecf8e57e0af82215ffa3b8bfc787af7e81 Mon Sep 17 00:00:00 2001 From: Juan Carlos Moreno Date: Fri, 12 Apr 2013 17:09:47 +0300 Subject: [PATCH 2/3] Update linode.py Linode Driver: Not use plan ids constant, fetch updated plan ids --- libcloud/compute/drivers/linode.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libcloud/compute/drivers/linode.py b/libcloud/compute/drivers/linode.py index 786fde32aa..385597a4d0 100644 --- a/libcloud/compute/drivers/linode.py +++ b/libcloud/compute/drivers/linode.py @@ -73,7 +73,6 @@ class LinodeNodeDriver(NodeDriver): name = "Linode" website = 'http://www.linode.com/' connectionCls = LinodeConnection - _linode_plan_ids = LINODE_PLAN_IDS def __init__(self, key): """Instantiate the driver with the given API key @@ -84,6 +83,7 @@ def __init__(self, key): @rtype: C{None} """ self.datacenter = None + self.plan_ids = None NodeDriver.__init__(self, key) # Converts Linode's state from DB to a NodeState constant. @@ -470,6 +470,15 @@ def linode_set_datacenter(self, dc): dcs = ", ".join([d["DATACENTERID"] for d in data]) self.datacenter = None raise LinodeException(0xFD, "Invalid datacenter (use one of %s)" % dcs) + + def _get_plan_id_by_ram(self, ram): + if not self.plan_ids: + self.plan_ids = self.list_sizes() + + for plan in self.plan_ids: + if plan.ram == ram: + return plan.id + return 0 def _to_nodes(self, objs): """Convert returned JSON Linodes into Node instances @@ -488,7 +497,7 @@ def _to_nodes(self, objs): state=self.LINODE_STATES[o["STATUS"]], driver=self.connection.driver) n.extra = copy(o) - n.extra["PLANID"] = self._linode_plan_ids.get(o.get("TOTALRAM")) + n.extra["PLANID"] = self._get_plan_id_by_ram(o.get("TOTALRAM")) batch.append({"api_action": "linode.ip.list", "LinodeID": lid}) # Avoid batch limitation From c2eee0864a25f672f8140b64f01525d825f5781a Mon Sep 17 00:00:00 2001 From: Juan Carlos Moreno Date: Fri, 12 Apr 2013 17:17:58 +0300 Subject: [PATCH 3/3] Update linode.py upps, foget to remove import --- libcloud/compute/drivers/linode.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcloud/compute/drivers/linode.py b/libcloud/compute/drivers/linode.py index 385597a4d0..96dcf91e42 100644 --- a/libcloud/compute/drivers/linode.py +++ b/libcloud/compute/drivers/linode.py @@ -41,8 +41,7 @@ from libcloud.utils.py3 import PY3 -from libcloud.common.linode import (API_ROOT, LinodeException, - LinodeConnection, LINODE_PLAN_IDS) +from libcloud.common.linode import (API_ROOT, LinodeException, LinodeConnection) from libcloud.compute.types import Provider, NodeState from libcloud.compute.base import NodeDriver, NodeSize, Node, NodeLocation from libcloud.compute.base import NodeAuthPassword, NodeAuthSSHKey