def NewFromJsonDict(data): '''Create a new instance base on a JSON dict Args: data: A JSON dict, as converted from the JSON in the kubernetes API Returns: A kubernetes.ReplicationControllerList instance ''' items = None if 'items' in data: from kubernetes import ReplicationController items = [ ReplicationController.NewFromJsonDict(r) for r in data['items'] ] return ReplicationControllerList( Kind=data.get('kind', None), ID=data.get('id', None), UID=data.get('uid', None), CreationTimestamp=data.get('creationTimestamp', None), SelfLink=data.get('selfLink', None), ResourceVersion=data.get('resourceVersion', None), APIVersion=data.get('apiVersion', None), Namespace=data.get('namespace', None), Annotations=data.get('annotations', None), Items=items)
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 GetReplicationController(self, name, namespace='default'): '''Retrieve the specific replicationcontroller on this cluster''' 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) return ReplicationController.NewFromJsonDict(data)
def CreateReplicationController(self, data, namespace='default'): '''Create a new ReplicationController''' url = ('%(base_url)s/namespaces/%(ns)s/replicationcontrollers' % { "base_url": self.base_url, "ns": namespace }) json = self._RequestUrl(url, 'POST', data) if json.status_code is not 201: raise KubernetesError(json.json()['message'], json.status_code) result = self._ParseAndCheckKubernetes(json.content) return ReplicationController.NewFromJsonDict(result)
def NewFromJsonDict(data): '''Create a new instance base on a JSON dict Args: data: A JSON dict, as converted from the JSON in the kubernetes API Returns: A kubernetes.ReplicationController instance ''' desiredState = None currentState = None metadata = data.get('metadata') if 'desiredState' in data: from kubernetes import ReplicationControllerSpec desiredState = ReplicationControllerSpec.NewFromJsonDict( data['desiredState']) if 'currentState' in data: from kubernetes import ReplicationControllerSpec currentState = ReplicationControllerSpec.NewFromJsonDict( data['currentState']) if 'spec' in data: from kubernetes import ReplicationControllerSpec spec = ReplicationControllerSpec.NewFromJsonDict(data['spec']) if spec.Replicas: desiredState = spec.Replicas if 'status' in data and 'replicas' in data['status']: currentState = data['status'].get('replicas') return ReplicationController( Spec=spec, Kind=data.get('kind', None), APIVersion=data.get('apiVersion', None), Name=metadata.get('name', None), UID=metadata.get('uid', None), CreationTimestamp=metadata.get('creationTimestamp', None), SelfLink=metadata.get('selfLink', None), ResourceVersion=metadata.get('resourceVersion', None), Namespace=metadata.get('namespace', None), Annotations=metadata.get('annotations', None), Labels=metadata.get('labels', None), DesiredState=desiredState, CurrentState=currentState)
def NewFromJsonDict(data): '''Create a new instance base on a JSON dict Args: data: A JSON dict, as converted from the JSON in the kubernetes API Returns: A kubernetes.ReplicationController instance ''' desiredState = None currentState = None if 'desiredState' in data: from kubernetes import ReplicationControllerState desiredState = ReplicationControllerState.NewFromJsonDict( data['desiredState']) if 'currentState' in data: from kubernetes import ReplicationControllerState currentState = ReplicationControllerState.NewFromJsonDict( data['currentState']) return ReplicationController(DesiredState=desiredState, CurrentState=currentState, Labels=data.get('labels', None))