コード例 #1
0
ファイル: api.py プロジェクト: idevopscloud/python-kubernetes
 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)
コード例 #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)
コード例 #3
0
ファイル: pod.py プロジェクト: pkilambi/python-kubernetes
    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)
コード例 #4
0
ファイル: pod.py プロジェクト: hancockt/python-kubernetes
    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)
コード例 #5
0
ファイル: status.py プロジェクト: hancockt/python-kubernetes
 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)
コード例 #6
0
ファイル: manifest.py プロジェクト: pjs7678/python-kubernetes
	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)
コード例 #7
0
	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)
コード例 #8
0
ファイル: minion.py プロジェクト: pkilambi/python-kubernetes
	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)
コード例 #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)
コード例 #10
0
ファイル: status.py プロジェクト: hancockt/python-kubernetes
 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)
コード例 #11
0
ファイル: pod.py プロジェクト: hancockt/python-kubernetes
    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)
コード例 #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)
コード例 #13
0
ファイル: pod.py プロジェクト: hancockt/python-kubernetes
    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)
コード例 #14
0
ファイル: api.py プロジェクト: idevopscloud/python-kubernetes
    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
コード例 #15
0
ファイル: pod.py プロジェクト: hancockt/python-kubernetes
    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)
コード例 #16
0
ファイル: manifest.py プロジェクト: pjs7678/python-kubernetes
	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)
コード例 #17
0
ファイル: pod.py プロジェクト: pkilambi/python-kubernetes
    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)
コード例 #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)
コード例 #19
0
ファイル: api.py プロジェクト: hancockt/python-kubernetes
    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)+']'})
コード例 #20
0
ファイル: api.py プロジェクト: hancockt/python-kubernetes
    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)
コード例 #21
0
ファイル: api.py プロジェクト: hancockt/python-kubernetes
 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)
コード例 #22
0
ファイル: api.py プロジェクト: idevopscloud/docker-repos
    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) + ']'
            })
コード例 #23
0
ファイル: api.py プロジェクト: idevopscloud/python-kubernetes
    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)
コード例 #24
0
ファイル: api.py プロジェクト: idevopscloud/python-kubernetes
    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)
            })
コード例 #25
0
ファイル: api.py プロジェクト: idevopscloud/python-kubernetes
    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)
コード例 #26
0
ファイル: service.py プロジェクト: hancockt/python-kubernetes
 def AsJsonString(self):
     ''' A JSON strint representation of this ServiceSpec instance.'''
     return simplejson.dumps(dict(self.AsDict().items()), sort_keys=True)
コード例 #27
0
ファイル: service.py プロジェクト: hancockt/python-kubernetes
    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)