@@ -37,29 +37,111 @@ def __init__(self, client, ordering_manager=None):
3737 if ordering_manager is None :
3838 self .ordering_manager = ordering .OrderingManager (client )
3939
40- def cancel_host (self , host_id , immediate = True ):
41- """Cancels a dedicated host server.
42-
43- Example::
44- # Cancels dedicated host id 1234
45- result = mgr.cancel_host(host_id=1234)
40+ def cancel_host (self , host_id ):
41+ """Cancel a dedicated host immediately, it fails if there are still guests in the host.
4642
4743 :param host_id: The ID of the dedicated host to be cancelled.
48- :param immediate: If False the dedicated host will be reclaimed in the anniversary date.
49- Default is True
5044 :return: True on success or an exception
45+
46+ Example::
47+ # Cancels dedicated host id 12345
48+ result = mgr.cancel_host(12345)
49+
5150 """
52- mask = 'mask[id,billingItem[id,hourlyFlag]]'
53- host_billing = self .get_host (host_id , mask = mask )
54- billing_id = host_billing ['billingItem' ]['id' ]
55- is_hourly = host_billing ['billingItem' ]['hourlyFlag' ]
51+ return self .host .deleteObject (id = host_id )
5652
57- if is_hourly and immediate is False :
58- raise SoftLayer .SoftLayerError ("Hourly Dedicated Hosts can only be cancelled immediately." )
59- else :
60- # Monthly dedicated host can be reclaimed immediately and no reasons are required
61- result = self .client ['Billing_Item' ].cancelItem (immediate , False , id = billing_id )
62- return result
53+ def list_guests (self , host_id , tags = None , cpus = None , memory = None , hostname = None ,
54+ domain = None , local_disk = None , nic_speed = None , public_ip = None ,
55+ private_ip = None , ** kwargs ):
56+ """Retrieve a list of all virtual servers on the dedicated host.
57+
58+ Example::
59+
60+ # Print out a list of hourly instances in the host id 12345.
61+
62+ for vsi in mgr.list_guests(host_id=12345, hourly=True):
63+ print vsi['fullyQualifiedDomainName'], vsi['primaryIpAddress']
64+
65+ # Using a custom object-mask. Will get ONLY what is specified
66+ object_mask = "mask[hostname,monitoringRobot[robotStatus]]"
67+ for vsi in mgr.list_guests(mask=object_mask,hourly=True):
68+ print vsi
69+
70+ :param integer host_id: the identifier of dedicated host
71+ :param boolean hourly: include hourly instances
72+ :param boolean monthly: include monthly instances
73+ :param list tags: filter based on list of tags
74+ :param integer cpus: filter based on number of CPUS
75+ :param integer memory: filter based on amount of memory
76+ :param string hostname: filter based on hostname
77+ :param string domain: filter based on domain
78+ :param string local_disk: filter based on local_disk
79+ :param integer nic_speed: filter based on network speed (in MBPS)
80+ :param string public_ip: filter based on public ip address
81+ :param string private_ip: filter based on private ip address
82+ :param dict \\ *\\ *kwargs: response-level options (mask, limit, etc.)
83+ :returns: Returns a list of dictionaries representing the matching
84+ virtual servers
85+ """
86+ if 'mask' not in kwargs :
87+ items = [
88+ 'id' ,
89+ 'globalIdentifier' ,
90+ 'hostname' ,
91+ 'domain' ,
92+ 'fullyQualifiedDomainName' ,
93+ 'primaryBackendIpAddress' ,
94+ 'primaryIpAddress' ,
95+ 'lastKnownPowerState.name' ,
96+ 'hourlyBillingFlag' ,
97+ 'powerState' ,
98+ 'maxCpu' ,
99+ 'maxMemory' ,
100+ 'datacenter' ,
101+ 'activeTransaction.transactionStatus[friendlyName,name]' ,
102+ 'status' ,
103+ ]
104+ kwargs ['mask' ] = "mask[%s]" % ',' .join (items )
105+
106+ _filter = utils .NestedDict (kwargs .get ('filter' ) or {})
107+
108+ if tags :
109+ _filter ['guests' ]['tagReferences' ]['tag' ]['name' ] = {
110+ 'operation' : 'in' ,
111+ 'options' : [{'name' : 'data' , 'value' : tags }],
112+ }
113+
114+ if cpus :
115+ _filter ['guests' ]['maxCpu' ] = utils .query_filter (cpus )
116+
117+ if memory :
118+ _filter ['guests' ]['maxMemory' ] = utils .query_filter (memory )
119+
120+ if hostname :
121+ _filter ['guests' ]['hostname' ] = utils .query_filter (hostname )
122+
123+ if domain :
124+ _filter ['guests' ]['domain' ] = utils .query_filter (domain )
125+
126+ if local_disk is not None :
127+ _filter ['guests' ]['localDiskFlag' ] = (
128+ utils .query_filter (bool (local_disk )))
129+
130+ if nic_speed :
131+ _filter ['guests' ]['networkComponents' ]['maxSpeed' ] = (
132+ utils .query_filter (nic_speed ))
133+
134+ if public_ip :
135+ _filter ['guests' ]['primaryIpAddress' ] = (
136+ utils .query_filter (public_ip ))
137+
138+ if private_ip :
139+ _filter ['guests' ]['primaryBackendIpAddress' ] = (
140+ utils .query_filter (private_ip ))
141+
142+ kwargs ['filter' ] = _filter .to_dict ()
143+ kwargs ['iter' ] = True
144+ return self .host .getGuests (id = host_id , ** kwargs )
63145
64146 def list_instances (self , tags = None , cpus = None , memory = None , hostname = None ,
65147 disk = None , datacenter = None , ** kwargs ):
0 commit comments