Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

CIRCLE / agent

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 7
  • Merge Requests 0
  • Wiki
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Commits
  • Issue Boards
Merged
Merge request !1 opened 10 years ago by Csók Tamás@SM0FZR 
  • Report abuse
Report abuse

Renew instance from agent

In response to Issue #35

Request to merge suspensionNotifier into master

Merged by

The changes were merged into master

The source branch has been removed

  • Discussion 23
  • Commits 21
  • Changes
0/0 discussions resolved
  • Őry Máté
    @orymate started a discussion on an old version of the diff 10 years ago
    Last updated by Csók Tamás 10 years ago
    vm_renewal
    1 #!/usr/bin/python
    2
    3 import notify
    4
    5 if __name__ == '__main__':
    6 try:
    7 notify.accept()
    8 finally:
    9 pass
    • Őry Máté @orymate commented 10 years ago
      Owner

      hm?

      hm?
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      command for accepting the proposed renewal, what user needs to type down at a console client (vm_renewal) to renew his suspension time. Any ideas to do it better?

      ps: (This file needs to be in the path enviroment variable ofc)

      Edited 10 years ago
      command for accepting the proposed renewal, what user needs to type down at a console client (vm_renewal) to renew his suspension time. Any ideas to do it better? ps: (This file needs to be in the path enviroment variable ofc)
    • Őry Máté @orymate commented 10 years ago
      Owner

      try: ... finally: pass is equivalent to ....

      `try: ... finally: pass` is equivalent to `...`.
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      Is it? I thought try catches all the exceptions whereas without it, it could go out

      Edited 10 years ago
      Is it? I thought try catches all the exceptions whereas without it, it could go out
    • Őry Máté @orymate commented 10 years ago
      Owner

      except is the one which catches exceptions :) the body of the finally clause is only guaranteed to run after the others

      except is the one which catches exceptions :) the body of the finally clause is only guaranteed to run after the others
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      So a try without a catch phase is useless :D

      So a try without a catch phase is useless :D
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff 10 years ago
    Last updated by Csók Tamás 10 years ago
    notify.py
    39 logger.error("Incorrect function call")
    40 else:
    41 process = subprocess.Popen("wall", stdin=subprocess.PIPE, shell=True)
    42 process.communicate(input=text)[0]
    43
    44
    45 def accept():
    46 import httplib
    47 if not os.path.isfile("%s/%s" % (get_temp_dir(), file_name)):
    48 logger.error("There isn't a request received currently")
    49 else:
    50 done = False
    51 # Load the saved url
    52 url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb"))
    53 headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    54 # Delete https:// or http:// from beginning
    • Őry Máté @orymate commented 10 years ago
      Owner

      urlparse module could help, but urllib.Request wouldn't even need to parse the url

      urlparse module could help, but [urllib.Request](https://docs.python.org/2/library/urllib2.html#urllib2.Request) wouldn't even need to parse the url
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      I checked into this. If we switch to urllib2 we still need to generate a fake data so we achive that the urllib2 sends a POST instead of a GET and in the response we loose the ability to easily check the headers. Even checking the returned page status code requires 2.6+ python. Are you sure it's worth the switch? I remember I ran into this problem when i made this code, but i double checked it now, to be sure.

      So it would look something like this:

      # Load the saved url
      url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb"))
      # Fake data to post so we make urllib2 send a POST instead of a GET
      data = urllib.urlencode(dict(fromPhyton='True'))
      # do POST request to 
      req = urllib2.Request(url, data)
      rsp = urllib2.urlopen(req)     
      # Get the result of the request - NOTE: only works past 2.6+ python
      if rsp.getcode() == 200:
          logger.info("Successfull renew, 200 - OK")
          done = True
      elif rsp.getcode() == 302:
          logger.info("Response is 302 - FOUND")
          done = True
      else:
          logger.error("Renewal failed please try it manually at %s" % url)
      # POST request was sent and received successfully
      if done:
          wall("Successfull renewal of this vm!")
          os.remove("%s/%s" % (get_temp_dir(), file_name))
      Edited 10 years ago
      I checked into this. If we switch to urllib2 we still need to generate a fake data so we achive that the urllib2 sends a POST instead of a GET and in the response we loose the ability to easily check the headers. Even checking the returned page status code requires 2.6+ python. Are you sure it's worth the switch? I remember I ran into this problem when i made this code, but i double checked it now, to be sure. So it would look something like this: ```python # Load the saved url url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb")) # Fake data to post so we make urllib2 send a POST instead of a GET data = urllib.urlencode(dict(fromPhyton='True')) # do POST request to req = urllib2.Request(url, data) rsp = urllib2.urlopen(req) # Get the result of the request - NOTE: only works past 2.6+ python if rsp.getcode() == 200: logger.info("Successfull renew, 200 - OK") done = True elif rsp.getcode() == 302: logger.info("Response is 302 - FOUND") done = True else: logger.error("Renewal failed please try it manually at %s" % url) # POST request was sent and received successfully if done: wall("Successfull renewal of this vm!") os.remove("%s/%s" % (get_temp_dir(), file_name)) ```
    • Őry Máté @orymate commented 10 years ago
      Owner
      • we do have python2.6+
      • urllib2 code seems much better
      • data="" is more simple
      • you can both get the response and send custom request headers
      req = Request("http://postcatcher.in/catchers/53d0c38b10b71c02000004c5", "", {'x-hello': 3})
      resp = urlopen(req)
      
      resp.info()['x-powered-by']
      # OUT: 'Express'
      * we do have python2.6+ * urllib2 code seems much better * `data=""` is more simple * you can both get the response and send custom request headers ``` req = Request("http://postcatcher.in/catchers/53d0c38b10b71c02000004c5", "", {'x-hello': 3}) resp = urlopen(req) resp.info()['x-powered-by'] # OUT: 'Express' ```
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      I feel bad now. I stand corrected, and already modified the code.

      I feel bad now. I stand corrected, and already modified the code.
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff 10 years ago
    Last updated by Őry Máté 10 years ago
    notify.py
    1 #!/usr/bin/python
    2 # -*- coding: utf-8 -*-
    3
    4 ##
    5 # Test program that informs the user about vm incoming time out
    6 ##
    7
    8 import platform, logging, os, subprocess, webbrowser, sys
    9 if sys.hexversion < 0x03000000 and sys.hexversion > 0x02000000:
    • Őry Máté @orymate commented 10 years ago
      Owner

      try: ... except ImporError? (btw python supports a < b < c form)

      try: ... except ImporError? (btw python supports `a < b < c` form)
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      Dosen't that just only makes it more pythonic or using a < b < c have benefits in runtime over the current one? And sure it can be changed to try except format too if needed.

      But maybe it would be even better to delete the whole checking as I recently learned about 2to3 python tool, which renders this useless

      Edited 10 years ago
      Dosen't that just only makes it more pythonic or using a < b < c have benefits in runtime over the current one? And sure it can be changed to try except format too if needed. But maybe it would be even better to delete the whole checking as I recently learned about 2to3 python tool, which renders this useless
    • Őry Máté @orymate commented 10 years ago
      Owner

      or you could even use json :) in this case i wouldn't care the run time of this expression, but the compact form must be slightly quicker as it evaluates b only once

      or you could even use json :) in this case i wouldn't care the run time of this expression, but the compact form must be slightly quicker as it evaluates `b` only once
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      So the question is I feel that this if statement is pointless, shall I remove it? I mean can I edit the code while it's under revision?

      So the question is I feel that this if statement is pointless, shall I remove it? I mean can I edit the code while it's under revision?
    • Őry Máté @orymate commented 10 years ago
      Owner

      yes and yes

      yes and yes
    Please register or sign in to reply
  • Őry Máté
    @orymate started a discussion on an old version of the diff 10 years ago
    notify.py
    1 #!/usr/bin/python
    • Őry Máté @orymate commented 10 years ago
      Owner

      #!/usr/bin/env python is more portable

      `#!/usr/bin/env python` is more portable
    Please register or sign in to reply
  • Őry Máté @orymate commented 10 years ago
    Owner

    Not really.

    [Not really.](https://git.ik.bme.hu/circle/storeserver/commit/35db65e40b724649280d629dc5a533f324427ae7#note_978)
  • Őry Máté
    @orymate started a discussion on commit aa01db5b 10 years ago
    Last updated by Csók Tamás 10 years ago
    vm_renewal
    1 #!/usr/bin/python
    1 #!/usr/bin/env python
    2 2  
    3 3 import notify
    4 4  
    5 5 if __name__ == '__main__':
    6 6 try:
    7 7 notify.accept()
    8 finally:
    9 pass
    8 except:
    9 notify.wall("There was an unknown error while trying to renew this vm, please do it manually!")
    • Őry Máté @orymate commented 10 years ago
      Owner

      you could simply print this

      you could simply `print` this
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      I could, but the main idea was to spam the user with information about the incoming suspension. Shouldn't a renew error be spammed too? Considering the other errors are all wall-ed too.

      Edited 10 years ago
      I could, but the main idea was to spam the user with information about the incoming suspension. Shouldn't a renew error be spammed too? Considering the other errors are all wall-ed too.
    • Őry Máté @orymate commented 10 years ago
      Owner

      They will call this command in a terminal, they will see its output as well.

      They will call this command in a terminal, they will see its output as well.
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      Shall I change all the rest of the accept method texts as well then?

      Shall I change all the rest of the accept method texts as well then?
    • Őry Máté @orymate commented 10 years ago
      Owner

      please

      please
    • Csók Tamás @SM0FZR commented 10 years ago
      Developer

      done :)

      done :)
    Please register or sign in to reply
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment
Bach Dániel
Assignee
Bach Dániel @bachdaniel
Assign to
None
Milestone
None
Assign milestone
None
Time tracking
No estimate or time spent
0
Labels
None
Assign labels
  • View labels
3
3 participants
Reference: circle/agent!1