@@ -15,14 +15,34 @@ def __init__(self, client, data, complete=True):
1515 data ['location' ] = BoundLocation (client ._client .locations , location )
1616 super (BoundVolume , self ).__init__ (client , data , complete )
1717
18- def attach (self , server ):
19- # type: (Union[Server, BoundServer]) -> Action
20- return self ._client .attach (server , self )
18+ def get_actions (self , sort = None ):
19+ # type: (Optional[List[str]]) -> List[BoundAction]
20+ return self ._client .get_actions (self , sort )
21+
22+ def update (self , name = None , labels = None ):
23+ # type: (Optional[str], Optional[Dict[str, str]]) -> BoundAction
24+ return self ._client .update (self , name , labels )
25+
26+ def delete (self ):
27+ # type: () -> BoundAction
28+ return self ._client .delete (self )
29+
30+ def attach (self , server , automount = None ):
31+ # type: (Union[Server, BoundServer]) -> BoundAction
32+ return self ._client .attach (self , server , automount )
2133
2234 def detach (self ):
2335 # type: () -> BoundAction
2436 return self ._client .detach (self )
2537
38+ def resize (self , size ):
39+ # type: (int) -> BoundAction
40+ return self ._client .resize (self , size )
41+
42+ def change_protection (self , delete = None ):
43+ # type: (Optional[bool]) -> BoundAction
44+ return self ._client .change_protection (self , delete )
45+
2646
2747class VolumesClient (ClientEntityBase ):
2848
@@ -82,12 +102,55 @@ def create(self,
82102 )
83103 return result
84104
85- def attach (self , server , volume ):
86- # type: (Union[Server, BoundServer], Union[Volume, BoundVolume]) -> Action
87- data = self ._client .request (url = "/volumes/{volume_id}/actions/attach" .format (volume_id = volume .id ), json = {'server' : server .id }, method = "POST" )
105+ def get_actions (self , volume , sort = None ):
106+ # type: (Union[Volume, BoundVolume], Optional[List[str]]) -> List[BoundAction]
107+ params = {}
108+
109+ if sort is not None :
110+ params .update ({"sort" : sort })
111+ response = self ._client .request (url = "/volumes/{volume_id}/actions" .format (volume_id = volume .id ), method = "GET" , params = params )
112+ return [BoundAction (self ._client .actions , action_data ) for action_data in response ['actions' ]]
113+
114+ def update (self , volume , name = None , labels = None ):
115+ # type:(Union[Volume, BoundVolume], Optional[str], Optional[Dict[str, str]]) -> BoundVolume
116+ data = {}
117+ if name is not None :
118+ data .update ({"name" : name })
119+ if labels is not None :
120+ data .update ({"labels" : labels })
121+ response = self ._client .request (url = "/volumes/{volume_id}" .format (volume_id = volume .id ), method = "PUT" , json = data )
122+ return BoundVolume (self , response ['volume' ])
123+
124+ def delete (self , volume ):
125+ # type: (Union[Volume, BoundVolume]) -> BoundAction
126+ self ._client .request (url = "/volumes/{volume_id}" .format (volume_id = volume .id ), method = "DELETE" )
127+ return True
128+
129+ def resize (self , volume , size ):
130+ # type: (Union[Volume, BoundVolume], int) -> BoundAction
131+ data = self ._client .request (url = "/volumes/{volume_id}/actions/resize" .format (volume_id = volume .id ), json = {'size' : size }, method = "POST" )
132+ return BoundAction (self ._client .actions , data ['action' ])
133+
134+ def attach (self , volume , server , automount = None ):
135+ # type: (Union[Volume, BoundVolume], Union[Server, BoundServer], Optional[bool]) -> BoundAction
136+ data = {'server' : server .id }
137+ if automount is not None :
138+ data ["automount" ] = automount
139+
140+ data = self ._client .request (url = "/volumes/{volume_id}/actions/attach" .format (volume_id = volume .id ), json = data , method = "POST" )
88141 return BoundAction (self ._client .actions , data ['action' ])
89142
90143 def detach (self , volume ):
91- # type: (Union[Volume, BoundVolume]) -> Action
144+ # type: (Union[Volume, BoundVolume]) -> BoundAction
92145 data = self ._client .request (url = "/volumes/{volume_id}/actions/detach" .format (volume_id = volume .id ), method = "POST" )
93146 return BoundAction (self ._client .actions , data ['action' ])
147+
148+ def change_protection (self , volume , delete = None ):
149+ # type: (Union[Volume, BoundVolume], Optional[bool], Optional[bool]) -> BoundAction
150+ data = {}
151+ if delete is not None :
152+ data .update ({"delete" : delete })
153+
154+ response = self ._client .request (url = "/volumes/{volume_id}/actions/change_protection" .format (volume_id = volume .id ),
155+ method = "POST" , json = data )
156+ return BoundAction (self ._client .actions , response ['action' ])
0 commit comments