Merge pull request #1484 from derwolfe/ssm-send-command

Add support for SSM send_command
This commit is contained in:
Steve Pulec 2018-03-07 07:37:44 -05:00 committed by GitHub
commit d37c355bd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 0 deletions

View file

@ -5,7 +5,9 @@ from collections import defaultdict
from moto.core import BaseBackend, BaseModel
from moto.ec2 import ec2_backends
import datetime
import time
import uuid
class Parameter(BaseModel):
@ -138,6 +140,39 @@ class SimpleSystemManagerBackend(BaseBackend):
def list_tags_for_resource(self, resource_type, resource_id):
return self._resource_tags[resource_type][resource_id]
def send_command(self, **kwargs):
instances = kwargs['InstanceIds']
now = datetime.datetime.now()
expires_after = now + datetime.timedelta(0, int(kwargs['TimeoutSeconds']))
return {
'Command': {
'CommandId': str(uuid.uuid4()),
'DocumentName': kwargs['DocumentName'],
'Comment': kwargs.get('Comment'),
'ExpiresAfter': expires_after.isoformat(),
'Parameters': kwargs['Parameters'],
'InstanceIds': kwargs['InstanceIds'],
'Targets': kwargs.get('targets'),
'RequestedDateTime': now.isoformat(),
'Status': 'Success',
'StatusDetails': 'string',
'OutputS3Region': kwargs.get('OutputS3Region'),
'OutputS3BucketName': kwargs.get('OutputS3BucketName'),
'OutputS3KeyPrefix': kwargs.get('OutputS3KeyPrefix'),
'MaxConcurrency': 'string',
'MaxErrors': 'string',
'TargetCount': len(instances),
'CompletedCount': len(instances),
'ErrorCount': 0,
'ServiceRole': kwargs.get('ServiceRoleArn'),
'NotificationConfig': {
'NotificationArn': 'string',
'NotificationEvents': ['Success'],
'NotificationType': 'Command'
}
}
}
ssm_backends = {}
for region, ec2_backend in ec2_backends.items():

View file

@ -190,3 +190,8 @@ class SimpleSystemManagerResponse(BaseResponse):
tag_list = [{'Key': k, 'Value': v} for (k, v) in tags.items()]
response = {'TagList': tag_list}
return json.dumps(response)
def send_command(self):
return json.dumps(
self.ssm_backend.send_command(**self.request_params)
)