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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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)
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)
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)+']'})
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)
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)
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) + ']' })
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)
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) })
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)
def AsJsonString(self): ''' A JSON strint representation of this ServiceSpec instance.''' return simplejson.dumps(dict(self.AsDict().items()), sort_keys=True)
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)