File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from linode_api4 .errors import UnexpectedResponseError
22from linode_api4 .groups import Group
3- from linode_api4 .objects import LongviewClient , LongviewSubscription
3+ from linode_api4 .objects import (
4+ LongviewClient ,
5+ LongviewPlan ,
6+ LongviewSubscription ,
7+ )
48
59
610class LongviewGroup (Group ):
@@ -60,3 +64,40 @@ def subscriptions(self, *filters):
6064 :rtype: PaginatedList of LongviewSubscription
6165 """
6266 return self .client ._get_and_filter (LongviewSubscription , * filters )
67+
68+ def longview_plan_update (self , longview_subscription ):
69+ """
70+ Update your Longview plan to that of the given subcription ID.
71+
72+ :param longview_subscription: The subscription ID for a particular Longview plan.
73+ A value of null corresponds to Longview Free.
74+ :type longview_subscription: str
75+
76+ :returns: The updated Longview Plan
77+ :rtype: LongviewPlan
78+ """
79+
80+ if longview_subscription not in [
81+ "" ,
82+ "longview-3" ,
83+ "longview-10" ,
84+ "longview-40" ,
85+ "longview-100" ,
86+ ]:
87+ raise ValueError (
88+ "Invalid longview plan subscription: {}" .format (
89+ longview_subscription
90+ )
91+ )
92+
93+ params = {"longview_subscription" : longview_subscription }
94+
95+ result = self .client .post (
96+ LongviewPlan .api_endpoint , model = self , data = params
97+ )
98+
99+ plan = LongviewPlan (self .client , result ["id" ], result )
100+
101+ plan .invalidate ()
102+
103+ return plan
Original file line number Diff line number Diff line change @@ -36,3 +36,20 @@ class LongviewSubscription(Base):
3636 "clients_included" : Property (),
3737 "price" : Property (),
3838 }
39+
40+
41+ class LongviewPlan (Base ):
42+ """
43+ The current Longview Plan an account is using.
44+
45+ API Documentation: https://www.linode.com/docs/api/longview/#longview-plan-view
46+ """
47+
48+ api_endpoint = "/longview/plan"
49+
50+ properties = {
51+ "id" : Property (identifier = True ),
52+ "label" : Property (),
53+ "clients_included" : Property (),
54+ "price" : Property (),
55+ }
Original file line number Diff line number Diff line change 1+ {
2+ "clients_included" : 10 ,
3+ "id" : " longview-10" ,
4+ "label" : " Longview Pro 10 pack" ,
5+ "price" : {
6+ "hourly" : 0.06 ,
7+ "monthly" : 40
8+ }
9+ }
Original file line number Diff line number Diff line change @@ -502,6 +502,21 @@ def test_client_create_with_label(self):
502502 self .assertEqual (m .call_url , "/longview/clients" )
503503 self .assertEqual (m .call_data , {"label" : "test_client_1" })
504504
505+ def test_update_plan (self ):
506+ """
507+ Tests that you can submit a correct longview plan update api request
508+ """
509+ with self .mock_post ("/longview/plan" ) as m :
510+ result = self .client .longview .longview_plan_update ("longview-100" )
511+ self .assertEqual (m .call_url , "/longview/plan" )
512+ self .assertEqual (
513+ m .call_data ["longview_subscription" ], "longview-100"
514+ )
515+ self .assertEqual (result .id , "longview-10" )
516+ self .assertEqual (result .clients_included , 10 )
517+ self .assertEqual (result .label , "Longview Pro 10 pack" )
518+ self .assertIsNotNone (result .price )
519+
505520 def test_get_subscriptions (self ):
506521 """
507522 Tests that Longview subscriptions can be retrieved
Original file line number Diff line number Diff line change 11from datetime import datetime
22from test .base import ClientBaseCase
33
4- from linode_api4 .objects import LongviewClient , LongviewSubscription
4+ from linode_api4 .objects import (
5+ LongviewClient ,
6+ LongviewPlan ,
7+ LongviewSubscription ,
8+ )
59from linode_api4 .objects .base import MappedObject
610
711
12+ class LongviewPlanTest (ClientBaseCase ):
13+ """
14+ Tests methods of the LongviewPlan class
15+ """
16+
17+ def test_get_plan (self ):
18+ """
19+ Tests that a plan is loaded correctly
20+ """
21+ plan = LongviewPlan (self .client , "longview-10" )
22+
23+ self .assertEqual (plan .id , "longview-10" )
24+ self .assertEqual (plan .clients_included , 10 )
25+ self .assertEqual (plan .label , "Longview Pro 10 pack" )
26+ self .assertIsNotNone (plan .price )
27+
28+
829class LongviewClientTest (ClientBaseCase ):
930 """
1031 Tests methods of the LongviewClient class
You can’t perform that action at this time.
0 commit comments