'''
    Cloudforms.VSManager
    ~~~~~~~~~~~~
    VS Manager (abstracts virtual machines and cloud instances)
    :license: MIT, see LICENSE for more details.
'''
from Cloudforms.utils import update_params


class VSManager(object):
    '''Manages Virtual Servers.

    :param Cloudforms.API.Client client: an API client instance
    Example::

        import Cloudforms
        client = Cloudforms.Client()
        vs_mgr = Cloudforms.VSManager(client)
    '''
    def __init__(self, client):
        self.client = client

    def get_instance(self, params=None):
        '''Retrieve details about a virtual server on the account
        :param dict params: response-level options (attributes, limit, etc.)
        :returns: Returns a dictionary representing the matching virtual server
        Example::
            # Gets a list of all virtual server instances (returns IDs only)
            instances = vs_mgr.list_instances({'attributes': 'id'})
            for instance in instances:
                vs_details = vs_mgr.get_instance(instance['id'])
        '''
        params = update_params(params, {'expand': 'resources'})
        return self.client.call('get', '/vms', params=params)

    def list_instances(self, params=None):
        '''Retrieve a list of all virtual servers on the account
        :param dict params: response-level options (attributes, limit, etc.)
        :returns: Returns a list of dictionaries representing the matching
        virtual server
        Example::
            # Gets a list of all virtual server instances (returns IDs only)
            instances = vs_mgr.list_instances({'attributes': 'id'})
        '''
        params = update_params(params, {'expand': 'resources'})
        return self.client.call('get', '/vms', params=params)

    def perform_action(self, _id, action, params=None):
        '''Sends a request to perform an action on a virtual server
        :param string _id: Specifies which virtual server the request is for
        :param string action: The action to request (start, stop, suspend, etc.)
        :param dict params: Additional POST request data
        :returns: Returns a task request dictionary (see TaskManager)
        Example::
            # Gets a list of all virtual server instances
            for vsi in vs_mgr.list_instances():
                # Send requests to start all virtual server instances
                vs_mgr.perform_action(vsi['id'], 'start')
        '''
        params = update_params(params, {'action': action})
        return self.client.call('post', '/vms/%s' % _id, data=params)

    def start_instance(self, _id, params=None):
        '''Sends a request to start a virtual server
        :param string _id: Specifies which virtual server the request is for
        :param dict params: Additional POST request data
        :returns: Returns a task request dictionary (see TaskManager)
        Example::
            # Gets a list of all virtual server instances
            for vsi in vs_mgr.list_instances():
                # Send requests to start all virtual server instances
                vs_mgr.start_instance(vsi['id'])
        '''
        return self.perform_action(_id, 'start', params)

    def stop_instance(self, _id, params=None):
        '''Sends a request to stop a virtual server
        :param string _id: Specifies which virtual server the request is for
        :param dict params: Additional POST request data
        :returns: Returns a task request dictionary (see TaskManager)
        Example::
            # Gets a list of all virtual server instances
            for vsi in vs_mgr.list_instances():
                # Send requests to stop all virtual server instances
                vs_mgr.stop_instance(vsi['id'])
        '''
        return self.perform_action(_id, 'stop', params)

    def suspend_instance(self, _id, params=None):
        '''Sends a request to suspend a virtual server
        :param string _id: Specifies which virtual server the request is for
        :param dict params: Additional POST request data
        :returns: Returns a task request dictionary (see TaskManager)
        Example::
            # Gets a list of all virtual server instances
            for vsi in vs_mgr.list_instances():
                # Send requests to suspend all virtual server instances
                vs_mgr.suspend_instance(vsi['id'])
        '''
        return self.perform_action(_id, 'suspend', params)

    def delete_instance(self, _id, params=None):
        '''Sends a request to delete a virtual server
        :param string _id: Specifies which virtual server the request is for
        :param dict params: Additional POST request data
        :returns: Returns a task request dictionary (see TaskManager)
        Example::
            # Gets a list of all virtual server instances
            for vsi in vs_mgr.list_instances():
                # Send requests to delete all virtual server instances
                vs_mgr.delete_instance(vsi['id'])
        '''
        return self.perform_action(_id, 'delete', params)

@@ -38,16 +38,24 @@
 ~~~~~~~~
+~~~~~~~~
 %0A    VS 
@@ -111,16 +111,17 @@
 tances)%0A
+%0A
     :lic
@@ -332,16 +332,17 @@
 nstance%0A
+%0A
     Exam
@@ -626,32 +626,33 @@
  on the account%0A
+%0A
         :param d
@@ -784,32 +784,33 @@
  virtual server%0A
+%0A
         Example:
@@ -803,32 +803,33 @@
       Example::%0A
+%0A
             # Ge
@@ -1308,16 +1308,17 @@
 account%0A
+%0A
         
@@ -1461,16 +1461,26 @@
 atching%0A
+          
         
@@ -1486,32 +1486,33 @@
  virtual server%0A
+%0A
         Example:
@@ -1505,32 +1505,33 @@
       Example::%0A
+%0A
             # Ge
@@ -1914,32 +1914,33 @@
  virtual server%0A
+%0A
         :param s
@@ -2200,32 +2200,33 @@
 ee TaskManager)%0A
+%0A
         Example:
@@ -2219,32 +2219,33 @@
       Example::%0A
+%0A
             # Ge
@@ -2697,32 +2697,33 @@
  virtual server%0A
+%0A
         :param s
@@ -2902,32 +2902,33 @@
 ee TaskManager)%0A
+%0A
         Example:
@@ -2921,32 +2921,33 @@
       Example::%0A
+%0A
             # Ge
@@ -3316,32 +3316,33 @@
  virtual server%0A
+%0A
         :param s
@@ -3521,32 +3521,33 @@
 ee TaskManager)%0A
+%0A
         Example:
@@ -3540,32 +3540,33 @@
       Example::%0A
+%0A
             # Ge
@@ -3938,32 +3938,33 @@
  virtual server%0A
+%0A
         :param s
@@ -4143,32 +4143,33 @@
 ee TaskManager)%0A
+%0A
         Example:
@@ -4162,32 +4162,33 @@
       Example::%0A
+%0A
             # Ge
@@ -4575,16 +4575,17 @@
  server%0A
+%0A
         
@@ -4780,16 +4780,17 @@
 anager)%0A
+%0A
         
@@ -4799,16 +4799,17 @@
 ample::%0A
+%0A
         

Comment styling updates