def main(event, context): token = {Your Token} accountId = {Your Account ID} client = spotinst.SpotinstClient(auth_token=token, account_id=accountId) getGroups = json.loads(json.dumps(client.get_elastigroups())) return { 'statusCode': 200, 'body': getGroupInfo(getGroups), 'headers': {"Content-Type": "application/json"} }
def main(): fields = dict( account_id=dict(type='str'), availability_vs_cost=dict(type='str', required=True), availability_zones=dict(type='list', required=True), block_device_mappings=dict(type='list'), chef=dict(type='dict'), credentials_path=dict(type='path', default="~/.spotinst/credentials"), do_not_update=dict(default=[], type='list'), down_scaling_policies=dict(type='list'), draining_timeout=dict(type='int'), ebs_optimized=dict(type='bool'), ebs_volume_pool=dict(type='list'), ecs=dict(type='dict'), elastic_beanstalk=dict(type='dict'), elastic_ips=dict(type='list'), fallback_to_od=dict(type='bool'), id=dict(type='str'), health_check_grace_period=dict(type='int'), health_check_type=dict(type='str'), health_check_unhealthy_duration_before_replacement=dict(type='int'), iam_role_arn=dict(type='str'), iam_role_name=dict(type='str'), image_id=dict(type='str', required=True), key_pair=dict(type='str'), kubernetes=dict(type='dict'), lifetime_period=dict(type='int'), load_balancers=dict(type='list'), max_size=dict(type='int', required=True), mesosphere=dict(type='dict'), min_size=dict(type='int', required=True), monitoring=dict(type='str'), multai_load_balancers=dict(type='list'), multai_token=dict(type='str'), name=dict(type='str', required=True), network_interfaces=dict(type='list'), on_demand_count=dict(type='int'), on_demand_instance_type=dict(type='str'), opsworks=dict(type='dict'), persistence=dict(type='dict'), product=dict(type='str', required=True), rancher=dict(type='dict'), right_scale=dict(type='dict'), risk=dict(type='int'), roll_config=dict(type='dict'), scheduled_tasks=dict(type='list'), security_group_ids=dict(type='list', required=True), shutdown_script=dict(type='str'), signals=dict(type='list'), spin_up_time=dict(type='int'), spot_instance_types=dict(type='list', required=True), state=dict(default='present', choices=['present', 'absent']), tags=dict(type='list'), target=dict(type='int', required=True), target_group_arns=dict(type='list'), tenancy=dict(type='str'), terminate_at_end_of_billing_hour=dict(type='bool'), token=dict(type='str'), unit=dict(type='str'), user_data=dict(type='str'), utilize_reserved_instances=dict(type='bool'), uniqueness_by=dict(default='name', choices=['name', 'id']), up_scaling_policies=dict(type='list'), target_tracking_policies=dict(type='list'), wait_for_instances=dict(type='bool', default=False), wait_timeout=dict(type='int') ) module = AnsibleModule(argument_spec=fields) if not HAS_SPOTINST_SDK: module.fail_json(msg="the Spotinst SDK library is required. (pip install spotinst)") # Retrieve creds file variables creds_file_loaded_vars = dict() credentials_path = module.params.get('credentials_path') try: with open(credentials_path, "r") as creds: for line in creds: eq_index = line.find('=') var_name = line[:eq_index].strip() string_value = line[eq_index + 1:].strip() creds_file_loaded_vars[var_name] = string_value except IOError: pass # End of creds file retrieval token = module.params.get('token') if not token: token = os.environ.get('SPOTINST_TOKEN') if not token: token = creds_file_loaded_vars.get("token") account = module.params.get('account_id') if not account: account = os.environ.get('ACCOUNT') if not account: account = creds_file_loaded_vars.get("account") client = spotinst.SpotinstClient(auth_token=token, print_output=False) if account is not None: client = spotinst.SpotinstClient(auth_token=token, print_output=False, account_id=account) group_id, message, has_changed = handle_elastigroup(client=client, module=module) instances = retrieve_group_instances(client=client, module=module, group_id=group_id) module.exit_json(changed=has_changed, group_id=group_id, message=message, instances=instances)
import spotinst # Initialize Spotinst Client with your Personal Access Token client = spotinst.SpotinstClient(auth_token="YOUR_API_TOKEN_HERE") # Initialize application application = spotinst.spotinst_functions.Application("my_great_application") # Create application and retrieve application-id app = client.create_application(application) app_id = app['id'] print "-------Create Functions Application-------" print app_id # Initialize providers providers = ['aws', 'azure'] # Initialize locations locations = ['us-east'] # Initialize environment environment = spotinst.spotinst_functions.Environment("testings", app_id, providers, locations) # Create environment and retrieve environment-id env = client.create_environment(environment) env_id = env['id'] print "-------Create Functions Environment-------" print env_id
import spotinst # Initialize Spotinst Client with your Personal Access Token client = spotinst.SpotinstClient(auth_token="YOUR_API_TOKEN_HERE", account_id="act-92d492634") # Initialize group strategy strategy = spotinst.aws_elastigroup.Strategy(risk=100, utilize_reserved_instances=False, fallback_to_od=True, availability_vs_cost="balanced") # Initialize group capacity capacity = spotinst.aws_elastigroup.Capacity(minimum=0, maximum=10, target=0, unit="instance") # Initialize group tags tag1 = spotinst.aws_elastigroup.Tag(tag_key="Creator", tag_value="Spotinst-Python-SDK") tag2 = spotinst.aws_elastigroup.Tag(tag_key="Name", tag_value="Spotinst-Python-SDK") tags = [tag1, tag2] # Initialize group security group id list securityGroupId = "sg-46e6b33d" securityGroupIds = [securityGroupId] # Initialize Launch Specification launchSpec = spotinst.aws_elastigroup.LaunchSpecification(image_id="ami-f173cc91", key_pair="spotinst-oregon", tags=tags, security_group_ids=securityGroupIds, monitoring=True) # Initialize Availability Zones az1 = spotinst.aws_elastigroup.AvailabilityZone(name="us-west-2a", subnet_ids=["subnet-5df28914"]) az_list = [az1] # Initialize spot and on demand instance types instance_types = spotinst.aws_elastigroup.InstanceTypes(ondemand="c3.large", spot=["c3.large"])