Exemplo n.º 1
0
 def ResizeReplicationController(self, name, replicas, namespace='default'):
     '''Update an existing ReplicationController by given data'''
     #retrieve the specific replicationcontroller first
     json = self._HandleReplicationController(name=name,
                                              action='GET',
                                              namespace=namespace)
     if json.status_code == 404:
         #not exit, just return None
         return None
     if json.status_code is not 200:
         raise KubernetesError({
             'message':
             'parsing error [' + simplejson.dumps(json.content) + ']'
         })
     data = self._ParseAndCheckKubernetes(json.content)
     #update the value of replicas, note, for v1beta3 only
     data['spec']['replicas'] = replicas
     json = self._HandleReplicationController(
         name=name,
         action='PUT',
         namespace=namespace,
         data_str=simplejson.dumps(data))
     if json.status_code is not 200:
         raise KubernetesError({
             'message':
             'parsing error [' + simplejson.dumps(json.content) + ']'
         })
     result = self._ParseAndCheckKubernetes(json.content)
     return ReplicationController.NewFromJsonDict(result)
Exemplo n.º 2
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.ReplicationController instance.

        Returns:
          A JSON string representation of this kubernetes.ReplicationController instance.
        '''
        return simplejson.dumps(dict(self.AsDict().items()+super(ReplicationController, self).AsDict().items()), sort_keys=True)
Exemplo n.º 3
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.RestartPolicyOnFailure instance.
	
		Returns:
		  A JSON string representation of this kubernetes.RestartPolicyOnFailure instance.
		'''
        return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 4
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.RestartPolicyOnFailure instance.

        Returns:
          A JSON string representation of this kubernetes.RestartPolicyOnFailure instance.
        '''
        return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 5
0
 def AsJsonString(self):
     """A JSON string representation of this kubernetes.Status instance.
 
     Returns:
       A JSON string representation of this kubernetes.Status instance.
     """
     return simplejson.dumps(dict(self.AsDict().items() + super(Status, self).AsDict().items()), sort_keys=True)
Exemplo n.º 6
0
	def AsJsonString(self):
		'''A JSON string representation of this kubernetes.BoundPods instance.
	
		Returns:
		  A JSON string representation of this kubernetes.BoundPods instance.
		'''
		return simplejson.dumps(dict(self.AsDict().items()+super(BoundPods, self).AsDict().items()), sort_keys=True)
	def AsJsonString(self):
		'''A JSON string representation of this kubernetes.ContainerStateTerminated instance.
	
		Returns:
		  A JSON string representation of this kubernetes.ContainerStateTerminated instance.
		'''
		return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 8
0
	def AsJsonString(self):
		'''A JSON string representation of this kubernetes.NodeResources instance.
	
		Returns:
		  A JSON string representation of this kubernetes.NodeResources instance.
		'''
		return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 9
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.BoundPods instance.

        Returns:
          A JSON string representation of this kubernetes.BoundPods instance.
        '''
        return simplejson.dumps(dict(self.AsDict().items()+super(BoundPods, self).AsDict().items()), sort_keys=True)
Exemplo n.º 10
0
 def AsJsonString(self):
     """A JSON string representation of this kubernetes.StatusCause instance.
 
     Returns:
       A JSON string representation of this kubernetes.StatusCause instance.
     """
     return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 11
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.PodTemplate instance.

        Returns:
          A JSON string representation of this kubernetes.PodTemplate instance.
        '''
        return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 12
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.ContainerManifestList instance.

        Returns:
          A JSON string representation of this kubernetes.ContainerManifestList instance.
        '''
        return simplejson.dumps(dict(self.AsDict().items()+super(ContainerManifestList, self).AsDict().items()), sort_keys=True)
Exemplo n.º 13
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.ReplicationControllerSpec instance.

        Returns:
          A JSON string representation of this kubernetes.ReplicationControllerSpec instance.
        '''
        return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 14
0
    def RemoveLabel(self,
                    resource_type,
                    resource_name,
                    label_list,
                    namespace=None):
        '''
        If the label already exists in the resource, its value will be replaced by new value.
        If the label does not exist in the resource, the label will be added.
        '''

        url = None
        if resource_type == ResourceType.Node:
            # Make and send requests
            url = ('%(base_url)s/nodes/%(node_name)s' % {
                "base_url": self.base_url,
                "node_name": resource_name
            })
            data = list()
            for label in label_list:
                data.append({
                    'op': 'remove',
                    'path': '/metadata/labels/' + label
                })
            reply = self._RequestUrl(
                url, 'PATCH', json.dumps(data),
                {'Content-Type': 'application/json-patch+json'})
            if reply.status_code is not 200:
                raise KubernetesError({
                    'message':
                    'parsing error [' + simplejson.dumps(reply.content) + ']'
                })
        else:
            raise ReqNotSupported
Exemplo n.º 15
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.ReplicationController instance.

        Returns:
          A JSON string representation of this kubernetes.ReplicationController instance.
        '''
        return simplejson.dumps(dict(self.AsDict().items()+super(ReplicationController, self).AsDict().items()), sort_keys=True)
Exemplo n.º 16
0
	def AsJsonString(self):
		'''A JSON string representation of this kubernetes.ContainerManifest instance.
	
		Returns:
		  A JSON string representation of this kubernetes.ContainerManifest instance.
		'''
		return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 17
