def _load_conf(instance): if 'publish_settings' in instance: cert_file_handle, cert_file_path = mkstemp() get_certificate_from_publish_settings(instance.get('publish_settings'), cert_file_path) else: cert_file_handle = None cert_file_path = instance.get('cert_file') namespace = instance.get('namespace') tags = [] if 'tags' in instance: tags = instance.get('tags') return instance.get('subscription_id'), cert_file_handle, cert_file_path, namespace, tags
def main(): ''' new version simulate a simple bash ''' config = __import__('config') subscription_id = get_certificate_from_publish_settings( publish_settings_path=config.publish_settings_path, path_to_write_certificate=config.path_to_write_certificate, ) cert_file = config.path_to_write_certificate sms = ServiceManagementService(subscription_id, cert_file) if len(sys.argv) < 2 : print "format should be python inspector.py <url of the vhd>" exit url = sys.argv[1] storage_name = url[8:url.find('.')] storage_account_key = sms.get_storage_account_keys(storage_name).storage_service_keys.primary.encode('ascii','ignore') nowpath = "/" def get_sentence(s) : st = s.find(' ') while st < len(s) and s[st] == ' ' : st += 1 ed = len(s) for i in range(st, len(s)) : if s[i] == ' ' and s[i-1] != '\\' : ed = i break while ed>0 and s[ed-1] == '/' : ed -= 1 return s[st:ed].replace("//", "/") global last_query_files_num while True : cmd = raw_input(nowpath+" $ ") if cmd.split(' ')[0] == "quit" : break elif cmd.split(' ')[0] == "ls" : old_main(url=url, account_key=storage_account_key, path=nowpath, ls=True) elif cmd.startswith("cd ") : sentence = get_sentence(cmd) if sentence != "" : if sentence == ".." : if nowpath != "/" : nowpath = nowpath[:nowpath[:-1].rfind('/')+1] elif sentence[0] == '/' : old_main(url=url, account_key=storage_account_key, path=sentence, ls=True) if last_query_files_num == 0 : print "no such directory" else : nowpath = sentence + "/" elif sentence != "" : old_main(url=url, account_key=storage_account_key, path=(nowpath+sentence), ls=True) if last_query_files_num == 0 : print "no such directory" else : nowpath += sentence + "/" elif cmd.startswith("download ") : sentence = get_sentence(cmd) tmp = sentence.rfind('/') if sentence != "" : old_main(url=url, account_key=storage_account_key, path=(nowpath+sentence[:tmp]), filename=sentence[(tmp+1):]) else : print "invalid command"
# The MIT License (MIT) # # Copyright (c) 2015 Taio Jia (jiasir) <*****@*****.**> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from azure.servicemanagement import get_certificate_from_publish_settings subscription_id = get_certificate_from_publish_settings( publish_settings_path='/Users/Taio/Downloads/Microsoft_Azure_credentials.publishsettings', path_to_write_certificate='/Users/Taio/Downloads/Microsoft_Azure_credentials.pem', subscription_id='7f32b7c7-8622-4070-84d0-1ec5bc64dd8f', )
from azure.servicemanagement import get_certificate_from_publish_settings subscription_id = get_certificate_from_publish_settings( publish_settings_path='latest.publishsettings', path_to_write_certificate='azurecert.pem', subscription_id='6210d80f-6574-4940-8f97-62e3f455d194', )
def process_sms_list(result_list, csv_filename): result_elements = [o.__dict__ for o in result_list] df = pd.DataFrame(result_elements) df.to_csv(csv_filename, encoding='utf-8', index=False) return df if __name__ == '__main__': subscription_id = '8ea1a328-9162-4a6e-9cdc-fcc8d6766608' pem_file = './azure/certs/azure_client.pem' subscription_id = get_certificate_from_publish_settings( publish_settings_path='./azure/certs/subscription.publishsettings', path_to_write_certificate=pem_file, subscription_id=subscription_id ) sms = ServiceManagementService(subscription_id, pem_file) if not os.path.exists('./azure/data'): os.mkdir('./azure/data') result = sms.list_os_images() process_sms_list(result.images, './azure/data/azure_os_images.csv') print ('Azure OS images saved in azure_os_images.csv') result = sms.list_vm_images() process_sms_list(result.vm_images, './azure/data/azure_vm_images.csv') print ('Azure VM images saved in azure_vm_images.csv')