I want to create a similar (hardware level) ec2 insatnce of an existing ec2 instance using saltstack.
Tried salt'boto_ec2.get_all_volumes' but unable to get the return type as volume objects. since it is mentioned as
return_objs
(bool) - Changes the return type from list of volume IDs to list of boto.ec2.volume.Volume objects
returns
(list) - A list of the requested values: Either the volume IDs; or, if return_objs is true,
boto.ec2.volume.Volume objects.
Yes we can get the objects by additional agrument "return_objs=True" and then get the size from the volume object
salt'boto_ec2.get_all_volumes'
Related
I am using the Spring Boot SDK for aws and I want to check my s3 bucket to check if a file exists or not, ignoring the case of the filename. Right now I am searching if the file exits by:
s3client.doesObjectExist(bucketname,objectname)
objectname is the file key for s3 with complete filename at the end. So, what I want to do is: if the file path is a/b/c/d/car.pdf, the above method should return "true," even though the actual file path in s3 is: a/b/c/d/CAR.pdf, a/b/c/d/caR.pdf or a/b/c/D/car.pdf.
ObjectListing listObjects(String bucketName) throws SdkClientException, AmazonServiceException
Returns a list of summary information about the objects in the
specified buckets. List results are always returned in lexicographic
(alphabetical) order.
Because buckets can contain a virtually unlimited number of keys, the
complete results of a list query can be extremely large. To manage
large result sets, Amazon S3 uses pagination to split them into
multiple responses. Always check the ObjectListing.isTruncated()
method to see if the returned listing is complete or if additional
calls are needed to get more results. Alternatively, use the
AmazonS3Client.listNextBatchOfObjects(ObjectListing) method as an easy
way to get the next page of object listings.
The total number of keys in a bucket doesn't substantially affect list
performance.
So, you can do something like this:
ObjectListing objectListing = s3client.listObjects("MyBucketName");
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
// implement some search algorithm to find matching files using objectSummary.getKey()
}
I a developing a macOS commandline application in Xcode, which uses User Defaults. I have the following code for my User Defaults
if let configDefaults = UserDefaults.init(suiteName: "com.tests.configuration") {
configDefaults.set("myStringValue", forKey: "stringKey")
configDefaults.synchronize()
print(configDefaults.dictionaryRepresentation())
}
This will create my own .plist file in the ~/Library/Preferences folder. If I look into the file, I can see only my single value which I added, which is perfectly fine. But when I call dictionaryRepresentation() on my UserDefaults object, the there are a lot of other attributes (I guess from the shared UserDefaults object), like
com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture or AKLastEmailListRequestDateKey
Looking into the documentation of UserDefaults, it seems that this has to do with the search list of UserDefaults and that the standard object is in the search list:
func dictionaryRepresentation() -> [String : Any]
Returns a dictionary that contains a union of all key-value pairs in the domains in the search list.
There are also the methods addSuite and removeSuite for a UserDefaults object, so I am guessing I need to remove the .standard suite from my configDefaults object, but I don't know the name, which should be used for that in the method.
Is it possible to remove the .standard defaults from the dictionary representation? I basically just want all of my own data in a dictionary, nothing more.
The reason I am trying to get only my values from the UserDefaults, is that a have a number of object of a custom type Connection (which store the configuration to connect to a server), which are saved in the UserDefaults. On program start I want to be able to load all objects into my app. Therefore I thought I could use dictionaryRepresentation(), as it would return all elements in the UserDefaults. But then there should be only my Connection objects in the dictionary, so that I can cast it to [String: Connection].
Given your purpose (in your latest edit of your question), what you should do is store a collection of Connection objects under a single key. Then, look up that key to get the collection.
It's not clear if the collection should be an array of Connection objects or a dictionary mapping strings to Connections. That's a choice you can make.
But, in any case, you shouldn't rely on the defaults being empty of everything else.
In other words, you would do:
UserDefaults.standard.set(yourStringToConnectionDictionary, forKey:"yourSingleKey")
and later:
let connectionMap = UserDefaults.dictionary(forKey:"yourSingleKey")
then look up Connections in the connectionMap by their name/ID/whatever.
Though the other solution proposed by Ken Thomases may be better from a design standpoint, I've found a solution that does exactly what I initially wanted. Calling
UserDefaults.standard.persistentDomain(forName: "com.company.TestApp.configuration")
Returns a dictionary containing only the values I've added to the domain com.company.TestApp.configuration, using
let configs = UserDefaults.init(suiteName: "com.company.TestApp.configuration")!
configs.set(someData, forKey: someKey)
Strangely in the Apple documentation says this about persistentDomain(forName:):
Calling this method is equivalent to initializing a user defaults object with init(suiteName:) passing domainName and calling the dictionaryRepresentation() method on it.
But this is not the case (see my question). Clarification on that subject is more than welcome.
Is it possible to list nodes in a non-default AWS VPC? This can be done easily using EC2::DescribeInstances by passing a filter with vpc-id= but I can't figure out how to do it using jclouds.
I know how to create an instance in a specified VPC using template options, but I cannot find an equivalent approach for listing nodes. I'm currently using listNodesDetailsMatching(...).
You cannot eagerly filter that on the provider. Using the portable interface you can just provide a predicate to filter nodes once you have them all. You can directly use the underlying AWS EC2 API to do what you want. It could be something like the following:
AWSEC2Api aws = computeServiceContext.unwrapApi(AWSEC2Api.class);
AWSInstanceApi instanceApi = aws.getInstanceApi().get();
instanceApi.describeInstancesInRegionWithFilter("region", ImmutableMultimap.of("vpc-id", "myvpc"));
Just like as title, I want to ask what difference between
fromPin()
and
fromLocalDatastore()
By the way, Pin and datastore two terminologies. What difference between two of them ?
Thanks.
There is a slight difference and you can see it from the docs and from the decompiled code of the Parse library (okay, this last one is more complicated...).
The docs says:
fromLocalDatastore(): Change the source of this query to all pinned objects.
fromPin(): Change the source of this query to the default group of pinned objects.
Here you can see that, interally on Parse, there is a way to get all the objects from the entire set of pinned data, without filters, but also from a so-called "default group". This group is defined in the Parse code with the following string: _default (o'rly?).
When you pin something using pinInBackground, you can do it in different ways:
pinInBackground() [without arguments]: Stores the object and every object it points to in the local datastore.
This is what the docs say, but if you look at the code you'll discover that the pin will be actually performed to the... _default group!
public Task<Void> pinInBackground() {
return pinAllInBackground("_default", Arrays.asList(new ParseObject[] { this }));
}
On the other hand, you can always call pinInBackground(String group) to specify a precise group.
Conclusion: every time you pin an object, it's guaranteed to be pinned to a certain group. The group is "_default" if you don't specify anything in the parameters. If you pin an object to your custom group "G", then a query using fromPin() will not find it! Because you didn't put it on "_default", but "G".
Instead, using fromLocalDatastore(), the query is guaranteed to find your object because it will search into "_default", "G" and so on.
I've got an EC2 snapshot from a running machine. When I create an image and then an instance out of it, it fails the reachability test, and I can't connect to it. I checked the volume and it's got no errors by attaching to another machine.
I now suspect that I have to choose the right kernel-id, and that the default might not be compatible.
Looking at other EC2 instances I have, they are running kernel id aki-427d952b, but this kernel is not available from the dropdown list (even in the same availability zone).
How do I find the next-best kernel id? Is there some list of kernel ids and which versions/architectures they support?
EDIT: can e.g. python boto or another library be used to list all kernel-ids and attributes to allow choosing a different kernel-id from aki-427d952b (which is missing from the dropdown list).
Boto can certainly be used to list images, and you can get data about their configuration. Whether that's the best way to search for a replacement is another question, but, if you want to do it, here's the python/boto code
# use your AWS id and Secret here
conn = EC2Connection(awsid, awssecret)
# returns array of all images your account can use
all_images = conn.get_all_images()
for img in all_images:
attrs = img.__dict__
# attrs will be a dictionary of key-value pairs associated
# with the image. Look through them to find what you want.
if img.kernel_id == 'aki-427d952b':
print "found aki-427d952b: imgid=" + img.id