0
    def AsJsonString(self):
        '''A JSON string representation of this kubernetes.ReplicationControllerState instance.
	
		Returns:
		  A JSON string representation of this kubernetes.ReplicationControllerState instance.
		'''
        return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 18
0
	def AsJsonString(self):
		'''A JSON string representation of this kubernetes.GCEPersistentDisk instance.
	
		Returns:
		  A JSON string representation of this kubernetes.GCEPersistentDisk instance.
		'''
		return simplejson.dumps(self.AsDict(), sort_keys=True)
Exemplo n.º 19
0
    def DeleteReplicationController(self, name, namespace='default'):
        '''Delete a new Service'''

        url = ('%(base_url)s/namespaces/%(ns)s/replicationcontrollers/%(name)s' %
               {"base_url":self.base_url, "ns":namespace, "name":name})
        json = self._RequestUrl(url, 'DELETE')
        if json.status_code not in [200, 404]:
            raise KubernetesError({'message': 'parsing error ['+simplejson.dumps(json.content)+']'})
Exemplo n.º 20
0
    def CreatePod(self, data, namespace='default'):
        '''Create a new Pod'''

        url = ('%(base_url)s/namespaces/%(ns)s/pods' %
               {"base_url":self.base_url, "ns":namespace})
        json = self._RequestUrl(url, 'PUT', data)
        if json.status_code is not 201:
            raise KubernetesError({'message': 'parsing error ['+simplejson.dumps(json.content)+']'})
        result = self._ParseAndCheckKubernetes(json.content)
        return Pod.NewFromJsonDict(result)
Exemplo n.º 21
0
 def ResizeReplicationController(self, name, replicas, namespace='default'):
     '''Update an existing ReplicationController by given data'''
     #retrieve the specific replicationcontroller first
     json = self._HandleReplicationController(name=name,
                                              action='GET',
                                              namespace=namespace)
     if json.status_code == 404:
         #not exit, just return None
         return None
     data = self._ParseAndCheckKubernetes(json.content)
     #update the value of replicas, note, for v1beta3 only
     data['spec']['replicas']=replicas
     json = self._HandleReplicationController(name=name,
                                              action='PUT',
                                              namespace=namespace,
                                              data_str=simplejson.dumps(data))
     if json.status_code is not 200:
         raise KubernetesError({'message': 'parsing error ['+simplejson.dumps(json.content)+']'})
     result = self._ParseAndCheckKubernetes(json.content)
     return ReplicationController.NewFromJsonDict(result)
Exemplo n.º 22
0
    def DeleteService(self, name, namespace='default'):
        '''Delete a new Service'''

        url = ('%(base_url)s/namespaces/%(ns)s/services/%(name)s' % {
            "base_url": self.base_url,
            "ns": namespace,
            "name": name
        })
        json = self._RequestUrl(url, 'DELETE')
        if json.status_code not in [200, 404]:
            raise KubernetesError({
                'message':
                'parsing error [' + simplejson.dumps(json.content) + ']'
            })
Exemplo n.º 23
0
    def CreatePod(self, data, namespace='default'):
        '''Create a new Pod'''

        url = ('%(base_url)s/namespaces/%(ns)s/pods' % {
            "base_url": self.base_url,
            "ns": namespace
        })
        json = self._RequestUrl(url, 'PUT', data)
        if json.status_code is not 201:
            raise KubernetesError({
                'message':
                'parsing error [' + simplejson.dumps(json.content) + ']'
            })
        result = self._ParseAndCheckKubernetes(json.content)
        return Pod.NewFromJsonDict(result)
Exemplo n.º 24
0
    def DeletePods(self, name, namespace='default'):
        '''Delete a new Pod'''

        url = ('%(base_url)s/namespaces/%(ns)s/pods/%(name)s' % {
            "base_url": self.base_url,
            "ns": namespace,
            "name": name
        })
        json = self._RequestUrl(url, 'DELETE')
        if json.status_code not in [200, 404]:
            raise KubernetesError({
                'message':
                'parsing error [' + simplejson.dumps(json.content) + ']'
            })
        if json.status_code == 404:
            raise KubernetesError({
                'message':
                'can not find the pod <{0}> in namespace <{1}>'.format(
                    name, namespace)
            })
Exemplo n.º 25
0
    def SetNodeSchedulable(self, node_name, is_scheduable=True):
        ''' Make the node as unscheduable '''

        # Make and send requests
        url = ('%(base_url)s/nodes/%(node_name)s' % {
            "base_url": self.base_url,
            "node_name": node_name
        })

        if is_scheduable:
            data = '{"spec":{"unschedulable":false}}'
        else:
            data = '{"spec":{"unschedulable":true}}'

        json = self._RequestUrl(url, 'PATCH', data)
        if json.status_code is not 200:
            raise KubernetesError({
                'message':
                'parsing error [' + simplejson.dumps(json.content) + ']'
            })
        result = self._ParseAndCheckKubernetes(json.content)
        return Pod.NewFromJsonDict(result)
Exemplo n.º 26
0
 def AsJsonString(self):
     ''' A JSON strint representation of this ServiceSpec instance.'''
     return simplejson.dumps(dict(self.AsDict().items()), sort_keys=True)
Exemplo n.º 27
0
    def AsJsonString(self):
#        return simplejson.dumps(dict(self.AsDict().items()+super(Service, self).As_Dict().items()), sort_keys=True)
        return simplejson.dumps(dict(self.AsDict().items()), sort_keys=True)