Ejemplo n.º 1
0
 def stop(self):
     check_version(self.parent_model.oc_address, self.parent_model.token,
                   '16.01')
     request(self.parent_model.oc_address, '/api/dhcp/stop/', {
         'token': self.parent_model.token,
         'network_id': self.parent_model.id
     }, self.parent_model.debug)
Ejemplo n.º 2
0
 def lease_list(self):
     '''
     List leases inside this network
     '''
     check_version(self.oc_address, self.token, '1.3')
     leases = request(self.oc_address, '/api/lease/get_list/', {'token': self.token}, self.debug)
     return [Lease(self.oc_address, self.token, lease, self.debug) for lease in leases]
Ejemplo n.º 3
0
 def start(self, gateway_ip):
     check_version(self.parent_model.oc_address, self.parent_model.token,
                   '16.01')
     request(
         self.parent_model.oc_address, '/api/dhcp/start/', {
             'token': self.parent_model.token,
             'network_id': self.parent_model.id,
             'gateway_ip': gateway_ip
         }, self.parent_model.debug)
Ejemplo n.º 4
0
    def lease_by_address(self, network_id, address):
        '''
        Get lease from selected by network_id network with given address
        '''
        check_version(self.oc_address, self.token, '1.3')

        leases = request(self.oc_address, '/api/lease/get_list/', {'token': self.token}, self.debug)
        for l in leases:
            if l['address'] == address and l['network_id'] == network_id:
                return Lease(self.oc_address, self.token, l, self.debug)
Ejemplo n.º 5
0
 def lease_create(self, address):
     """
     Create new lease in network
     """
     check_version(self.oc_address, self.token, '1.3')
     l_dict = request(self.oc_address, '/api/lease/create/', {
         'token': self.token,
         'address': str(address),
         'network_id': self.id
     }, self.debug)
     return Lease(self.oc_address, self.token, l_dict, self.debug)
Ejemplo n.º 6
0
 def delete(self):
     try:
         check_version(self.oc_address, self.token, '15.12')
         request(self.oc_address, '/api/userdata/delete/', {
             'token': self.token,
             'userdata_id': self.id
         }, self.debug)
     except VersionException:
         request(self.oc_address, '/coreTalk/userdata/delete/', {
             'token': self.token,
             'userdata_id': self.id
         }, self.debug)
Ejemplo n.º 7
0
 def attach(self, vm):
     try:
         check_version(self.oc_address, self.token, '15.12')
         request(self.oc_address, '/api/userdata/attach/', {
             'token': self.token,
             'userdata_id': self.id,
             'vm_id': vm.id
         }, self.debug)
     except VersionException:
         request(self.oc_address, '/coreTalk/userdata/attach/', {
             'token': self.token,
             'userdata_id': self.id,
             'vm_id': vm.id
         }, self.debug)
Ejemplo n.º 8
0
 def userdata_list(self):
     """
     List user data objects from cloud
     :return: list of userdata objects
     """
     try:
         check_version(self.parent_model.oc_address, self.parent_model.token, '15.12')
         resp = request(self.parent_model.oc_address, '/api/userdata/get_list/', {'token': self.parent_model.token})
     except VersionException:
         resp = request(self.parent_model.oc_address,
                        '/coreTalk/userdata/get_list/',
                        {'token': self.parent_model.token})
     return [pycore.extensions.coretalk.models.userdata.UserData(self.parent_model.oc_address,
                                                                 self.parent_model.token, ud) for ud in resp]
Ejemplo n.º 9
0
    def userdata_by_id(self, id):
        try:
            check_version(self.parent_model.oc_address, self.parent_model.token, '15.12')
            resp = request(self.parent_model.oc_address,
                           '/api/userdata/get_by_id/',
                           {'token': self.parent_model.token, 'userdata_id': id})
        except VersionException:
            resp = request(self.parent_model.oc_address,
                           '/coreTalk/userdata/get_by_id/',
                           {'token': self.parent_model.token, 'userdata_id': id})

        return pycore.extensions.coretalk.models.userdata.UserData(self.parent_model.oc_address,
                                                                   self.parent_model.token,
                                                                   resp, self.parent_model.debug)
Ejemplo n.º 10
0
    def lease_list(self):
        """
        List leases inside this network
        :return: List of Lease objects
        """
        check_version(self.oc_address, self.token, '1.3')
        leases = request(self.oc_address, '/api/lease/get_list/', {
            'token': self.token,
            'network_id': self.id
        }, self.debug)

        return [
            Lease(self.oc_address, self.token, lease, self.debug)
            for lease in leases
        ]
Ejemplo n.º 11
0
 def userdata_create(self, name, data, convert_from=None):
     try:
         check_version(self.parent_model.oc_address, self.parent_model.token, '15.12')
         resp = request(self.parent_model.oc_address,
                        '/api/userdata/create/',
                        {'token': self.parent_model.token,
                         'name': name,
                         'data': data,
                         'convert_from': convert_from})
     except VersionException:
         resp = request(self.parent_model.oc_address,
                        '/coreTalk/userdata/create/',
                        {'token': self.parent_model.token,
                         'name': name,
                         'data': data})
     return pycore.extensions.coretalk.models.userdata.UserData(self.parent_model.oc_address,
                                                                self.parent_model.token,
                                                                resp)
Ejemplo n.º 12
0
    def edit(self, **kwargs):
        for key in kwargs.keys():
            if hasattr(self, key):
                setattr(self, key, kwargs[key])
                try:
                    check_version(self.oc_address, self.token, '15.12')
                    request(
                        self.oc_address, '/api/userdata/edit/', {
                            'token': self.token,
                            'userdata_id': self.id,
                            key: kwargs[key]
                        }, self.debug)

                except VersionException:
                    request(
                        self.oc_address, '/coreTalk/userdata/edit/', {
                            'token': self.token,
                            'userdata_id': self.id,
                            key: kwargs[key]
                        }, self.debug)
Ejemplo n.º 13
0
 def storage_capabilities(self):
     check_version(self.oc_address, self.token, '15.08')
     return request(self.oc_address, '/api/storage/capabilities/', {'token': self.token}, self.debug)
Ejemplo n.º 14
0
 def resize_image(self, size):
     check_version(self.oc_address, self.token, '16.11')
     request(self.oc_address, '/api/vm/resize/', {'token': self.token,
                                                  'vm_id': self.id,
                                                  'size': size}, self.debug)