def __init__(self, private=False, refresh=False): self.openstack_config = os_client_config.config.OpenStackConfig( os_client_config.config.CONFIG_FILES.append( '/etc/ansible/openstack.yml'), private) self.clouds = shade.openstack_clouds(self.openstack_config) self.refresh = refresh self.cache_max_age = self.openstack_config.get_cache_max_age() cache_path = self.openstack_config.get_cache_path() # Cache related if not os.path.exists(cache_path): os.makedirs(cache_path) self.cache_file = os.path.join(cache_path, "ansible-inventory.cache")
if "OnMetal" in i.name: continue new_images.append(i) return new_images if __name__ == "__main__": shade.simple_logging(debug=False) print "HODOR, make vm" user = os.getlogin() clouds = shade.openstack_clouds() cloud = random.choice(clouds) print "HODOR, using {0}-{1}".format(cloud.name, cloud.region_name) flavor = cloud.get_flavor_by_ram(512) images = filter_images(cloud.list_images()) ubuntus = [i for i in images if 'Ubuntu' in i.name] trustys = [i for i in ubuntus if '14.04' in i.name] xenials = [i for i in ubuntus if '16.04' in i.name] print "HODOR, using image: {0}".format(trustys[0].name) print "HODOR, image id is {0}".format(trustys[0].id) image = cloud.get_image(trustys[0].name)
default=10, help='Maximum number of minutes to wait for shutdown.') args = parser.parse_args() userdata = ('#!/bin/sh\n' + '# Image and Kickstart URLs\n' + 'vmlinuz_url=' + args.mirrorurl + 'images/pxeboot/vmlinuz\n' + 'initrd_url=' + args.mirrorurl + 'images/pxeboot/initrd.img\n' + 'ks_url=' + args.ksurl + '\n' + BOOTSTRAP_SCRIPT) # Connect to Openstack API using config from environment or files cfg = OpenStackConfig(pw_func=getpass) if args.cloud: envauth = shade.openstack_cloud().auth cloud = shade.openstack_cloud(config=cfg, cloud=args.cloud, **envauth) else: cloud = shade.openstack_clouds(config=cfg)[0] # Set up argument list for create_server call kwargs = {'security_groups': [args.secgroup], 'userdata': userdata} if args.key: kwargs['key_name'] = args.key # Pick a network if args.network: kwargs['network'] = args.network else: kwargs['network'] = cloud.list_networks()[0]['id'] # Set disk mapping if needed if args.disksize: print "Creating volume for instance..." result = cloud.create_volume(args.disksize, timeout=60, image=args.bootimage,