vr_server: implement startup_script (#34565)

* simplify

* vr_server: implement startup_script
pull/33809/head
René Moser 7 years ago committed by GitHub
parent fbffcb36bf
commit 476030a49c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -203,7 +203,7 @@ class Vultr:
}) })
return r_data return r_data
self.module.fail_json(msg="Could not find %s %s: %s" % (resource, key, value)) self.module.fail_json(msg="Could not find %s with %s: %s" % (resource, key, value))
def get_result(self, resource): def get_result(self, resource):
if resource: if resource:

@ -67,6 +67,10 @@ options:
user_data: user_data:
description: description:
- User data to be passed to the server. - User data to be passed to the server.
startup_script:
description:
- Name of the startup script to execute on boot.
- Only considered while creating the server.
ssh_keys: ssh_keys:
description: description:
- List of SSH keys passed to the server on creation. - List of SSH keys passed to the server on creation.
@ -351,61 +355,49 @@ class AnsibleVultrServer(Vultr):
} }
self.server_power_state = None self.server_power_state = None
def get_os(self): def get_startup_script(self):
name = self.module.params.get('os') return self.query_resource_by_key(
if not name: key='name',
return {} value=self.module.params.get('startup_script'),
resource='startupscript',
)
def get_os(self):
return self.query_resource_by_key( return self.query_resource_by_key(
key='name', key='name',
value=name, value=self.module.params.get('os'),
resource='os', resource='os',
use_cache=True use_cache=True
) )
def get_ssh_key(self): def get_ssh_key(self):
name = self.module.params.get('ssh_key')
if not name:
return {}
return self.query_resource_by_key( return self.query_resource_by_key(
key='name', key='name',
value=name, value=self.module.params.get('ssh_key'),
resource='sshkey', resource='sshkey',
use_cache=True use_cache=True
) )
def get_region(self): def get_region(self):
name = self.module.params.get('region')
if not name:
return {}
return self.query_resource_by_key( return self.query_resource_by_key(
key='name', key='name',
value=name, value=self.module.params.get('region'),
resource='regions', resource='regions',
use_cache=True use_cache=True
) )
def get_plan(self): def get_plan(self):
name = self.module.params.get('plan')
if not name:
return {}
return self.query_resource_by_key( return self.query_resource_by_key(
key='name', key='name',
value=name, value=self.module.params.get('plan'),
resource='plans', resource='plans',
use_cache=True use_cache=True
) )
def get_firewall_group(self): def get_firewall_group(self):
name = self.module.params.get('firewall_group')
if not name:
return {}
return self.query_resource_by_key( return self.query_resource_by_key(
key='description', key='description',
value=name, value=self.module.params.get('firewall_group'),
resource='firewall', resource='firewall',
query_by='group_list' query_by='group_list'
) )
@ -492,6 +484,7 @@ class AnsibleVultrServer(Vultr):
'tag': self.module.params.get('tag'), 'tag': self.module.params.get('tag'),
'reserved_ip_v4': self.module.params.get('reserved_ip_v4'), 'reserved_ip_v4': self.module.params.get('reserved_ip_v4'),
'user_data': self.get_user_data(), 'user_data': self.get_user_data(),
'SCRIPTID': self.get_startup_script().get('SCRIPTID'),
} }
self.api_query( self.api_query(
path="/v1/server/create", path="/v1/server/create",
@ -835,6 +828,7 @@ def main():
tag=dict(), tag=dict(),
reserved_ip_v4=dict(), reserved_ip_v4=dict(),
firewall_group=dict(), firewall_group=dict(),
startup_script=dict(),
user_data=dict(), user_data=dict(),
ssh_keys=dict(type='list', aliases=['ssh_key']), ssh_keys=dict(type='list', aliases=['ssh_key']),
region=dict(), region=dict(),

Loading…
Cancel
Save