def ensure_key(self, config_name, root_configuration): keyname = self.get_username() + 'Key' keyfile = '~/.ssh/{}.rsa'.format(keyname) self.set_keyname(os.path.join(os.path.dirname(root_configuration), config_name), keyname) if True or self.has_property(root_configuration, '[key mykey]'): try: from starcluster import config, exception from boto.exception import EC2ResponseError print 'Creating EC2 key ' + keyfile self.set_property(root_configuration, 'KEY_LOCATION=~/.ssh/mykey.rsa', 'KEY_LOCATION={}'.format(keyfile)) self.set_property(root_configuration, '[key mykey]', '[key {}]'.format(keyname)) self.set_property(root_configuration, 'KEYNAME = mykey', 'KEYNAME = {}'.format(keyname)) config = config.StarClusterConfig() config.load() config.get_easy_ec2().create_keypair(keyname, output_file=os.path.expanduser(keyfile)) self.update_ownership(os.path.expanduser(keyfile), self.get_username()) except exception.KeyPairAlreadyExists: print 'Key pair "{}" already exists on EC2 -- name must be unique'.format(keyname) print '*** Must manually create using "starcluster createkey {} -o {}"'.format( keyname, keyfile) except EC2ResponseError: print 'Unable to create key pair -- incorrect API credentials?' print '*** Must manually create using "starcluster createkey {} -o {}"'.format( keyname, keyfile) except ImportError: print 'Unable to import starcluster; skipping key generation'
buckets = self.conn.get_all_buckets() except TypeError,e: #hack until boto fixes get_all_buckets raise exception.AWSError("AWS credentials are not valid") return buckets def list_buckets(self): for bucket in self.get_buckets(): print bucket.name def get_bucket_files(self, bucketname): files = [] try: bucket = self.get_bucket(bucketname) files = [ file for file in bucket.list() ] except: pass return files def show_bucket_files(self, bucket_name): if self.bucket_exists(bucket_name): files = self.get_bucket_files(bucket_name) for file in files: print file if __name__ == "__main__": from starcluster.config import get_easy_ec2 ec2 = get_easy_ec2() ec2.list_all_instances() ec2.list_registered_images()
#!/usr/bin/python import starcluster.config as config def get_instance_by_tag(ec2, tag, key='Name'): return next( (instance for instance in ec2.get_all_instances() if instance.tags[key] == tag)) if __name__ == '__main__': configuration_file = None configuration = config.get_config(configuration_file) plugin = configuration.plugins['myriaplugin'] port = plugin.get('REST_PORT', 8753) instance = get_instance_by_tag( config.get_easy_ec2(configuration_file), 'myriacluster-master') print 'http://{}:{}'.format(instance.dns_name, port)
for file in bucket.list(): if file.name: print file.name def get_buckets(self): try: buckets = self.conn.get_all_buckets() except TypeError: #hack until boto fixes get_all_buckets raise exception.AWSError("AWS credentials are not valid") return buckets def list_buckets(self): for bucket in self.get_buckets(): print bucket.name def get_bucket_files(self, bucketname): files = [] try: bucket = self.get_bucket(bucketname) files = [file for file in bucket.list()] except: pass return files if __name__ == "__main__": from starcluster.config import get_easy_ec2 ec2 = get_easy_ec2() ec2.list_all_instances() ec2.list_registered_images()